[virglrenderer-devel] [PATCH 4/4] vrend_shader: move source register translation
Gurchetan Singh
gurchetansingh at chromium.org
Tue May 8 22:25:57 UTC 2018
iter_instruction is a big function. Let's make it smaller
by moving some functionality.
One simplification that was made is assuming there's 3, not 4,
source registers as TGSI specificies.
v2: Fix comment
---
src/vrend_shader.c | 102 ++++++++++++++++++++++++++-------------------
1 file changed, 58 insertions(+), 44 deletions(-)
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index c7892fe..9a1e027 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -1734,65 +1734,35 @@ get_destination_info(struct dump_ctx *ctx,
return 0;
}
-
-static boolean
-iter_instruction(struct tgsi_iterate_context *iter,
- struct tgsi_full_instruction *inst)
+static int
+get_source_info(struct dump_ctx *ctx,
+ const struct tgsi_full_instruction *inst,
+ enum vrend_type_conversion *svec4, int *sreg_index,
+ char srcs[3][255], bool *override_no_wm)
{
- struct dump_ctx *ctx = (struct dump_ctx *)iter;
- char srcs[4][255], dst[255], buf[512];
- uint instno = ctx->instno++;
- int i;
- int j;
- int sreg_index = 0;
- char writemask[6] = {0};
- enum tgsi_opcode_type stype = tgsi_opcode_infer_src_type(inst->Instruction.Opcode);
bool stprefix = false;
- bool override_no_wm[4];
- bool dst_override_no_wm;
- char *sret;
- int ret;
-
- enum vrend_type_conversion dtypeprefix, stypeprefix, dstconv, udstconv, svec4;
- dtypeprefix = stypeprefix = dstconv = udstconv = TYPE_CONVERSION_NONE;
- svec4 = VEC4;
+ enum vrend_type_conversion stypeprefix = TYPE_CONVERSION_NONE;
+ enum tgsi_opcode_type stype = tgsi_opcode_infer_src_type(inst->Instruction.Opcode);
- if (ctx->prog_type == -1)
- ctx->prog_type = iter->processor.Processor;
if (stype == TGSI_TYPE_SIGNED || stype == TGSI_TYPE_UNSIGNED)
ctx->has_ints = true;
switch (stype) {
case TGSI_TYPE_UNSIGNED:
stypeprefix = FLOAT_BITS_TO_UINT;
- svec4 = UVEC4;
+ *svec4 = UVEC4;
stprefix = true;
break;
case TGSI_TYPE_SIGNED:
stypeprefix = FLOAT_BITS_TO_INT;
- svec4 = IVEC4;
+ *svec4 = IVEC4;
stprefix = true;
break;
default:
break;
}
- if (instno == 0) {
- sret = add_str_to_glsl_main(ctx, "void main(void)\n{\n");
- if (!sret)
- return FALSE;
- if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) {
- ret = emit_color_select(ctx);
- if (ret)
- return FALSE;
- }
- }
-
- ret = get_destination_info(ctx, inst, &dtypeprefix, &dstconv, &udstconv, &dst_override_no_wm, dst, writemask);
- if (ret)
- return FALSE;
-
- for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
+ for (uint32_t i = 0; i < inst->Instruction.NumSrcRegs; i++) {
const struct tgsi_full_src_register *src = &inst->Src[i];
char swizzle[8] = {0};
char prefix[6] = {0};
@@ -1823,7 +1793,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
swizzle[swz_idx++] = get_swiz_char(src->Register.SwizzleW);
}
if (src->Register.File == TGSI_FILE_INPUT) {
- for (j = 0; j < ctx->num_inputs; j++)
+ for (uint32_t j = 0; j < ctx->num_inputs; j++)
if (ctx->inputs[j].first == src->Register.Index) {
if (ctx->key->color_two_side && ctx->inputs[j].name == TGSI_SEMANTIC_COLOR)
snprintf(srcs[i], 255, "%s(%s%s%d%s%s)", get_string(stypeprefix), prefix, "realcolor", ctx->inputs[j].sid, arrayname, swizzle);
@@ -1886,7 +1856,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
} else if (src->Register.File == TGSI_FILE_SAMPLER) {
const char *cname = tgsi_proc_to_prefix(ctx->prog_type);
snprintf(srcs[i], 255, "%ssamp%d%s", cname, src->Register.Index, swizzle);
- sreg_index = src->Register.Index;
+ *sreg_index = src->Register.Index;
} else if (src->Register.File == TGSI_FILE_IMMEDIATE) {
if (src->Register.Index >= ARRAY_SIZE(ctx->imm)) {
fprintf(stderr, "Immediate exceeded, max is %lu\n", ARRAY_SIZE(ctx->imm));
@@ -1919,7 +1889,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
/* build up a vec4 of immediates */
snprintf(srcs[i], 255, "%s(%s%s(", get_string(imm_stypeprefix), prefix, get_string(vtype));
- for (j = 0; j < 4; j++) {
+ for (uint32_t j = 0; j < 4; j++) {
if (j == 0)
idx = src->Register.SwizzleX;
else if (j == 1)
@@ -1955,7 +1925,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
}
}
} else if (src->Register.File == TGSI_FILE_SYSTEM_VALUE) {
- for (j = 0; j < ctx->num_system_values; j++)
+ for (uint32_t j = 0; j < ctx->num_system_values; j++)
if (ctx->system_values[j].first == src->Register.Index) {
if (ctx->system_values[j].name == TGSI_SEMANTIC_VERTEXID ||
ctx->system_values[j].name == TGSI_SEMANTIC_INSTANCEID ||
@@ -1975,6 +1945,50 @@ iter_instruction(struct tgsi_iterate_context *iter,
}
}
}
+
+ return 0;
+}
+
+static boolean
+iter_instruction(struct tgsi_iterate_context *iter,
+ struct tgsi_full_instruction *inst)
+{
+ struct dump_ctx *ctx = (struct dump_ctx *)iter;
+ char srcs[3][255], dst[255], buf[512];
+ uint instno = ctx->instno++;
+ int sreg_index = 0;
+ char writemask[6] = {0};
+ bool override_no_wm[3];
+ bool dst_override_no_wm;
+ char *sret;
+ int ret;
+
+ enum vrend_type_conversion dtypeprefix, dstconv, udstconv, svec4;
+ dtypeprefix = dstconv = udstconv = TYPE_CONVERSION_NONE;
+ svec4 = VEC4;
+
+ if (ctx->prog_type == -1)
+ ctx->prog_type = iter->processor.Processor;
+
+ if (instno == 0) {
+ sret = add_str_to_glsl_main(ctx, "void main(void)\n{\n");
+ if (!sret)
+ return FALSE;
+ if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) {
+ ret = emit_color_select(ctx);
+ if (ret)
+ return FALSE;
+ }
+ }
+
+ ret = get_destination_info(ctx, inst, &dtypeprefix, &dstconv, &udstconv, &dst_override_no_wm, dst, writemask);
+ if (ret)
+ return FALSE;
+
+ ret = get_source_info(ctx, inst, &svec4, &sreg_index, srcs, override_no_wm);
+ if (ret)
+ return FALSE;
+
switch (inst->Instruction.Opcode) {
case TGSI_OPCODE_SQRT:
snprintf(buf, 255, "%s = sqrt(vec4(%s))%s;\n", dst, srcs[0], writemask);
--
2.17.0.441.gb46fe60e1d-goog
More information about the virglrenderer-devel
mailing list