Module: vkd3d Branch: master Commit: 0e3377a1be7c915d2ed8dd6e3c97ba085c8af867 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/0e3377a1be7c915d2ed8dd6e3c97ba...
Author: Zebediah Figura zfigura@codeweavers.com Date: Fri Jan 26 17:29:54 2024 -0600
vkd3d-shader/hlsl: Avoid using HLSL_CLASS_OBJECT without checking the base type.
As the diffstat shows, HLSL_CLASS_OBJECT does not really have much in common. Resource types (TEXTURE, SAMPLER, UAV) sometimes behave similarly to each other, but do not generally behave similarly to effect-specific types (string, shader, state, view). Most consumers of HLSL_CLASS_OBJECT subsequently check the base type anyway.
Hence we want to replace HLSL_TYPE_* with individual classes for object types. As a first step, change the last few places that only check HLSL_CLASS_OBJECT.
---
libs/vkd3d-shader/d3dbc.c | 12 ++---------- libs/vkd3d-shader/hlsl.c | 5 ++++- libs/vkd3d-shader/hlsl_codegen.c | 4 ++-- libs/vkd3d-shader/tpf.c | 12 +++--------- 4 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 099729fb..97650942 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -2572,19 +2572,11 @@ static void write_sm1_instructions(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b { if (instr->data_type) { - if (instr->data_type->class == HLSL_CLASS_MATRIX) + if (instr->data_type->class != HLSL_CLASS_SCALAR && instr->data_type->class != HLSL_CLASS_VECTOR) { - /* These need to be lowered. */ - hlsl_fixme(ctx, &instr->loc, "SM1 matrix expression."); - continue; - } - else if (instr->data_type->class == HLSL_CLASS_OBJECT) - { - hlsl_fixme(ctx, &instr->loc, "Object copy."); + hlsl_fixme(ctx, &instr->loc, "Class %#x should have been lowered or removed.", instr->data_type->class); break; } - - assert(instr->data_type->class == HLSL_CLASS_SCALAR || instr->data_type->class == HLSL_CLASS_VECTOR); }
switch (instr->type) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index a5248c89..da6f29f1 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1570,7 +1570,10 @@ bool hlsl_index_is_noncontiguous(struct hlsl_ir_index *index)
bool hlsl_index_is_resource_access(struct hlsl_ir_index *index) { - return index->val.node->data_type->class == HLSL_CLASS_OBJECT; + const struct hlsl_type *type = index->val.node->data_type; + + return type->class == HLSL_CLASS_OBJECT + && (type->base_type == HLSL_TYPE_TEXTURE || type->base_type == HLSL_TYPE_UAV); }
bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 4acedb78..15c60e50 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1565,7 +1565,7 @@ static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx, var->name, start, start + count, debug_hlsl_swizzle(swizzle, instr_component_count), new_instr, debug_hlsl_swizzle(ret_swizzle, instr_component_count));
- if (instr->data_type->class != HLSL_CLASS_OBJECT) + if (new_instr->data_type->class == HLSL_CLASS_SCALAR || new_instr->data_type->class == HLSL_CLASS_VECTOR) { struct hlsl_ir_node *swizzle_node;
@@ -1742,7 +1742,7 @@ static void copy_propagation_record_store(struct hlsl_ctx *ctx, struct hlsl_ir_s { unsigned int writemask = store->writemask;
- if (store->rhs.node->data_type->class == HLSL_CLASS_OBJECT) + if (!hlsl_is_numeric_type(store->rhs.node->data_type)) writemask = VKD3DSP_WRITEMASK_0; copy_propagation_set_value(ctx, var_def, start, writemask, store->rhs.node, store->node.index); } diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index c4a298b6..d5019a5d 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -5707,18 +5707,12 @@ static void write_sm4_block(const struct tpf_writer *tpf, const struct hlsl_bloc { if (instr->data_type) { - if (instr->data_type->class == HLSL_CLASS_MATRIX) + if (instr->data_type->class != HLSL_CLASS_SCALAR && instr->data_type->class != HLSL_CLASS_VECTOR) { - hlsl_fixme(tpf->ctx, &instr->loc, "Matrix operations need to be lowered."); + hlsl_fixme(tpf->ctx, &instr->loc, "Class %#x should have been lowered or removed.", + instr->data_type->class); break; } - else if (instr->data_type->class == HLSL_CLASS_OBJECT) - { - hlsl_fixme(tpf->ctx, &instr->loc, "Object copy."); - break; - } - - assert(instr->data_type->class == HLSL_CLASS_SCALAR || instr->data_type->class == HLSL_CLASS_VECTOR);
if (!instr->reg.allocated) {