[PATCH vkd3d v2 1/6] vkd3d-shader/hlsl: Parse state blocks in variable definitions.
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- Makefile.am | 1 + libs/vkd3d-shader/hlsl.h | 2 + libs/vkd3d-shader/hlsl.y | 54 ++++++- tests/hlsl-state-block-syntax.shader_test | 173 ++++++++++++++++++++++ 4 files changed, 223 insertions(+), 7 deletions(-) create mode 100644 tests/hlsl-state-block-syntax.shader_test diff --git a/Makefile.am b/Makefile.am index 4a2bf8e18..bc33e0f60 100644 --- a/Makefile.am +++ b/Makefile.am @@ -74,6 +74,7 @@ vkd3d_shader_tests = \ tests/hlsl-return-implicit-conversion.shader_test \ tests/hlsl-return-void.shader_test \ tests/hlsl-shape.shader_test \ + tests/hlsl-state-block-syntax.shader_test \ tests/hlsl-static-initializer.shader_test \ tests/hlsl-storage-qualifiers.shader_test \ tests/hlsl-struct-assignment.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 27afeedd4..abc870f4f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -469,6 +469,8 @@ struct hlsl_ctx size_t count, size; } constant_defs; uint32_t temp_count; + + uint32_t in_state_block : 1; }; enum hlsl_error_level diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 19745e725..8ad892f9e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2558,6 +2558,23 @@ variable_decl: $$->reg_reservation = $3.reg_reservation; } +state: + any_identifier '=' expr ';' + { + vkd3d_free($1); + hlsl_free_instr_list($3); + } + +state_block_start: + %empty + { + ctx->in_state_block = 1; + } + +state_block: + %empty + | state_block state + variable_def: variable_decl | variable_decl '=' complex_initializer @@ -2565,6 +2582,11 @@ variable_def: $$ = $1; $$->initializer = $3; } + | variable_decl '{' state_block_start state_block '}' + { + $$ = $1; + ctx->in_state_block = 0; + } arrays: %empty @@ -2861,13 +2883,10 @@ primary_expr: hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Variable \"%s\" is not defined.", $1); YYABORT; } - if ((load = hlsl_new_var_load(ctx, var, @1))) - { - if (!($$ = make_list(ctx, &load->node))) - YYABORT; - } - else - $$ = NULL; + if (!(load = hlsl_new_var_load(ctx, var, @1))) + YYABORT; + if (!($$ = make_list(ctx, &load->node))) + YYABORT; } | '(' expr ')' { @@ -2878,6 +2897,27 @@ primary_expr: if (!($$ = add_call(ctx, $1, &$3, @1))) YYABORT; } + | NEW_IDENTIFIER + { + if (ctx->in_state_block) + { + struct hlsl_ir_load *load; + struct hlsl_ir_var *var; + + if (!(var = hlsl_new_synthetic_var(ctx, "<state-block-expr>", + ctx->builtin_types.scalar[HLSL_TYPE_INT], @1))) + YYABORT; + if (!(load = hlsl_new_var_load(ctx, var, @1))) + YYABORT; + if (!($$ = make_list(ctx, &load->node))) + YYABORT; + } + else + { + hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Identifier \"%s\" is not declared.\n", $1); + YYABORT; + } + } postfix_expr: primary_expr diff --git a/tests/hlsl-state-block-syntax.shader_test b/tests/hlsl-state-block-syntax.shader_test new file mode 100644 index 000000000..26853bf40 --- /dev/null +++ b/tests/hlsl-state-block-syntax.shader_test @@ -0,0 +1,173 @@ +[pixel shader fail] +sampler s +{ + foo = float; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s = sampler_state +{ + foo = float; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + 2 = 3; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + 2; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + foo; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + foo = bar +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s {} + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f {} = 1; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f = 1 {}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s = sampler_state; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f {} : register(c1); + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = (sampler)2; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = (faketype)2; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = (sampler)bar; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = bar(); +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader] +float u : register(c1) {}; +float4 main() : sv_target +{ + float zero = 0; + float a {}; + float b + { + foo = bar; + foo = bar; + foo = (int)2; + foo = (int)bar; + foo = float4(bar, baz, qux, xyzzy); + foo = zero++; + }; + float c {}, d = 1, e; + struct {int a;} s {foo = bar;}; + return float4(0, 1, zero, 1); +} + +[test] +draw quad +probe all rgba (0, 1, 0, 1) -- 2.33.0
From: Giovanni Mascellani <gmascellani(a)codeweavers.com> Some instructions (e.g. umul) have multiple destination registers. Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_sm4.c | 85 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 500c9f434..f407b4a63 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -572,7 +572,8 @@ struct sm4_instruction { struct sm4_register reg; unsigned int writemask; - } dst; + } dsts[1]; + unsigned int dst_count; struct { @@ -583,8 +584,6 @@ struct sm4_instruction uint32_t idx[2]; unsigned int idx_count; - - unsigned int has_dst; }; static unsigned int sm4_swizzle_type(enum vkd3d_sm4_register_type type) @@ -724,8 +723,8 @@ static void write_sm4_instruction(struct vkd3d_bytecode_buffer *buffer, const st uint32_t token = instr->opcode; unsigned int size = 1, i, j; - if (instr->has_dst) - size += sm4_register_order(&instr->dst.reg); + for (i = 0; i < instr->dst_count; ++i) + size += sm4_register_order(&instr->dsts[i].reg); for (i = 0; i < instr->src_count; ++i) size += sm4_register_order(&instr->srcs[i].reg); size += instr->idx_count; @@ -733,15 +732,15 @@ static void write_sm4_instruction(struct vkd3d_bytecode_buffer *buffer, const st token |= (size << VKD3D_SM4_INSTRUCTION_LENGTH_SHIFT); put_u32(buffer, token); - if (instr->has_dst) + for (i = 0; i < instr->dst_count; ++i) { - token = sm4_encode_register(&instr->dst.reg); - if (instr->dst.reg.dim == VKD3D_SM4_DIMENSION_VEC4) - token |= instr->dst.writemask << VKD3D_SM4_WRITEMASK_SHIFT; + token = sm4_encode_register(&instr->dsts[i].reg); + if (instr->dsts[i].reg.dim == VKD3D_SM4_DIMENSION_VEC4) + token |= instr->dsts[i].writemask << VKD3D_SM4_WRITEMASK_SHIFT; put_u32(buffer, token); - for (j = 0; j < instr->dst.reg.idx_count; ++j) - put_u32(buffer, instr->dst.reg.idx[j]); + for (j = 0; j < instr->dsts[i].reg.idx_count; ++j) + put_u32(buffer, instr->dsts[i].reg.idx[j]); } for (i = 0; i < instr->src_count; ++i) @@ -800,33 +799,33 @@ static void write_sm4_dcl_semantic(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b struct sm4_instruction instr = { - .dst.reg.dim = VKD3D_SM4_DIMENSION_VEC4, - .has_dst = 1, + .dsts[0].reg.dim = VKD3D_SM4_DIMENSION_VEC4, + .dst_count = 1, }; - if (hlsl_sm4_register_from_semantic(ctx, &var->semantic, output, &instr.dst.reg.type, &has_idx)) + if (hlsl_sm4_register_from_semantic(ctx, &var->semantic, output, &instr.dsts[0].reg.type, &has_idx)) { if (has_idx) { - instr.dst.reg.idx[0] = var->semantic.index; - instr.dst.reg.idx_count = 1; + instr.dsts[0].reg.idx[0] = var->semantic.index; + instr.dsts[0].reg.idx_count = 1; } else { - instr.dst.reg.idx_count = 0; + instr.dsts[0].reg.idx_count = 0; } - instr.dst.writemask = (1 << var->data_type->dimx) - 1; + instr.dsts[0].writemask = (1 << var->data_type->dimx) - 1; } else { - instr.dst.reg.type = output ? VKD3D_SM4_RT_OUTPUT : VKD3D_SM4_RT_INPUT; - instr.dst.reg.idx[0] = var->reg.id; - instr.dst.reg.idx_count = 1; - instr.dst.writemask = var->reg.writemask; + instr.dsts[0].reg.type = output ? VKD3D_SM4_RT_OUTPUT : VKD3D_SM4_RT_INPUT; + instr.dsts[0].reg.idx[0] = var->reg.id; + instr.dsts[0].reg.idx_count = 1; + instr.dsts[0].writemask = var->reg.writemask; } - if (instr.dst.reg.type == VKD3D_SM4_RT_DEPTHOUT) - instr.dst.reg.dim = VKD3D_SM4_DIMENSION_SCALAR; + if (instr.dsts[0].reg.type == VKD3D_SM4_RT_DEPTHOUT) + instr.dsts[0].reg.dim = VKD3D_SM4_DIMENSION_SCALAR; hlsl_sm4_usage_from_semantic(ctx, &var->semantic, output, &usage); @@ -914,11 +913,11 @@ static void write_sm4_unary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d_ memset(&instr, 0, sizeof(instr)); instr.opcode = opcode; - sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, dst); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, dst); + instr.dst_count = 1; sm4_register_from_node(&instr.srcs[0].reg, &writemask, src); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.srcs[0].reg.mod = src_mod; instr.src_count = 1; @@ -934,13 +933,13 @@ static void write_sm4_binary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d memset(&instr, 0, sizeof(instr)); instr.opcode = opcode; - sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, dst); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, dst); + instr.dst_count = 1; sm4_register_from_node(&instr.srcs[0].reg, &writemask, src1); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); sm4_register_from_node(&instr.srcs[1].reg, &writemask, src2); - instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.src_count = 2; write_sm4_instruction(buffer, &instr); @@ -956,8 +955,8 @@ static void write_sm4_constant(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV; - sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, &constant->node); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, &constant->node); + instr.dst_count = 1; instr.srcs[0].reg.dim = (dimx > 1) ? VKD3D_SM4_DIMENSION_VEC4 : VKD3D_SM4_DIMENSION_SCALAR; instr.srcs[0].reg.type = VKD3D_SM4_RT_IMMCONST; @@ -1181,11 +1180,11 @@ static void write_sm4_load(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV; - sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, &load->node); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, &load->node); + instr.dst_count = 1; sm4_register_from_deref(ctx, &instr.srcs[0].reg, &writemask, &load->src, load->node.data_type); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.src_count = 1; write_sm4_instruction(buffer, &instr); @@ -1207,12 +1206,12 @@ static void write_sm4_store(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV; - sm4_register_from_deref(ctx, &instr.dst.reg, &writemask, &store->lhs, rhs->data_type); - instr.dst.writemask = hlsl_combine_writemasks(writemask, store->writemask); - instr.has_dst = 1; + sm4_register_from_deref(ctx, &instr.dsts[0].reg, &writemask, &store->lhs, rhs->data_type); + instr.dsts[0].writemask = hlsl_combine_writemasks(writemask, store->writemask); + instr.dst_count = 1; sm4_register_from_node(&instr.srcs[0].reg, &writemask, rhs); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.src_count = 1; write_sm4_instruction(buffer, &instr); @@ -1227,12 +1226,12 @@ static void write_sm4_swizzle(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV; - sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, &swizzle->node); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, &swizzle->node); + instr.dst_count = 1; sm4_register_from_node(&instr.srcs[0].reg, &writemask, swizzle->val.node); instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_combine_swizzles(hlsl_swizzle_from_writemask(writemask), - swizzle->swizzle, swizzle->node.data_type->dimx), instr.dst.writemask); + swizzle->swizzle, swizzle->node.data_type->dimx), instr.dsts[0].writemask); instr.src_count = 1; write_sm4_instruction(buffer, &instr); -- 2.33.0
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Il 28/09/21 03:51, Zebediah Figura ha scritto:
From: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Some instructions (e.g. umul) have multiple destination registers.
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl_sm4.c | 85 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 43 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 500c9f434..f407b4a63 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -572,7 +572,8 @@ struct sm4_instruction { struct sm4_register reg; unsigned int writemask; - } dst; + } dsts[1]; + unsigned int dst_count;
struct { @@ -583,8 +584,6 @@ struct sm4_instruction
uint32_t idx[2]; unsigned int idx_count; - - unsigned int has_dst; };
static unsigned int sm4_swizzle_type(enum vkd3d_sm4_register_type type) @@ -724,8 +723,8 @@ static void write_sm4_instruction(struct vkd3d_bytecode_buffer *buffer, const st uint32_t token = instr->opcode; unsigned int size = 1, i, j;
- if (instr->has_dst) - size += sm4_register_order(&instr->dst.reg); + for (i = 0; i < instr->dst_count; ++i) + size += sm4_register_order(&instr->dsts[i].reg); for (i = 0; i < instr->src_count; ++i) size += sm4_register_order(&instr->srcs[i].reg); size += instr->idx_count; @@ -733,15 +732,15 @@ static void write_sm4_instruction(struct vkd3d_bytecode_buffer *buffer, const st token |= (size << VKD3D_SM4_INSTRUCTION_LENGTH_SHIFT); put_u32(buffer, token);
- if (instr->has_dst) + for (i = 0; i < instr->dst_count; ++i) { - token = sm4_encode_register(&instr->dst.reg); - if (instr->dst.reg.dim == VKD3D_SM4_DIMENSION_VEC4) - token |= instr->dst.writemask << VKD3D_SM4_WRITEMASK_SHIFT; + token = sm4_encode_register(&instr->dsts[i].reg); + if (instr->dsts[i].reg.dim == VKD3D_SM4_DIMENSION_VEC4) + token |= instr->dsts[i].writemask << VKD3D_SM4_WRITEMASK_SHIFT; put_u32(buffer, token);
- for (j = 0; j < instr->dst.reg.idx_count; ++j) - put_u32(buffer, instr->dst.reg.idx[j]); + for (j = 0; j < instr->dsts[i].reg.idx_count; ++j) + put_u32(buffer, instr->dsts[i].reg.idx[j]); }
for (i = 0; i < instr->src_count; ++i) @@ -800,33 +799,33 @@ static void write_sm4_dcl_semantic(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b
struct sm4_instruction instr = { - .dst.reg.dim = VKD3D_SM4_DIMENSION_VEC4, - .has_dst = 1, + .dsts[0].reg.dim = VKD3D_SM4_DIMENSION_VEC4, + .dst_count = 1, };
- if (hlsl_sm4_register_from_semantic(ctx, &var->semantic, output, &instr.dst.reg.type, &has_idx)) + if (hlsl_sm4_register_from_semantic(ctx, &var->semantic, output, &instr.dsts[0].reg.type, &has_idx)) { if (has_idx) { - instr.dst.reg.idx[0] = var->semantic.index; - instr.dst.reg.idx_count = 1; + instr.dsts[0].reg.idx[0] = var->semantic.index; + instr.dsts[0].reg.idx_count = 1; } else { - instr.dst.reg.idx_count = 0; + instr.dsts[0].reg.idx_count = 0; } - instr.dst.writemask = (1 << var->data_type->dimx) - 1; + instr.dsts[0].writemask = (1 << var->data_type->dimx) - 1; } else { - instr.dst.reg.type = output ? VKD3D_SM4_RT_OUTPUT : VKD3D_SM4_RT_INPUT; - instr.dst.reg.idx[0] = var->reg.id; - instr.dst.reg.idx_count = 1; - instr.dst.writemask = var->reg.writemask; + instr.dsts[0].reg.type = output ? VKD3D_SM4_RT_OUTPUT : VKD3D_SM4_RT_INPUT; + instr.dsts[0].reg.idx[0] = var->reg.id; + instr.dsts[0].reg.idx_count = 1; + instr.dsts[0].writemask = var->reg.writemask; }
- if (instr.dst.reg.type == VKD3D_SM4_RT_DEPTHOUT) - instr.dst.reg.dim = VKD3D_SM4_DIMENSION_SCALAR; + if (instr.dsts[0].reg.type == VKD3D_SM4_RT_DEPTHOUT) + instr.dsts[0].reg.dim = VKD3D_SM4_DIMENSION_SCALAR;
hlsl_sm4_usage_from_semantic(ctx, &var->semantic, output, &usage);
@@ -914,11 +913,11 @@ static void write_sm4_unary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d_ memset(&instr, 0, sizeof(instr)); instr.opcode = opcode;
- sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, dst); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, dst); + instr.dst_count = 1;
sm4_register_from_node(&instr.srcs[0].reg, &writemask, src); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.srcs[0].reg.mod = src_mod; instr.src_count = 1;
@@ -934,13 +933,13 @@ static void write_sm4_binary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d memset(&instr, 0, sizeof(instr)); instr.opcode = opcode;
- sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, dst); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, dst); + instr.dst_count = 1;
sm4_register_from_node(&instr.srcs[0].reg, &writemask, src1); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); sm4_register_from_node(&instr.srcs[1].reg, &writemask, src2); - instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.src_count = 2;
write_sm4_instruction(buffer, &instr); @@ -956,8 +955,8 @@ static void write_sm4_constant(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV;
- sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, &constant->node); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, &constant->node); + instr.dst_count = 1;
instr.srcs[0].reg.dim = (dimx > 1) ? VKD3D_SM4_DIMENSION_VEC4 : VKD3D_SM4_DIMENSION_SCALAR; instr.srcs[0].reg.type = VKD3D_SM4_RT_IMMCONST; @@ -1181,11 +1180,11 @@ static void write_sm4_load(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV;
- sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, &load->node); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, &load->node); + instr.dst_count = 1;
sm4_register_from_deref(ctx, &instr.srcs[0].reg, &writemask, &load->src, load->node.data_type); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.src_count = 1;
write_sm4_instruction(buffer, &instr); @@ -1207,12 +1206,12 @@ static void write_sm4_store(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV;
- sm4_register_from_deref(ctx, &instr.dst.reg, &writemask, &store->lhs, rhs->data_type); - instr.dst.writemask = hlsl_combine_writemasks(writemask, store->writemask); - instr.has_dst = 1; + sm4_register_from_deref(ctx, &instr.dsts[0].reg, &writemask, &store->lhs, rhs->data_type); + instr.dsts[0].writemask = hlsl_combine_writemasks(writemask, store->writemask); + instr.dst_count = 1;
sm4_register_from_node(&instr.srcs[0].reg, &writemask, rhs); - instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask); + instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); instr.src_count = 1;
write_sm4_instruction(buffer, &instr); @@ -1227,12 +1226,12 @@ static void write_sm4_swizzle(struct hlsl_ctx *ctx, memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_MOV;
- sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, &swizzle->node); - instr.has_dst = 1; + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, &swizzle->node); + instr.dst_count = 1;
sm4_register_from_node(&instr.srcs[0].reg, &writemask, swizzle->val.node); instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_combine_swizzles(hlsl_swizzle_from_writemask(writemask), - swizzle->swizzle, swizzle->node.data_type->dimx), instr.dst.writemask); + swizzle->swizzle, swizzle->node.data_type->dimx), instr.dsts[0].writemask); instr.src_count = 1;
write_sm4_instruction(buffer, &instr);
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/hlsl.h | 4 +++- libs/vkd3d-shader/hlsl.y | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8a2286c45..c546bf06f 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1108,7 +1108,7 @@ static void dump_ir_expr(struct vkd3d_string_buffer *buffer, const struct hlsl_i unsigned int i; vkd3d_string_buffer_printf(buffer, "%s (", debug_hlsl_expr_op(expr->op)); - for (i = 0; i < 3 && expr->operands[i].node; ++i) + for (i = 0; i < HLSL_MAX_OPERANDS && expr->operands[i].node; ++i) { dump_src(buffer, &expr->operands[i]); vkd3d_string_buffer_printf(buffer, " "); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index abc870f4f..7e6283921 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -323,11 +323,13 @@ enum hlsl_ir_expr_op HLSL_OP3_LERP, }; +#define HLSL_MAX_OPERANDS 3 + struct hlsl_ir_expr { struct hlsl_ir_node node; enum hlsl_ir_expr_op op; - struct hlsl_src operands[3]; + struct hlsl_src operands[HLSL_MAX_OPERANDS]; }; enum hlsl_ir_jump_type diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8ad892f9e..21e1cb455 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1022,15 +1022,15 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type return hlsl_new_type(ctx, NULL, type, base, dimx, dimy); } -static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, - enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[3], struct vkd3d_shader_location *loc) +static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, + struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct vkd3d_shader_location *loc) { struct hlsl_ir_expr *expr; struct hlsl_type *type; unsigned int i; type = operands[0]->data_type; - for (i = 1; i <= 2; ++i) + for (i = 1; i < HLSL_MAX_OPERANDS; ++i) { if (!operands[i]) break; @@ -1038,7 +1038,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, if (!type) return NULL; } - for (i = 0; i <= 2; ++i) + for (i = 0; i < HLSL_MAX_OPERANDS; ++i) { struct hlsl_ir_expr *cast; @@ -1062,7 +1062,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, return NULL; init_node(&expr->node, HLSL_IR_EXPR, type, *loc); expr->op = op; - for (i = 0; i <= 2; ++i) + for (i = 0; i < HLSL_MAX_OPERANDS; ++i) hlsl_src_from_node(&expr->operands[i], operands[i]); list_add_tail(instrs, &expr->node.entry); @@ -1083,7 +1083,7 @@ static struct list *add_unary_expr(struct hlsl_ctx *ctx, struct list *instrs, static struct list *add_binary_expr(struct hlsl_ctx *ctx, struct list *list1, struct list *list2, enum hlsl_ir_expr_op op, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {node_from_list(list1), node_from_list(list2)}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {node_from_list(list1), node_from_list(list2)}; list_move_tail(list1, list2); vkd3d_free(list2); @@ -1157,7 +1157,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in if (assign_op == ASSIGN_OP_SUB) { - struct hlsl_ir_node *args[3] = {rhs}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {rhs}; struct hlsl_ir_expr *expr; if (!(expr = add_expr(ctx, instrs, HLSL_OP1_NEG, args, &rhs->loc))) @@ -1167,8 +1167,8 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in } if (assign_op != ASSIGN_OP_ASSIGN) { + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {lhs, rhs}; enum hlsl_ir_expr_op op = op_from_assignment(assign_op); - struct hlsl_ir_node *args[3] = {lhs, rhs}; struct hlsl_ir_expr *expr; assert(op); @@ -1556,7 +1556,7 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c static bool intrinsic_abs(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0]}; return !!add_expr(ctx, params->instrs, HLSL_OP1_ABS, args, &loc); } @@ -1564,7 +1564,7 @@ static bool intrinsic_abs(struct hlsl_ctx *ctx, static bool intrinsic_clamp(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0], params->args[1]}; struct hlsl_ir_expr *max; if (!(max = add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc))) @@ -1578,7 +1578,7 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx, static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0], params->args[1]}; return !!add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc); } @@ -1586,7 +1586,7 @@ static bool intrinsic_max(struct hlsl_ctx *ctx, static bool intrinsic_pow(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {0}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; struct hlsl_ir_node *log, *exp; struct hlsl_ir_expr *mul; @@ -1608,7 +1608,7 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx, static bool intrinsic_saturate(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0]}; return !!add_expr(ctx, params->instrs, HLSL_OP1_SAT, args, &loc); } -- 2.33.0
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Il 28/09/21 03:51, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/hlsl.h | 4 +++- libs/vkd3d-shader/hlsl.y | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8a2286c45..c546bf06f 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1108,7 +1108,7 @@ static void dump_ir_expr(struct vkd3d_string_buffer *buffer, const struct hlsl_i unsigned int i;
vkd3d_string_buffer_printf(buffer, "%s (", debug_hlsl_expr_op(expr->op)); - for (i = 0; i < 3 && expr->operands[i].node; ++i) + for (i = 0; i < HLSL_MAX_OPERANDS && expr->operands[i].node; ++i) { dump_src(buffer, &expr->operands[i]); vkd3d_string_buffer_printf(buffer, " "); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index abc870f4f..7e6283921 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -323,11 +323,13 @@ enum hlsl_ir_expr_op HLSL_OP3_LERP, };
+#define HLSL_MAX_OPERANDS 3 + struct hlsl_ir_expr { struct hlsl_ir_node node; enum hlsl_ir_expr_op op; - struct hlsl_src operands[3]; + struct hlsl_src operands[HLSL_MAX_OPERANDS]; };
enum hlsl_ir_jump_type diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8ad892f9e..21e1cb455 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1022,15 +1022,15 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type return hlsl_new_type(ctx, NULL, type, base, dimx, dimy); }
-static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, - enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[3], struct vkd3d_shader_location *loc) +static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, + struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct vkd3d_shader_location *loc) { struct hlsl_ir_expr *expr; struct hlsl_type *type; unsigned int i;
type = operands[0]->data_type; - for (i = 1; i <= 2; ++i) + for (i = 1; i < HLSL_MAX_OPERANDS; ++i) { if (!operands[i]) break; @@ -1038,7 +1038,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, if (!type) return NULL; } - for (i = 0; i <= 2; ++i) + for (i = 0; i < HLSL_MAX_OPERANDS; ++i) { struct hlsl_ir_expr *cast;
@@ -1062,7 +1062,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, return NULL; init_node(&expr->node, HLSL_IR_EXPR, type, *loc); expr->op = op; - for (i = 0; i <= 2; ++i) + for (i = 0; i < HLSL_MAX_OPERANDS; ++i) hlsl_src_from_node(&expr->operands[i], operands[i]); list_add_tail(instrs, &expr->node.entry);
@@ -1083,7 +1083,7 @@ static struct list *add_unary_expr(struct hlsl_ctx *ctx, struct list *instrs, static struct list *add_binary_expr(struct hlsl_ctx *ctx, struct list *list1, struct list *list2, enum hlsl_ir_expr_op op, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {node_from_list(list1), node_from_list(list2)}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {node_from_list(list1), node_from_list(list2)};
list_move_tail(list1, list2); vkd3d_free(list2); @@ -1157,7 +1157,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in
if (assign_op == ASSIGN_OP_SUB) { - struct hlsl_ir_node *args[3] = {rhs}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {rhs}; struct hlsl_ir_expr *expr;
if (!(expr = add_expr(ctx, instrs, HLSL_OP1_NEG, args, &rhs->loc))) @@ -1167,8 +1167,8 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in } if (assign_op != ASSIGN_OP_ASSIGN) { + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {lhs, rhs}; enum hlsl_ir_expr_op op = op_from_assignment(assign_op); - struct hlsl_ir_node *args[3] = {lhs, rhs}; struct hlsl_ir_expr *expr;
assert(op); @@ -1556,7 +1556,7 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c static bool intrinsic_abs(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0]};
return !!add_expr(ctx, params->instrs, HLSL_OP1_ABS, args, &loc); } @@ -1564,7 +1564,7 @@ static bool intrinsic_abs(struct hlsl_ctx *ctx, static bool intrinsic_clamp(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0], params->args[1]}; struct hlsl_ir_expr *max;
if (!(max = add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc))) @@ -1578,7 +1578,7 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx, static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0], params->args[1]};
return !!add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc); } @@ -1586,7 +1586,7 @@ static bool intrinsic_max(struct hlsl_ctx *ctx, static bool intrinsic_pow(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {0}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0}; struct hlsl_ir_node *log, *exp; struct hlsl_ir_expr *mul;
@@ -1608,7 +1608,7 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx, static bool intrinsic_saturate(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc) { - struct hlsl_ir_node *args[3] = {params->args[0]}; + struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {params->args[0]};
return !!add_expr(ctx, params->instrs, HLSL_OP1_SAT, args, &loc); }
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/hlsl.y | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index c546bf06f..8a531d627 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -608,7 +608,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned if (!(swizzle = hlsl_alloc(ctx, sizeof(*swizzle)))) return NULL; init_node(&swizzle->node, HLSL_IR_SWIZZLE, - hlsl_new_type(ctx, NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1), *loc); + ctx->builtin_types.vector[val->data_type->base_type][components - 1], *loc); hlsl_src_from_node(&swizzle->val, val); swizzle->swizzle = s; return swizzle; diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 21e1cb455..56b996991 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2397,7 +2397,7 @@ type: YYABORT; } - $$ = hlsl_new_type(ctx, NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1); + $$ = ctx->builtin_types.vector[$3->base_type][$5 - 1]; } | KW_MATRIX '<' type ',' C_INTEGER ',' C_INTEGER '>' { -- 2.33.0
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> --- Just FTR, eventually I'll propose a helper for accessing builtin numeric types[1]. [1] https://repo.or.cz/vkd3d/zf.git/commitdiff/f4af1b6a0486dd4dc692795170dedfa06... Il 28/09/21 03:51, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/hlsl.y | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index c546bf06f..8a531d627 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -608,7 +608,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned if (!(swizzle = hlsl_alloc(ctx, sizeof(*swizzle)))) return NULL; init_node(&swizzle->node, HLSL_IR_SWIZZLE, - hlsl_new_type(ctx, NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1), *loc); + ctx->builtin_types.vector[val->data_type->base_type][components - 1], *loc); hlsl_src_from_node(&swizzle->val, val); swizzle->swizzle = s; return swizzle; diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 21e1cb455..56b996991 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2397,7 +2397,7 @@ type: YYABORT; }
- $$ = hlsl_new_type(ctx, NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1); + $$ = ctx->builtin_types.vector[$3->base_type][$5 - 1]; } | KW_MATRIX '<' type ',' C_INTEGER ',' C_INTEGER '>' {
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 3 ++- libs/vkd3d-shader/hlsl.h | 4 ++-- libs/vkd3d-shader/hlsl.y | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8a531d627..6dfcc7bb5 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -200,7 +200,7 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type } } -struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, +static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) { struct hlsl_type *type; @@ -1658,6 +1658,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) sprintf(name, "%s%ux%u", names[bt], y, x); type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_MATRIX, bt, x, y); hlsl_scope_add_type(ctx->globals, type); + ctx->builtin_types.matrix[bt][x - 1][y - 1] = type; if (y == 1) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 7e6283921..9686a496b 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -459,6 +459,8 @@ struct hlsl_ctx { struct hlsl_type *scalar[HLSL_TYPE_LAST_SCALAR + 1]; struct hlsl_type *vector[HLSL_TYPE_LAST_SCALAR + 1][4]; + /* matrix[float][2][4] is a float4x2, i.e. dimx = 2, dimy = 4 */ + struct hlsl_type *matrix[HLSL_TYPE_LAST_SCALAR + 1][4][4]; struct hlsl_type *sampler[HLSL_SAMPLER_DIM_MAX + 1]; struct hlsl_type *Void; } builtin_types; @@ -653,8 +655,6 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned struct hlsl_ir_node *val, struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc); -struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, - enum hlsl_base_type base_type, unsigned dimx, unsigned dimy); struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location loc); struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 56b996991..b058ee502 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1019,7 +1019,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type return ctx->builtin_types.scalar[base]; if (type == HLSL_CLASS_VECTOR) return ctx->builtin_types.vector[base][dimx - 1]; - return hlsl_new_type(ctx, NULL, type, base, dimx, dimy); + return ctx->builtin_types.matrix[base][dimx - 1][dimy - 1]; } static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, @@ -2425,7 +2425,7 @@ type: YYABORT; } - $$ = hlsl_new_type(ctx, NULL, HLSL_CLASS_MATRIX, $3->base_type, $7, $5); + $$ = ctx->builtin_types.matrix[$3->base_type][$7 - 1][$5 - 1]; } | KW_VOID { -- 2.33.0
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Il 28/09/21 03:51, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 3 ++- libs/vkd3d-shader/hlsl.h | 4 ++-- libs/vkd3d-shader/hlsl.y | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8a531d627..6dfcc7bb5 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -200,7 +200,7 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type } }
-struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, +static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) { struct hlsl_type *type; @@ -1658,6 +1658,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) sprintf(name, "%s%ux%u", names[bt], y, x); type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_MATRIX, bt, x, y); hlsl_scope_add_type(ctx->globals, type); + ctx->builtin_types.matrix[bt][x - 1][y - 1] = type;
if (y == 1) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 7e6283921..9686a496b 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -459,6 +459,8 @@ struct hlsl_ctx { struct hlsl_type *scalar[HLSL_TYPE_LAST_SCALAR + 1]; struct hlsl_type *vector[HLSL_TYPE_LAST_SCALAR + 1][4]; + /* matrix[float][2][4] is a float4x2, i.e. dimx = 2, dimy = 4 */ + struct hlsl_type *matrix[HLSL_TYPE_LAST_SCALAR + 1][4][4]; struct hlsl_type *sampler[HLSL_SAMPLER_DIM_MAX + 1]; struct hlsl_type *Void; } builtin_types; @@ -653,8 +655,6 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned struct hlsl_ir_node *val, struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc); -struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, - enum hlsl_base_type base_type, unsigned dimx, unsigned dimy); struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location loc); struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 56b996991..b058ee502 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1019,7 +1019,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type return ctx->builtin_types.scalar[base]; if (type == HLSL_CLASS_VECTOR) return ctx->builtin_types.vector[base][dimx - 1]; - return hlsl_new_type(ctx, NULL, type, base, dimx, dimy); + return ctx->builtin_types.matrix[base][dimx - 1][dimy - 1]; }
static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op, @@ -2425,7 +2425,7 @@ type: YYABORT; }
- $$ = hlsl_new_type(ctx, NULL, HLSL_CLASS_MATRIX, $3->base_type, $7, $5); + $$ = ctx->builtin_types.matrix[$3->base_type][$7 - 1][$5 - 1]; } | KW_VOID {
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6dfcc7bb5..d106cc0b2 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -207,7 +207,11 @@ static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, e if (!(type = hlsl_alloc(ctx, sizeof(*type)))) return NULL; - type->name = name; + if (!(type->name = hlsl_strdup(ctx, name))) + { + vkd3d_free(type); + return NULL; + } type->type = type_class; type->base_type = base_type; type->dimx = dimx; @@ -1656,21 +1660,21 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) for (x = 1; x <= 4; ++x) { sprintf(name, "%s%ux%u", names[bt], y, x); - type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_MATRIX, bt, x, y); + type = hlsl_new_type(ctx, name, HLSL_CLASS_MATRIX, bt, x, y); hlsl_scope_add_type(ctx->globals, type); ctx->builtin_types.matrix[bt][x - 1][y - 1] = type; if (y == 1) { sprintf(name, "%s%u", names[bt], x); - type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_VECTOR, bt, x, y); + type = hlsl_new_type(ctx, name, HLSL_CLASS_VECTOR, bt, x, y); hlsl_scope_add_type(ctx->globals, type); ctx->builtin_types.vector[bt][x - 1] = type; if (x == 1) { sprintf(name, "%s", names[bt]); - type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_SCALAR, bt, x, y); + type = hlsl_new_type(ctx, name, HLSL_CLASS_SCALAR, bt, x, y); hlsl_scope_add_type(ctx->globals, type); ctx->builtin_types.scalar[bt] = type; } @@ -1681,16 +1685,16 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) for (bt = 0; bt <= HLSL_SAMPLER_DIM_MAX; ++bt) { - type = hlsl_new_type(ctx, hlsl_strdup(ctx, sampler_names[bt]), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + type = hlsl_new_type(ctx, sampler_names[bt], HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); type->sampler_dim = bt; ctx->builtin_types.sampler[bt] = type; } - ctx->builtin_types.Void = hlsl_new_type(ctx, hlsl_strdup(ctx, "void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1); + ctx->builtin_types.Void = hlsl_new_type(ctx, "void", HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1); for (i = 0; i < ARRAY_SIZE(effect_types); ++i) { - type = hlsl_new_type(ctx, hlsl_strdup(ctx, effect_types[i].name), effect_types[i].class, + type = hlsl_new_type(ctx, effect_types[i].name, effect_types[i].class, effect_types[i].base_type, effect_types[i].dimx, effect_types[i].dimy); hlsl_scope_add_type(ctx->globals, type); } -- 2.33.0
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> -- Though the result of hlsl_new_type is never checked for being non-NULL. If allocation fails, UB immediately happens. Not worse than current situation, though. Il 28/09/21 03:51, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6dfcc7bb5..d106cc0b2 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -207,7 +207,11 @@ static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, e
if (!(type = hlsl_alloc(ctx, sizeof(*type)))) return NULL; - type->name = name; + if (!(type->name = hlsl_strdup(ctx, name))) + { + vkd3d_free(type); + return NULL; + } type->type = type_class; type->base_type = base_type; type->dimx = dimx; @@ -1656,21 +1660,21 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) for (x = 1; x <= 4; ++x) { sprintf(name, "%s%ux%u", names[bt], y, x); - type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_MATRIX, bt, x, y); + type = hlsl_new_type(ctx, name, HLSL_CLASS_MATRIX, bt, x, y); hlsl_scope_add_type(ctx->globals, type); ctx->builtin_types.matrix[bt][x - 1][y - 1] = type;
if (y == 1) { sprintf(name, "%s%u", names[bt], x); - type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_VECTOR, bt, x, y); + type = hlsl_new_type(ctx, name, HLSL_CLASS_VECTOR, bt, x, y); hlsl_scope_add_type(ctx->globals, type); ctx->builtin_types.vector[bt][x - 1] = type;
if (x == 1) { sprintf(name, "%s", names[bt]); - type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_SCALAR, bt, x, y); + type = hlsl_new_type(ctx, name, HLSL_CLASS_SCALAR, bt, x, y); hlsl_scope_add_type(ctx->globals, type); ctx->builtin_types.scalar[bt] = type; } @@ -1681,16 +1685,16 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
for (bt = 0; bt <= HLSL_SAMPLER_DIM_MAX; ++bt) { - type = hlsl_new_type(ctx, hlsl_strdup(ctx, sampler_names[bt]), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + type = hlsl_new_type(ctx, sampler_names[bt], HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); type->sampler_dim = bt; ctx->builtin_types.sampler[bt] = type; }
- ctx->builtin_types.Void = hlsl_new_type(ctx, hlsl_strdup(ctx, "void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1); + ctx->builtin_types.Void = hlsl_new_type(ctx, "void", HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
for (i = 0; i < ARRAY_SIZE(effect_types); ++i) { - type = hlsl_new_type(ctx, hlsl_strdup(ctx, effect_types[i].name), effect_types[i].class, + type = hlsl_new_type(ctx, effect_types[i].name, effect_types[i].class, effect_types[i].base_type, effect_types[i].dimx, effect_types[i].dimy); hlsl_scope_add_type(ctx->globals, type); }
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com> Il 28/09/21 03:51, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com> --- Makefile.am | 1 + libs/vkd3d-shader/hlsl.h | 2 + libs/vkd3d-shader/hlsl.y | 54 ++++++- tests/hlsl-state-block-syntax.shader_test | 173 ++++++++++++++++++++++ 4 files changed, 223 insertions(+), 7 deletions(-) create mode 100644 tests/hlsl-state-block-syntax.shader_test
diff --git a/Makefile.am b/Makefile.am index 4a2bf8e18..bc33e0f60 100644 --- a/Makefile.am +++ b/Makefile.am @@ -74,6 +74,7 @@ vkd3d_shader_tests = \ tests/hlsl-return-implicit-conversion.shader_test \ tests/hlsl-return-void.shader_test \ tests/hlsl-shape.shader_test \ + tests/hlsl-state-block-syntax.shader_test \ tests/hlsl-static-initializer.shader_test \ tests/hlsl-storage-qualifiers.shader_test \ tests/hlsl-struct-assignment.shader_test \ diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 27afeedd4..abc870f4f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -469,6 +469,8 @@ struct hlsl_ctx size_t count, size; } constant_defs; uint32_t temp_count; + + uint32_t in_state_block : 1; };
enum hlsl_error_level diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 19745e725..8ad892f9e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2558,6 +2558,23 @@ variable_decl: $$->reg_reservation = $3.reg_reservation; }
+state: + any_identifier '=' expr ';' + { + vkd3d_free($1); + hlsl_free_instr_list($3); + } + +state_block_start: + %empty + { + ctx->in_state_block = 1; + } + +state_block: + %empty + | state_block state + variable_def: variable_decl | variable_decl '=' complex_initializer @@ -2565,6 +2582,11 @@ variable_def: $$ = $1; $$->initializer = $3; } + | variable_decl '{' state_block_start state_block '}' + { + $$ = $1; + ctx->in_state_block = 0; + }
arrays: %empty @@ -2861,13 +2883,10 @@ primary_expr: hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Variable \"%s\" is not defined.", $1); YYABORT; } - if ((load = hlsl_new_var_load(ctx, var, @1))) - { - if (!($$ = make_list(ctx, &load->node))) - YYABORT; - } - else - $$ = NULL; + if (!(load = hlsl_new_var_load(ctx, var, @1))) + YYABORT; + if (!($$ = make_list(ctx, &load->node))) + YYABORT; } | '(' expr ')' { @@ -2878,6 +2897,27 @@ primary_expr: if (!($$ = add_call(ctx, $1, &$3, @1))) YYABORT; } + | NEW_IDENTIFIER + { + if (ctx->in_state_block) + { + struct hlsl_ir_load *load; + struct hlsl_ir_var *var; + + if (!(var = hlsl_new_synthetic_var(ctx, "<state-block-expr>", + ctx->builtin_types.scalar[HLSL_TYPE_INT], @1))) + YYABORT; + if (!(load = hlsl_new_var_load(ctx, var, @1))) + YYABORT; + if (!($$ = make_list(ctx, &load->node))) + YYABORT; + } + else + { + hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Identifier \"%s\" is not declared.\n", $1); + YYABORT; + } + }
postfix_expr: primary_expr diff --git a/tests/hlsl-state-block-syntax.shader_test b/tests/hlsl-state-block-syntax.shader_test new file mode 100644 index 000000000..26853bf40 --- /dev/null +++ b/tests/hlsl-state-block-syntax.shader_test @@ -0,0 +1,173 @@ +[pixel shader fail] +sampler s +{ + foo = float; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s = sampler_state +{ + foo = float; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + 2 = 3; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + 2; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + foo; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s +{ + foo = bar +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s {} + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f {} = 1; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f = 1 {}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +sampler s = sampler_state; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f {} : register(c1); + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = (sampler)2; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = (faketype)2; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = (sampler)bar; +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail] +float f +{ + foo = bar(); +}; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader] +float u : register(c1) {}; +float4 main() : sv_target +{ + float zero = 0; + float a {}; + float b + { + foo = bar; + foo = bar; + foo = (int)2; + foo = (int)bar; + foo = float4(bar, baz, qux, xyzzy); + foo = zero++; + }; + float c {}, d = 1, e; + struct {int a;} s {foo = bar;}; + return float4(0, 1, zero, 1); +} + +[test] +draw quad +probe all rgba (0, 1, 0, 1)
participants (4)
-
Giovanni Mascellani -
Henri Verbeet -
Matteo Bruni -
Zebediah Figura