Or: "Get rid of HLSL_CLASS_OBJECT, part 1."
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/d3dbc.c | 13 ++++--- libs/vkd3d-shader/fx.c | 8 +++++ libs/vkd3d-shader/hlsl.c | 61 ++++++++++++++++++++++++++------ libs/vkd3d-shader/hlsl.h | 2 +- libs/vkd3d-shader/hlsl_codegen.c | 3 ++ libs/vkd3d-shader/tpf.c | 1 + 6 files changed, 71 insertions(+), 17 deletions(-)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 4685afa08..78818b366 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1514,10 +1514,11 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type) return D3DXPC_STRUCT; case HLSL_CLASS_VECTOR: return D3DXPC_VECTOR; - default: - ERR("Invalid class %#x.\n", type->class); - vkd3d_unreachable(); + case HLSL_CLASS_VOID: + /* This shouldn't happen. */ } + + vkd3d_unreachable(); }
D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) @@ -1595,8 +1596,6 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) break; case HLSL_TYPE_VERTEXSHADER: return D3DXPT_VERTEXSHADER; - case HLSL_TYPE_VOID: - return D3DXPT_VOID; default: vkd3d_unreachable(); } @@ -1607,6 +1606,10 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type)
case HLSL_CLASS_STRUCT: return D3DXPT_VOID; + + case HLSL_CLASS_VOID: + /* This shouldn't happen. */ + break; }
vkd3d_unreachable(); diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index 1d90cd70e..c94552da1 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -436,6 +436,11 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
case HLSL_CLASS_ARRAY: vkd3d_unreachable(); + + case HLSL_CLASS_VOID: + FIXME("Writing type class %u is not implemented.\n", type->class); + set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED); + return 0; }
size = stride = type->reg_size[HLSL_REGSET_NUMERIC] * sizeof(float); @@ -814,6 +819,9 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type default: return false; } + + case HLSL_CLASS_VOID: + return false; }
vkd3d_unreachable(); diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index ed80e2b75..6859e1a33 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -365,6 +365,9 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type } break; } + + case HLSL_CLASS_VOID: + break; } }
@@ -377,6 +380,25 @@ unsigned int hlsl_type_get_array_element_reg_size(const struct hlsl_type *type, return type->reg_size[regset]; }
+static struct hlsl_type *hlsl_new_simple_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class class) +{ + struct hlsl_type *type; + + if (!(type = hlsl_alloc(ctx, sizeof(*type)))) + return NULL; + if (!(type->name = hlsl_strdup(ctx, name))) + { + vkd3d_free(type); + return NULL; + } + type->class = class; + hlsl_type_calculate_reg_size(ctx, type); + + list_add_tail(&ctx->types, &type->entry); + + return type; +} + 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) { @@ -402,7 +424,22 @@ static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, e
static bool type_is_single_component(const struct hlsl_type *type) { - return type->class == HLSL_CLASS_SCALAR || type->class == HLSL_CLASS_OBJECT; + switch (type->class) + { + case HLSL_CLASS_SCALAR: + case HLSL_CLASS_OBJECT: + return true; + + case HLSL_CLASS_VECTOR: + case HLSL_CLASS_MATRIX: + case HLSL_CLASS_STRUCT: + case HLSL_CLASS_ARRAY: + return false; + + case HLSL_CLASS_VOID: + break; + } + vkd3d_unreachable(); }
/* Given a type and a component index, this function moves one step through the path required to @@ -525,7 +562,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty assert(idx == 0); break;
- default: + case HLSL_CLASS_VOID: vkd3d_unreachable(); } type = next_type; @@ -752,7 +789,6 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, if (!(type = hlsl_alloc(ctx, sizeof(*type)))) return NULL; type->class = HLSL_CLASS_STRUCT; - type->base_type = HLSL_TYPE_VOID; type->name = name; type->dimy = 1; type->e.record.fields = fields; @@ -896,9 +932,11 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type) case HLSL_CLASS_OBJECT: return 1;
- default: - vkd3d_unreachable(); + case HLSL_CLASS_VOID: + break; } + + vkd3d_unreachable(); }
bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2) @@ -2313,15 +2351,16 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru return string;
default: - vkd3d_string_buffer_printf(string, "<unexpected type>"); - return string; + break; } }
- default: - vkd3d_string_buffer_printf(string, "<unexpected type>"); - return string; + case HLSL_CLASS_VOID: + break; } + + vkd3d_string_buffer_printf(string, "<unexpected type>"); + return string; }
struct vkd3d_string_buffer *hlsl_component_to_string(struct hlsl_ctx *ctx, const struct hlsl_ir_var *var, @@ -3609,7 +3648,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) ctx->builtin_types.sampler[bt] = type; }
- ctx->builtin_types.Void = hlsl_new_type(ctx, "void", HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1); + ctx->builtin_types.Void = hlsl_new_simple_type(ctx, "void", HLSL_CLASS_VOID);
for (i = 0; i < ARRAY_SIZE(effect_types); ++i) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 3cb98b765..97bc087f8 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -79,6 +79,7 @@ enum hlsl_type_class HLSL_CLASS_STRUCT, HLSL_CLASS_ARRAY, HLSL_CLASS_OBJECT, + HLSL_CLASS_VOID, };
enum hlsl_base_type @@ -101,7 +102,6 @@ enum hlsl_base_type HLSL_TYPE_TECHNIQUE, HLSL_TYPE_EFFECT_GROUP, HLSL_TYPE_STRING, - HLSL_TYPE_VOID, };
enum hlsl_sampler_dim diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index eaa72836d..511b1a66e 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1634,6 +1634,9 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, /* FIXME: Actually we shouldn't even get here, but we don't split * matrices yet. */ return false; + + case HLSL_CLASS_VOID: + vkd3d_unreachable(); }
if (copy_propagation_replace_with_constant_vector(ctx, state, load, HLSL_SWIZZLE(X, Y, Z, W), &load->node)) diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index d5019a5dd..d0f0111f9 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3008,6 +3008,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type) case HLSL_CLASS_ARRAY: case HLSL_CLASS_STRUCT: case HLSL_CLASS_OBJECT: + case HLSL_CLASS_VOID: break; } vkd3d_unreachable();
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/d3dbc.c | 10 ++++++---- libs/vkd3d-shader/fx.c | 6 +++++- libs/vkd3d-shader/hlsl.c | 7 ++++++- libs/vkd3d-shader/hlsl.h | 2 +- libs/vkd3d-shader/hlsl_codegen.c | 1 + libs/vkd3d-shader/tpf.c | 1 + 6 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 78818b366..4932bcaf3 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1506,14 +1506,15 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type) return D3DXPC_MATRIX_COLUMNS; else return D3DXPC_MATRIX_ROWS; - case HLSL_CLASS_OBJECT: - return D3DXPC_OBJECT; case HLSL_CLASS_SCALAR: return D3DXPC_SCALAR; case HLSL_CLASS_STRUCT: return D3DXPC_STRUCT; case HLSL_CLASS_VECTOR: return D3DXPC_VECTOR; + case HLSL_CLASS_OBJECT: + case HLSL_CLASS_STRING: + return D3DXPC_OBJECT; case HLSL_CLASS_VOID: /* This shouldn't happen. */ } @@ -1574,8 +1575,6 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) vkd3d_unreachable(); } break; - case HLSL_TYPE_STRING: - return D3DXPT_STRING; case HLSL_TYPE_TEXTURE: switch (type->sampler_dim) { @@ -1607,6 +1606,9 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) case HLSL_CLASS_STRUCT: return D3DXPT_VOID;
+ case HLSL_CLASS_STRING: + return D3DXPT_STRING; + case HLSL_CLASS_VOID: /* This shouldn't happen. */ break; diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index c94552da1..e5770f10b 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -437,6 +437,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co case HLSL_CLASS_ARRAY: vkd3d_unreachable();
+ case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: FIXME("Writing type class %u is not implemented.\n", type->class); set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED); @@ -810,7 +811,6 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type break;
case HLSL_TYPE_SAMPLER: - case HLSL_TYPE_STRING: case HLSL_TYPE_PIXELSHADER: case HLSL_TYPE_VERTEXSHADER: hlsl_fixme(ctx, loc, "Write fx 2.0 parameter object type %#x.", type->base_type); @@ -820,6 +820,10 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type return false; }
+ case HLSL_CLASS_STRING: + hlsl_fixme(ctx, loc, "Write fx 2.0 parameter class %#x.", type->class); + return false; + case HLSL_CLASS_VOID: return false; } diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6859e1a33..c3170ff7b 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -366,6 +366,7 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type break; }
+ case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; } @@ -428,6 +429,7 @@ static bool type_is_single_component(const struct hlsl_type *type) { case HLSL_CLASS_SCALAR: case HLSL_CLASS_OBJECT: + case HLSL_CLASS_STRING: return true;
case HLSL_CLASS_VECTOR: @@ -559,6 +561,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty break;
case HLSL_CLASS_OBJECT: + case HLSL_CLASS_STRING: assert(idx == 0); break;
@@ -930,6 +933,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type) return hlsl_type_component_count(type->e.array.type) * type->e.array.elements_count;
case HLSL_CLASS_OBJECT: + case HLSL_CLASS_STRING: return 1;
case HLSL_CLASS_VOID: @@ -2355,6 +2359,7 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru } }
+ case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; } @@ -3532,7 +3537,6 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) {"matrix", HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4}, {"fxgroup", HLSL_CLASS_OBJECT, HLSL_TYPE_EFFECT_GROUP, 1, 1}, {"pass", HLSL_CLASS_OBJECT, HLSL_TYPE_PASS, 1, 1}, - {"STRING", HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1}, {"texture", HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1}, {"pixelshader", HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1}, {"vertexshader", HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1}, @@ -3649,6 +3653,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) }
ctx->builtin_types.Void = hlsl_new_simple_type(ctx, "void", HLSL_CLASS_VOID); + hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "STRING", HLSL_CLASS_STRING));
for (i = 0; i < ARRAY_SIZE(effect_types); ++i) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 97bc087f8..2b5eb043e 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -79,6 +79,7 @@ enum hlsl_type_class HLSL_CLASS_STRUCT, HLSL_CLASS_ARRAY, HLSL_CLASS_OBJECT, + HLSL_CLASS_STRING, HLSL_CLASS_VOID, };
@@ -101,7 +102,6 @@ enum hlsl_base_type HLSL_TYPE_DEPTHSTENCILVIEW, HLSL_TYPE_TECHNIQUE, HLSL_TYPE_EFFECT_GROUP, - HLSL_TYPE_STRING, };
enum hlsl_sampler_dim diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 511b1a66e..e1064b998 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1635,6 +1635,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, * matrices yet. */ return false;
+ case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: vkd3d_unreachable(); } diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index d0f0111f9..4bacbefd3 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3008,6 +3008,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type) case HLSL_CLASS_ARRAY: case HLSL_CLASS_STRUCT: case HLSL_CLASS_OBJECT: + case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; }
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/d3dbc.c | 38 +++++++------- libs/vkd3d-shader/fx.c | 29 ++++++----- libs/vkd3d-shader/hlsl.c | 85 +++++++++++++++++++------------- libs/vkd3d-shader/hlsl.h | 5 +- libs/vkd3d-shader/hlsl.y | 17 +++---- libs/vkd3d-shader/hlsl_codegen.c | 3 +- libs/vkd3d-shader/tpf.c | 29 +++++++---- 7 files changed, 119 insertions(+), 87 deletions(-)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 4932bcaf3..5cee482d5 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1513,6 +1513,7 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type) case HLSL_CLASS_VECTOR: return D3DXPC_VECTOR; case HLSL_CLASS_OBJECT: + case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: return D3DXPC_OBJECT; case HLSL_CLASS_VOID: @@ -1552,29 +1553,30 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) vkd3d_unreachable(); }
+ case HLSL_CLASS_SAMPLER: + switch (type->sampler_dim) + { + case HLSL_SAMPLER_DIM_1D: + return D3DXPT_SAMPLER1D; + case HLSL_SAMPLER_DIM_2D: + return D3DXPT_SAMPLER2D; + case HLSL_SAMPLER_DIM_3D: + return D3DXPT_SAMPLER3D; + case HLSL_SAMPLER_DIM_CUBE: + return D3DXPT_SAMPLERCUBE; + case HLSL_SAMPLER_DIM_GENERIC: + return D3DXPT_SAMPLER; + default: + ERR("Invalid dimension %#x.\n", type->sampler_dim); + vkd3d_unreachable(); + } + break; + case HLSL_CLASS_OBJECT: switch (type->base_type) { case HLSL_TYPE_PIXELSHADER: return D3DXPT_PIXELSHADER; - case HLSL_TYPE_SAMPLER: - switch (type->sampler_dim) - { - case HLSL_SAMPLER_DIM_1D: - return D3DXPT_SAMPLER1D; - case HLSL_SAMPLER_DIM_2D: - return D3DXPT_SAMPLER2D; - case HLSL_SAMPLER_DIM_3D: - return D3DXPT_SAMPLER3D; - case HLSL_SAMPLER_DIM_CUBE: - return D3DXPT_SAMPLERCUBE; - case HLSL_SAMPLER_DIM_GENERIC: - return D3DXPT_SAMPLER; - default: - ERR("Invalid dimension %#x.\n", type->sampler_dim); - vkd3d_unreachable(); - } - break; case HLSL_TYPE_TEXTURE: switch (type->sampler_dim) { diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index e5770f10b..c5caeadf8 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -437,6 +437,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co case HLSL_CLASS_ARRAY: vkd3d_unreachable();
+ case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: FIXME("Writing type class %u is not implemented.\n", type->class); @@ -810,7 +811,6 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type } break;
- case HLSL_TYPE_SAMPLER: case HLSL_TYPE_PIXELSHADER: case HLSL_TYPE_VERTEXSHADER: hlsl_fixme(ctx, loc, "Write fx 2.0 parameter object type %#x.", type->base_type); @@ -820,6 +820,7 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type return false; }
+ case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: hlsl_fixme(ctx, loc, "Write fx 2.0 parameter class %#x.", type->class); return false; @@ -1097,18 +1098,24 @@ static bool is_object_variable(const struct hlsl_ir_var *var) { const struct hlsl_type *type = hlsl_get_multiarray_element_type(var->data_type);
- if (type->class != HLSL_CLASS_OBJECT) - return false; - - switch (type->base_type) + switch (type->class) { - case HLSL_TYPE_SAMPLER: - case HLSL_TYPE_TEXTURE: - case HLSL_TYPE_UAV: - case HLSL_TYPE_PIXELSHADER: - case HLSL_TYPE_VERTEXSHADER: - case HLSL_TYPE_RENDERTARGETVIEW: + case HLSL_CLASS_SAMPLER: return true; + + case HLSL_CLASS_OBJECT: + switch (type->base_type) + { + case HLSL_TYPE_TEXTURE: + case HLSL_TYPE_UAV: + case HLSL_TYPE_PIXELSHADER: + case HLSL_TYPE_VERTEXSHADER: + case HLSL_TYPE_RENDERTARGETVIEW: + return true; + default: + return false; + } + default: return false; } diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index c3170ff7b..d1353ead6 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -226,50 +226,61 @@ unsigned int hlsl_get_multiarray_size(const struct hlsl_type *type)
bool hlsl_type_is_resource(const struct hlsl_type *type) { - if (type->class == HLSL_CLASS_ARRAY) - return hlsl_type_is_resource(type->e.array.type); - - if (type->class == HLSL_CLASS_OBJECT) + switch (type->class) { - switch (type->base_type) - { - case HLSL_TYPE_TEXTURE: - case HLSL_TYPE_SAMPLER: - case HLSL_TYPE_UAV: - return true; - default: - return false; - } + case HLSL_CLASS_ARRAY: + return hlsl_type_is_resource(type->e.array.type); + + case HLSL_CLASS_SAMPLER: + return true; + + case HLSL_CLASS_OBJECT: + switch (type->base_type) + { + case HLSL_TYPE_TEXTURE: + case HLSL_TYPE_UAV: + return true; + default: + return false; + } + + default: + return false; } - return false; }
/* Only intended to be used for derefs (after copies have been lowered to components or vectors) or * resources, since for both their data types span across a single regset. */ static enum hlsl_regset type_get_regset(const struct hlsl_type *type) { - if (hlsl_is_numeric_type(type)) - return HLSL_REGSET_NUMERIC; + switch (type->class) + { + case HLSL_CLASS_SCALAR: + case HLSL_CLASS_VECTOR: + case HLSL_CLASS_MATRIX: + return HLSL_REGSET_NUMERIC;
- if (type->class == HLSL_CLASS_ARRAY) - return type_get_regset(type->e.array.type); + case HLSL_CLASS_ARRAY: + return type_get_regset(type->e.array.type);
- if (type->class == HLSL_CLASS_OBJECT) - { - switch (type->base_type) - { - case HLSL_TYPE_TEXTURE: - return HLSL_REGSET_TEXTURES; + case HLSL_CLASS_SAMPLER: + return HLSL_REGSET_SAMPLERS;
- case HLSL_TYPE_SAMPLER: - return HLSL_REGSET_SAMPLERS; + case HLSL_CLASS_OBJECT: + switch (type->base_type) + { + case HLSL_TYPE_TEXTURE: + return HLSL_REGSET_TEXTURES;
- case HLSL_TYPE_UAV: - return HLSL_REGSET_UAVS; + case HLSL_TYPE_UAV: + return HLSL_REGSET_UAVS;
- default: - vkd3d_unreachable(); - } + default: + vkd3d_unreachable(); + } + + default: + break; }
vkd3d_unreachable(); @@ -366,6 +377,10 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type break; }
+ case HLSL_CLASS_SAMPLER: + type->reg_size[HLSL_REGSET_SAMPLERS] = 1; + break; + case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; @@ -429,6 +444,7 @@ static bool type_is_single_component(const struct hlsl_type *type) { case HLSL_CLASS_SCALAR: case HLSL_CLASS_OBJECT: + case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: return true;
@@ -561,6 +577,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty break;
case HLSL_CLASS_OBJECT: + case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: assert(idx == 0); break; @@ -933,6 +950,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type) return hlsl_type_component_count(type->e.array.type) * type->e.array.elements_count;
case HLSL_CLASS_OBJECT: + case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: return 1;
@@ -952,7 +970,7 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 return false; if (t1->base_type != t2->base_type) return false; - if (t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE + if (t1->class == HLSL_CLASS_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE || t1->base_type == HLSL_TYPE_UAV) { if (t1->sampler_dim != t2->sampler_dim) @@ -2359,6 +2377,7 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru } }
+ case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; @@ -3647,7 +3666,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
for (bt = 0; bt <= HLSL_SAMPLER_DIM_LAST_SAMPLER; ++bt) { - type = hlsl_new_type(ctx, sampler_names[bt], HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + type = hlsl_new_simple_type(ctx, sampler_names[bt], HLSL_CLASS_SAMPLER); type->sampler_dim = bt; ctx->builtin_types.sampler[bt] = type; } diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 2b5eb043e..49e51f2e4 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -79,6 +79,7 @@ enum hlsl_type_class HLSL_CLASS_STRUCT, HLSL_CLASS_ARRAY, HLSL_CLASS_OBJECT, + HLSL_CLASS_SAMPLER, HLSL_CLASS_STRING, HLSL_CLASS_VOID, }; @@ -92,7 +93,6 @@ enum hlsl_base_type HLSL_TYPE_UINT, HLSL_TYPE_BOOL, HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL, - HLSL_TYPE_SAMPLER, HLSL_TYPE_TEXTURE, HLSL_TYPE_UAV, HLSL_TYPE_PIXELSHADER, @@ -150,7 +150,7 @@ struct hlsl_type * Otherwise, base_type is not used. */ enum hlsl_base_type base_type;
- /* If base_type is HLSL_TYPE_SAMPLER, then sampler_dim is <= HLSL_SAMPLER_DIM_LAST_SAMPLER. + /* If class is HLSL_CLASS_SAMPLER, then sampler_dim is <= HLSL_SAMPLER_DIM_LAST_SAMPLER. * If base_type is HLSL_TYPE_TEXTURE, then sampler_dim can be any value of the enum except * HLSL_SAMPLER_DIM_GENERIC and HLSL_SAMPLER_DIM_COMPARISON. * If base_type is HLSL_TYPE_UAV, then sampler_dim must be one of HLSL_SAMPLER_DIM_1D, @@ -172,7 +172,6 @@ struct hlsl_type * If type is HLSL_CLASS_ARRAY, then dimx and dimy have the same value as in the type of the array elements. * If type is HLSL_CLASS_STRUCT, then dimx is the sum of (dimx * dimy) of every component, and dimy = 1. * If type is HLSL_CLASS_OBJECT, dimx and dimy depend on the base_type: - * If base_type is HLSL_TYPE_SAMPLER, then both dimx = 1 and dimy = 1. * If base_type is HLSL_TYPE_TEXTURE, then dimx = 4 and dimy = 1. * If base_type is HLSL_TYPE_UAV, then dimx is the dimx of e.resource_format, and dimy = 1. * Otherwise both dimx = 1 and dimy = 1. */ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 7fc35d4e1..02d88d10c 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3965,7 +3965,7 @@ static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer * }
sampler_type = params->args[0]->data_type; - if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER + if (sampler_type->class != HLSL_CLASS_SAMPLER || (sampler_type->sampler_dim != dim && sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC)) { struct vkd3d_string_buffer *string; @@ -4639,8 +4639,7 @@ static bool add_sample_method_call(struct hlsl_ctx *ctx, struct hlsl_block *bloc }
sampler_type = params->args[0]->data_type; - if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER - || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) + if (sampler_type->class != HLSL_CLASS_SAMPLER || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) { struct vkd3d_string_buffer *string;
@@ -4704,8 +4703,7 @@ static bool add_sample_cmp_method_call(struct hlsl_ctx *ctx, struct hlsl_block * }
sampler_type = params->args[0]->data_type; - if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER - || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_COMPARISON) + if (sampler_type->class != HLSL_CLASS_SAMPLER || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_COMPARISON) { struct vkd3d_string_buffer *string;
@@ -4815,8 +4813,7 @@ static bool add_gather_method_call(struct hlsl_ctx *ctx, struct hlsl_block *bloc }
sampler_type = params->args[0]->data_type; - if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER - || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) + if (sampler_type->class != HLSL_CLASS_SAMPLER || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) { struct vkd3d_string_buffer *string;
@@ -5052,8 +5049,7 @@ static bool add_sample_lod_method_call(struct hlsl_ctx *ctx, struct hlsl_block * }
sampler_type = params->args[0]->data_type; - if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER - || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) + if (sampler_type->class != HLSL_CLASS_SAMPLER || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) { struct vkd3d_string_buffer *string;
@@ -5115,8 +5111,7 @@ static bool add_sample_grad_method_call(struct hlsl_ctx *ctx, struct hlsl_block }
sampler_type = params->args[0]->data_type; - if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER - || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) + if (sampler_type->class != HLSL_CLASS_SAMPLER || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) { struct vkd3d_string_buffer *string;
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index e1064b998..092eb7f75 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1625,6 +1625,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, { case HLSL_CLASS_SCALAR: case HLSL_CLASS_VECTOR: + case HLSL_CLASS_SAMPLER: case HLSL_CLASS_OBJECT: break;
@@ -2611,7 +2612,7 @@ static bool lower_combined_samples(struct hlsl_ctx *ctx, struct hlsl_ir_node *in hlsl_copy_deref(ctx, &load->sampler, &load->resource); load->resource.var = var; assert(hlsl_deref_get_type(ctx, &load->resource)->base_type == HLSL_TYPE_TEXTURE); - assert(hlsl_deref_get_type(ctx, &load->sampler)->base_type == HLSL_TYPE_SAMPLER); + assert(hlsl_deref_get_type(ctx, &load->sampler)->class == HLSL_CLASS_SAMPLER);
return true; } diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 4bacbefd3..e9f9ba409 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3008,6 +3008,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type) case HLSL_CLASS_ARRAY: case HLSL_CLASS_STRUCT: case HLSL_CLASS_OBJECT: + case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; @@ -3109,20 +3110,28 @@ static void write_sm4_type(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b
static D3D_SHADER_INPUT_TYPE sm4_resource_type(const struct hlsl_type *type) { - if (type->class == HLSL_CLASS_ARRAY) - return sm4_resource_type(type->e.array.type); - - switch (type->base_type) + switch (type->class) { - case HLSL_TYPE_SAMPLER: + case HLSL_CLASS_ARRAY: + return sm4_resource_type(type->e.array.type); + case HLSL_CLASS_SAMPLER: return D3D_SIT_SAMPLER; - case HLSL_TYPE_TEXTURE: - return D3D_SIT_TEXTURE; - case HLSL_TYPE_UAV: - return D3D_SIT_UAV_RWTYPED; + case HLSL_CLASS_OBJECT: + switch (type->base_type) + { + case HLSL_TYPE_TEXTURE: + return D3D_SIT_TEXTURE; + case HLSL_TYPE_UAV: + return D3D_SIT_UAV_RWTYPED; + default: + break; + } + default: - vkd3d_unreachable(); + break; } + + vkd3d_unreachable(); }
static D3D_RESOURCE_RETURN_TYPE sm4_resource_format(const struct hlsl_type *type)
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/d3dbc.c | 38 ++++++----- libs/vkd3d-shader/fx.c | 88 ++++++++++++++----------- libs/vkd3d-shader/hlsl.c | 109 +++++++++++++++++-------------- libs/vkd3d-shader/hlsl.h | 5 +- libs/vkd3d-shader/hlsl.y | 9 ++- libs/vkd3d-shader/hlsl_codegen.c | 3 +- libs/vkd3d-shader/tpf.c | 7 +- 7 files changed, 142 insertions(+), 117 deletions(-)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 5cee482d5..08c19efb8 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1515,6 +1515,7 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type) case HLSL_CLASS_OBJECT: case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: + case HLSL_CLASS_TEXTURE: return D3DXPC_OBJECT; case HLSL_CLASS_VOID: /* This shouldn't happen. */ @@ -1572,29 +1573,30 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) } break;
+ case HLSL_CLASS_TEXTURE: + switch (type->sampler_dim) + { + case HLSL_SAMPLER_DIM_1D: + return D3DXPT_TEXTURE1D; + case HLSL_SAMPLER_DIM_2D: + return D3DXPT_TEXTURE2D; + case HLSL_SAMPLER_DIM_3D: + return D3DXPT_TEXTURE3D; + case HLSL_SAMPLER_DIM_CUBE: + return D3DXPT_TEXTURECUBE; + case HLSL_SAMPLER_DIM_GENERIC: + return D3DXPT_TEXTURE; + default: + ERR("Invalid dimension %#x.\n", type->sampler_dim); + vkd3d_unreachable(); + } + break; + case HLSL_CLASS_OBJECT: switch (type->base_type) { case HLSL_TYPE_PIXELSHADER: return D3DXPT_PIXELSHADER; - case HLSL_TYPE_TEXTURE: - switch (type->sampler_dim) - { - case HLSL_SAMPLER_DIM_1D: - return D3DXPT_TEXTURE1D; - case HLSL_SAMPLER_DIM_2D: - return D3DXPT_TEXTURE2D; - case HLSL_SAMPLER_DIM_3D: - return D3DXPT_TEXTURE3D; - case HLSL_SAMPLER_DIM_CUBE: - return D3DXPT_TEXTURECUBE; - case HLSL_SAMPLER_DIM_GENERIC: - return D3DXPT_TEXTURE; - default: - ERR("Invalid dimension %#x.\n", type->sampler_dim); - vkd3d_unreachable(); - } - break; case HLSL_TYPE_VERTEXSHADER: return D3DXPT_VERTEXSHADER; default: diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index c5caeadf8..0b32f4abb 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -380,7 +380,7 @@ static const char * get_fx_4_type_name(const struct hlsl_type *type) [HLSL_SAMPLER_DIM_STRUCTURED_BUFFER] = "RWStructuredBuffer", };
- if (type->base_type == HLSL_TYPE_TEXTURE) + if (type->class == HLSL_CLASS_TEXTURE) return texture_type_names[type->sampler_dim];
if (type->base_type == HLSL_TYPE_UAV) @@ -427,6 +427,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co break;
case HLSL_CLASS_OBJECT: + case HLSL_CLASS_TEXTURE: put_u32_unaligned(buffer, 2); break;
@@ -475,15 +476,8 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co put_u32_unaligned(buffer, field_type_offset); } } - else if (type->class == HLSL_CLASS_OBJECT) + else if (type->class == HLSL_CLASS_TEXTURE) { - static const uint32_t object_type[] = - { - [HLSL_TYPE_PIXELSHADER] = 5, - [HLSL_TYPE_VERTEXSHADER] = 6, - [HLSL_TYPE_RENDERTARGETVIEW] = 19, - [HLSL_TYPE_DEPTHSTENCILVIEW] = 20, - }; static const uint32_t texture_type[] = { [HLSL_SAMPLER_DIM_GENERIC] = 9, @@ -497,6 +491,18 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co [HLSL_SAMPLER_DIM_CUBE] = 17, [HLSL_SAMPLER_DIM_CUBEARRAY] = 23, }; + + put_u32_unaligned(buffer, texture_type[type->sampler_dim]); + } + else if (type->class == HLSL_CLASS_OBJECT) + { + static const uint32_t object_type[] = + { + [HLSL_TYPE_PIXELSHADER] = 5, + [HLSL_TYPE_VERTEXSHADER] = 6, + [HLSL_TYPE_RENDERTARGETVIEW] = 19, + [HLSL_TYPE_DEPTHSTENCILVIEW] = 20, + }; static const uint32_t uav_type[] = { [HLSL_SAMPLER_DIM_1D] = 31, @@ -516,9 +522,6 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co case HLSL_TYPE_VERTEXSHADER: put_u32_unaligned(buffer, object_type[type->base_type]); break; - case HLSL_TYPE_TEXTURE: - put_u32_unaligned(buffer, texture_type[type->sampler_dim]); - break; case HLSL_TYPE_UAV: put_u32_unaligned(buffer, uav_type[type->sampler_dim]); break; @@ -794,23 +797,23 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type case HLSL_CLASS_ARRAY: return is_type_supported_fx_2(ctx, type->e.array.type, loc);
+ case HLSL_CLASS_TEXTURE: + switch (type->sampler_dim) + { + case HLSL_SAMPLER_DIM_1D: + case HLSL_SAMPLER_DIM_2D: + case HLSL_SAMPLER_DIM_3D: + case HLSL_SAMPLER_DIM_CUBE: + case HLSL_SAMPLER_DIM_GENERIC: + return true; + default: + return false; + } + break; + case HLSL_CLASS_OBJECT: switch (type->base_type) { - case HLSL_TYPE_TEXTURE: - switch (type->sampler_dim) - { - case HLSL_SAMPLER_DIM_1D: - case HLSL_SAMPLER_DIM_2D: - case HLSL_SAMPLER_DIM_3D: - case HLSL_SAMPLER_DIM_CUBE: - case HLSL_SAMPLER_DIM_GENERIC: - return true; - default: - return false; - } - break; - case HLSL_TYPE_PIXELSHADER: case HLSL_TYPE_VERTEXSHADER: hlsl_fixme(ctx, loc, "Write fx 2.0 parameter object type %#x.", type->base_type); @@ -1002,19 +1005,30 @@ static void write_fx_4_object_variable(struct hlsl_ir_var *var, struct fx_write_ }
/* Initializer */ - switch (type->base_type) + switch (type->class) { - case HLSL_TYPE_TEXTURE: - case HLSL_TYPE_UAV: - case HLSL_TYPE_RENDERTARGETVIEW: + case HLSL_CLASS_TEXTURE: break; - case HLSL_TYPE_PIXELSHADER: - case HLSL_TYPE_VERTEXSHADER: - /* FIXME: write shader blobs, once parser support works. */ - for (i = 0; i < elements_count; ++i) - put_u32(buffer, 0); - ++fx->shader_variable_count; + + case HLSL_CLASS_OBJECT: + switch (type->base_type) + { + case HLSL_TYPE_UAV: + case HLSL_TYPE_RENDERTARGETVIEW: + break; + case HLSL_TYPE_PIXELSHADER: + case HLSL_TYPE_VERTEXSHADER: + /* FIXME: write shader blobs, once parser support works. */ + for (i = 0; i < elements_count; ++i) + put_u32(buffer, 0); + ++fx->shader_variable_count; + break; + default: + hlsl_fixme(ctx, &ctx->location, "Writing initializer for object type %u is not implemented.", + type->base_type); + } break; + default: hlsl_fixme(ctx, &ctx->location, "Writing initializer for object type %u is not implemented.", type->base_type); @@ -1101,12 +1115,12 @@ static bool is_object_variable(const struct hlsl_ir_var *var) switch (type->class) { case HLSL_CLASS_SAMPLER: + case HLSL_CLASS_TEXTURE: return true;
case HLSL_CLASS_OBJECT: switch (type->base_type) { - case HLSL_TYPE_TEXTURE: case HLSL_TYPE_UAV: case HLSL_TYPE_PIXELSHADER: case HLSL_TYPE_VERTEXSHADER: diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index d1353ead6..55135254f 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -232,12 +232,12 @@ bool hlsl_type_is_resource(const struct hlsl_type *type) return hlsl_type_is_resource(type->e.array.type);
case HLSL_CLASS_SAMPLER: + case HLSL_CLASS_TEXTURE: return true;
case HLSL_CLASS_OBJECT: switch (type->base_type) { - case HLSL_TYPE_TEXTURE: case HLSL_TYPE_UAV: return true; default: @@ -266,12 +266,12 @@ static enum hlsl_regset type_get_regset(const struct hlsl_type *type) case HLSL_CLASS_SAMPLER: return HLSL_REGSET_SAMPLERS;
+ case HLSL_CLASS_TEXTURE: + return HLSL_REGSET_TEXTURES; + case HLSL_CLASS_OBJECT: switch (type->base_type) { - case HLSL_TYPE_TEXTURE: - return HLSL_REGSET_TEXTURES; - case HLSL_TYPE_UAV: return HLSL_REGSET_UAVS;
@@ -381,6 +381,10 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type type->reg_size[HLSL_REGSET_SAMPLERS] = 1; break;
+ case HLSL_CLASS_TEXTURE: + type->reg_size[HLSL_REGSET_TEXTURES] = 1; + break; + case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; @@ -446,6 +450,7 @@ static bool type_is_single_component(const struct hlsl_type *type) case HLSL_CLASS_OBJECT: case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: + case HLSL_CLASS_TEXTURE: return true;
case HLSL_CLASS_VECTOR: @@ -579,6 +584,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty case HLSL_CLASS_OBJECT: case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: + case HLSL_CLASS_TEXTURE: assert(idx == 0); break;
@@ -827,8 +833,7 @@ struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_
if (!(type = hlsl_alloc(ctx, sizeof(*type)))) return NULL; - type->class = HLSL_CLASS_OBJECT; - type->base_type = HLSL_TYPE_TEXTURE; + type->class = HLSL_CLASS_TEXTURE; type->dimx = 4; type->dimy = 1; type->sampler_dim = dim; @@ -952,6 +957,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type) case HLSL_CLASS_OBJECT: case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: + case HLSL_CLASS_TEXTURE: return 1;
case HLSL_CLASS_VOID: @@ -970,12 +976,12 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 return false; if (t1->base_type != t2->base_type) return false; - if (t1->class == HLSL_CLASS_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE + if (t1->class == HLSL_CLASS_SAMPLER || t1->class == HLSL_CLASS_TEXTURE || t1->base_type == HLSL_TYPE_UAV) { if (t1->sampler_dim != t2->sampler_dim) return false; - if ((t1->base_type == HLSL_TYPE_TEXTURE || t1->base_type == HLSL_TYPE_UAV) + if ((t1->class == HLSL_CLASS_TEXTURE || t1->base_type == HLSL_TYPE_UAV) && t1->sampler_dim != HLSL_SAMPLER_DIM_GENERIC && !hlsl_types_are_equal(t1->e.resource.format, t2->e.resource.format)) return false; @@ -1096,10 +1102,14 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, break; }
+ case HLSL_CLASS_TEXTURE: + type->e.resource.format = old->e.resource.format; + break; + case HLSL_CLASS_OBJECT: if (type->base_type == HLSL_TYPE_TECHNIQUE) type->e.version = old->e.version; - if (old->base_type == HLSL_TYPE_TEXTURE || old->base_type == HLSL_TYPE_UAV) + if (old->base_type == HLSL_TYPE_UAV) { type->e.resource.format = old->e.resource.format; type->e.resource.rasteriser_ordered = old->e.resource.rasteriser_ordered; @@ -1678,8 +1688,7 @@ bool hlsl_index_is_resource_access(struct hlsl_ir_index *index) { 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); + return type->class == HLSL_CLASS_TEXTURE || (type->class == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_UAV); }
bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index) @@ -1700,7 +1709,7 @@ struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *v if (!(index = hlsl_alloc(ctx, sizeof(*index)))) return NULL;
- if (type->class == HLSL_CLASS_OBJECT) + if (type->class == HLSL_CLASS_TEXTURE || type->class == HLSL_CLASS_OBJECT) type = type->e.resource.format; else if (type->class == HLSL_CLASS_MATRIX) type = hlsl_get_vector_type(ctx, type->base_type, type->dimx); @@ -2264,6 +2273,19 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru [HLSL_TYPE_BOOL] = "bool", };
+ static const char *const dimensions[] = + { + [HLSL_SAMPLER_DIM_1D] = "1D", + [HLSL_SAMPLER_DIM_2D] = "2D", + [HLSL_SAMPLER_DIM_3D] = "3D", + [HLSL_SAMPLER_DIM_CUBE] = "Cube", + [HLSL_SAMPLER_DIM_1DARRAY] = "1DArray", + [HLSL_SAMPLER_DIM_2DARRAY] = "2DArray", + [HLSL_SAMPLER_DIM_2DMS] = "2DMS", + [HLSL_SAMPLER_DIM_2DMSARRAY] = "2DMSArray", + [HLSL_SAMPLER_DIM_CUBEARRAY] = "CubeArray", + }; + if (!(string = hlsl_get_string_buffer(ctx))) return NULL;
@@ -2317,47 +2339,34 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru vkd3d_string_buffer_printf(string, "<anonymous struct>"); return string;
- case HLSL_CLASS_OBJECT: - { - static const char *const dimensions[] = + case HLSL_CLASS_TEXTURE: + if (type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC) { - [HLSL_SAMPLER_DIM_1D] = "1D", - [HLSL_SAMPLER_DIM_2D] = "2D", - [HLSL_SAMPLER_DIM_3D] = "3D", - [HLSL_SAMPLER_DIM_CUBE] = "Cube", - [HLSL_SAMPLER_DIM_1DARRAY] = "1DArray", - [HLSL_SAMPLER_DIM_2DARRAY] = "2DArray", - [HLSL_SAMPLER_DIM_2DMS] = "2DMS", - [HLSL_SAMPLER_DIM_2DMSARRAY] = "2DMSArray", - [HLSL_SAMPLER_DIM_CUBEARRAY] = "CubeArray", - }; + vkd3d_string_buffer_printf(string, "Texture"); + return string; + }
- switch (type->base_type) + assert(type->e.resource.format->base_type < ARRAY_SIZE(base_types)); + if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER) { - case HLSL_TYPE_TEXTURE: - if (type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC) - { - vkd3d_string_buffer_printf(string, "Texture"); - return string; - } - - assert(type->e.resource.format->base_type < ARRAY_SIZE(base_types)); - if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER) - { - vkd3d_string_buffer_printf(string, "Buffer"); - } - else - { - assert(type->sampler_dim < ARRAY_SIZE(dimensions)); - vkd3d_string_buffer_printf(string, "Texture%s", dimensions[type->sampler_dim]); - } - if ((inner_string = hlsl_type_to_string(ctx, type->e.resource.format))) - { - vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer); - hlsl_release_string_buffer(ctx, inner_string); - } - return string; + vkd3d_string_buffer_printf(string, "Buffer"); + } + else + { + assert(type->sampler_dim < ARRAY_SIZE(dimensions)); + vkd3d_string_buffer_printf(string, "Texture%s", dimensions[type->sampler_dim]); + } + if ((inner_string = hlsl_type_to_string(ctx, type->e.resource.format))) + { + vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer); + hlsl_release_string_buffer(ctx, inner_string); + } + return string;
+ case HLSL_CLASS_OBJECT: + { + switch (type->base_type) + { case HLSL_TYPE_UAV: if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER) vkd3d_string_buffer_printf(string, "RWBuffer"); @@ -3556,7 +3565,6 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) {"matrix", HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4}, {"fxgroup", HLSL_CLASS_OBJECT, HLSL_TYPE_EFFECT_GROUP, 1, 1}, {"pass", HLSL_CLASS_OBJECT, HLSL_TYPE_PASS, 1, 1}, - {"texture", HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1}, {"pixelshader", HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1}, {"vertexshader", HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1}, {"RenderTargetView",HLSL_CLASS_OBJECT, HLSL_TYPE_RENDERTARGETVIEW, 1, 1}, @@ -3673,6 +3681,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
ctx->builtin_types.Void = hlsl_new_simple_type(ctx, "void", HLSL_CLASS_VOID); hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "STRING", HLSL_CLASS_STRING)); + hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "texture", HLSL_CLASS_TEXTURE));
for (i = 0; i < ARRAY_SIZE(effect_types); ++i) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 49e51f2e4..9f333fd33 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -81,6 +81,7 @@ enum hlsl_type_class HLSL_CLASS_OBJECT, HLSL_CLASS_SAMPLER, HLSL_CLASS_STRING, + HLSL_CLASS_TEXTURE, HLSL_CLASS_VOID, };
@@ -93,7 +94,6 @@ enum hlsl_base_type HLSL_TYPE_UINT, HLSL_TYPE_BOOL, HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL, - HLSL_TYPE_TEXTURE, HLSL_TYPE_UAV, HLSL_TYPE_PIXELSHADER, HLSL_TYPE_VERTEXSHADER, @@ -151,7 +151,7 @@ struct hlsl_type enum hlsl_base_type base_type;
/* If class is HLSL_CLASS_SAMPLER, then sampler_dim is <= HLSL_SAMPLER_DIM_LAST_SAMPLER. - * If base_type is HLSL_TYPE_TEXTURE, then sampler_dim can be any value of the enum except + * If class is HLSL_CLASS_TEXTURE, then sampler_dim can be any value of the enum except * HLSL_SAMPLER_DIM_GENERIC and HLSL_SAMPLER_DIM_COMPARISON. * If base_type is HLSL_TYPE_UAV, then sampler_dim must be one of HLSL_SAMPLER_DIM_1D, * HLSL_SAMPLER_DIM_2D, HLSL_SAMPLER_DIM_3D, HLSL_SAMPLER_DIM_1DARRAY, HLSL_SAMPLER_DIM_2DARRAY, @@ -172,7 +172,6 @@ struct hlsl_type * If type is HLSL_CLASS_ARRAY, then dimx and dimy have the same value as in the type of the array elements. * If type is HLSL_CLASS_STRUCT, then dimx is the sum of (dimx * dimy) of every component, and dimy = 1. * If type is HLSL_CLASS_OBJECT, dimx and dimy depend on the base_type: - * If base_type is HLSL_TYPE_TEXTURE, then dimx = 4 and dimy = 1. * If base_type is HLSL_TYPE_UAV, then dimx is the dimx of e.resource_format, and dimy = 1. * Otherwise both dimx = 1 and dimy = 1. */ unsigned int dimx; diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 02d88d10c..1832aa8b8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -833,8 +833,8 @@ static bool add_array_access(struct hlsl_ctx *ctx, struct hlsl_block *block, str const struct hlsl_type *expr_type = array->data_type, *index_type = index->data_type; struct hlsl_ir_node *return_index, *cast;
- if (expr_type->class == HLSL_CLASS_OBJECT - && (expr_type->base_type == HLSL_TYPE_TEXTURE || expr_type->base_type == HLSL_TYPE_UAV) + if ((expr_type->class == HLSL_CLASS_TEXTURE + || (expr_type->class == HLSL_CLASS_OBJECT && expr_type->base_type == HLSL_TYPE_UAV)) && expr_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) { unsigned int dim_count = hlsl_sampler_dim_count(expr_type->sampler_dim); @@ -1942,7 +1942,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct hlsl_blo
resource_type = hlsl_deref_get_type(ctx, &resource_deref); assert(resource_type->class == HLSL_CLASS_OBJECT); - assert(resource_type->base_type == HLSL_TYPE_TEXTURE || resource_type->base_type == HLSL_TYPE_UAV); + assert(resource_type->class == HLSL_CLASS_TEXTURE || resource_type->base_type == HLSL_TYPE_UAV);
if (resource_type->base_type != HLSL_TYPE_UAV) hlsl_error(ctx, &lhs->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, @@ -5195,8 +5195,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct hlsl_block *block, stru const struct hlsl_type *object_type = object->data_type; const struct method_function *method;
- if (object_type->class != HLSL_CLASS_OBJECT || object_type->base_type != HLSL_TYPE_TEXTURE - || object_type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC) + if (object_type->class != HLSL_CLASS_TEXTURE || object_type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC) { struct vkd3d_string_buffer *string;
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 092eb7f75..e6c8dab9c 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1626,6 +1626,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, case HLSL_CLASS_SCALAR: case HLSL_CLASS_VECTOR: case HLSL_CLASS_SAMPLER: + case HLSL_CLASS_TEXTURE: case HLSL_CLASS_OBJECT: break;
@@ -2611,7 +2612,7 @@ static bool lower_combined_samples(struct hlsl_ctx *ctx, struct hlsl_ir_node *in
hlsl_copy_deref(ctx, &load->sampler, &load->resource); load->resource.var = var; - assert(hlsl_deref_get_type(ctx, &load->resource)->base_type == HLSL_TYPE_TEXTURE); + assert(hlsl_deref_get_type(ctx, &load->resource)->class == HLSL_CLASS_TEXTURE); assert(hlsl_deref_get_type(ctx, &load->sampler)->class == HLSL_CLASS_SAMPLER);
return true; diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index e9f9ba409..db4e5e2fb 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3010,6 +3010,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type) case HLSL_CLASS_OBJECT: case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: + case HLSL_CLASS_TEXTURE: case HLSL_CLASS_VOID: break; } @@ -3116,11 +3117,11 @@ static D3D_SHADER_INPUT_TYPE sm4_resource_type(const struct hlsl_type *type) return sm4_resource_type(type->e.array.type); case HLSL_CLASS_SAMPLER: return D3D_SIT_SAMPLER; + case HLSL_CLASS_TEXTURE: + return D3D_SIT_TEXTURE; case HLSL_CLASS_OBJECT: switch (type->base_type) { - case HLSL_TYPE_TEXTURE: - return D3D_SIT_TEXTURE; case HLSL_TYPE_UAV: return D3D_SIT_UAV_RWTYPED; default: @@ -4569,7 +4570,7 @@ static void write_sm4_ld(const struct tpf_writer *tpf, const struct hlsl_ir_node enum hlsl_sampler_dim dim) { const struct hlsl_type *resource_type = hlsl_deref_get_type(tpf->ctx, resource); - bool multisampled = resource_type->base_type == HLSL_TYPE_TEXTURE + bool multisampled = resource_type->class == HLSL_CLASS_TEXTURE && (resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS || resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY); bool uav = (hlsl_deref_get_regset(tpf->ctx, resource) == HLSL_REGSET_UAVS); unsigned int coords_writemask = VKD3DSP_WRITEMASK_ALL;
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/d3dbc.c | 2 + libs/vkd3d-shader/fx.c | 32 ++++++----- libs/vkd3d-shader/hlsl.c | 94 +++++++++++--------------------- libs/vkd3d-shader/hlsl.h | 10 ++-- libs/vkd3d-shader/hlsl.y | 8 +-- libs/vkd3d-shader/hlsl_codegen.c | 1 + libs/vkd3d-shader/tpf.c | 12 +--- 7 files changed, 63 insertions(+), 96 deletions(-)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 08c19efb8..542fc71f7 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1517,6 +1517,7 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type) case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: return D3DXPC_OBJECT; + case HLSL_CLASS_UAV: case HLSL_CLASS_VOID: /* This shouldn't happen. */ } @@ -1613,6 +1614,7 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) case HLSL_CLASS_STRING: return D3DXPT_STRING;
+ case HLSL_CLASS_UAV: case HLSL_CLASS_VOID: /* This shouldn't happen. */ break; diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index 0b32f4abb..984437975 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -383,7 +383,7 @@ static const char * get_fx_4_type_name(const struct hlsl_type *type) if (type->class == HLSL_CLASS_TEXTURE) return texture_type_names[type->sampler_dim];
- if (type->base_type == HLSL_TYPE_UAV) + if (type->class == HLSL_CLASS_UAV) return uav_type_names[type->sampler_dim];
switch (type->base_type) @@ -428,6 +428,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
case HLSL_CLASS_OBJECT: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: put_u32_unaligned(buffer, 2); break;
@@ -494,15 +495,8 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
put_u32_unaligned(buffer, texture_type[type->sampler_dim]); } - else if (type->class == HLSL_CLASS_OBJECT) + else if (type->class == HLSL_CLASS_UAV) { - static const uint32_t object_type[] = - { - [HLSL_TYPE_PIXELSHADER] = 5, - [HLSL_TYPE_VERTEXSHADER] = 6, - [HLSL_TYPE_RENDERTARGETVIEW] = 19, - [HLSL_TYPE_DEPTHSTENCILVIEW] = 20, - }; static const uint32_t uav_type[] = { [HLSL_SAMPLER_DIM_1D] = 31, @@ -514,6 +508,18 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co [HLSL_SAMPLER_DIM_STRUCTURED_BUFFER] = 40, };
+ put_u32_unaligned(buffer, uav_type[type->sampler_dim]); + } + else if (type->class == HLSL_CLASS_OBJECT) + { + static const uint32_t object_type[] = + { + [HLSL_TYPE_PIXELSHADER] = 5, + [HLSL_TYPE_VERTEXSHADER] = 6, + [HLSL_TYPE_RENDERTARGETVIEW] = 19, + [HLSL_TYPE_DEPTHSTENCILVIEW] = 20, + }; + switch (type->base_type) { case HLSL_TYPE_DEPTHSTENCILVIEW: @@ -522,9 +528,6 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co case HLSL_TYPE_VERTEXSHADER: put_u32_unaligned(buffer, object_type[type->base_type]); break; - case HLSL_TYPE_UAV: - put_u32_unaligned(buffer, uav_type[type->sampler_dim]); - break; default: hlsl_fixme(ctx, &ctx->location, "Object type %u is not supported.", type->base_type); return 0; @@ -828,6 +831,7 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type hlsl_fixme(ctx, loc, "Write fx 2.0 parameter class %#x.", type->class); return false;
+ case HLSL_CLASS_UAV: case HLSL_CLASS_VOID: return false; } @@ -1008,12 +1012,12 @@ static void write_fx_4_object_variable(struct hlsl_ir_var *var, struct fx_write_ switch (type->class) { case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: break;
case HLSL_CLASS_OBJECT: switch (type->base_type) { - case HLSL_TYPE_UAV: case HLSL_TYPE_RENDERTARGETVIEW: break; case HLSL_TYPE_PIXELSHADER: @@ -1116,12 +1120,12 @@ static bool is_object_variable(const struct hlsl_ir_var *var) { case HLSL_CLASS_SAMPLER: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: return true;
case HLSL_CLASS_OBJECT: switch (type->base_type) { - case HLSL_TYPE_UAV: case HLSL_TYPE_PIXELSHADER: case HLSL_TYPE_VERTEXSHADER: case HLSL_TYPE_RENDERTARGETVIEW: diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 55135254f..ad6a443bc 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -233,17 +233,9 @@ bool hlsl_type_is_resource(const struct hlsl_type *type)
case HLSL_CLASS_SAMPLER: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: return true;
- case HLSL_CLASS_OBJECT: - switch (type->base_type) - { - case HLSL_TYPE_UAV: - return true; - default: - return false; - } - default: return false; } @@ -269,15 +261,8 @@ static enum hlsl_regset type_get_regset(const struct hlsl_type *type) case HLSL_CLASS_TEXTURE: return HLSL_REGSET_TEXTURES;
- case HLSL_CLASS_OBJECT: - switch (type->base_type) - { - case HLSL_TYPE_UAV: - return HLSL_REGSET_UAVS; - - default: - vkd3d_unreachable(); - } + case HLSL_CLASS_UAV: + return HLSL_REGSET_UAVS;
default: break; @@ -366,17 +351,6 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type break; }
- case HLSL_CLASS_OBJECT: - { - if (hlsl_type_is_resource(type)) - { - enum hlsl_regset regset = type_get_regset(type); - - type->reg_size[regset] = 1; - } - break; - } - case HLSL_CLASS_SAMPLER: type->reg_size[HLSL_REGSET_SAMPLERS] = 1; break; @@ -385,6 +359,11 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type type->reg_size[HLSL_REGSET_TEXTURES] = 1; break;
+ case HLSL_CLASS_UAV: + type->reg_size[HLSL_REGSET_UAVS] = 1; + break; + + case HLSL_CLASS_OBJECT: case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: break; @@ -451,6 +430,7 @@ static bool type_is_single_component(const struct hlsl_type *type) case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: return true;
case HLSL_CLASS_VECTOR: @@ -585,6 +565,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: assert(idx == 0); break;
@@ -851,8 +832,7 @@ struct hlsl_type *hlsl_new_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim
if (!(type = hlsl_alloc(ctx, sizeof(*type)))) return NULL; - type->class = HLSL_CLASS_OBJECT; - type->base_type = HLSL_TYPE_UAV; + type->class = HLSL_CLASS_UAV; type->dimx = format->dimx; type->dimy = 1; type->sampler_dim = dim; @@ -958,6 +938,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type) case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: return 1;
case HLSL_CLASS_VOID: @@ -976,16 +957,15 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 return false; if (t1->base_type != t2->base_type) return false; - if (t1->class == HLSL_CLASS_SAMPLER || t1->class == HLSL_CLASS_TEXTURE - || t1->base_type == HLSL_TYPE_UAV) + if (t1->class == HLSL_CLASS_SAMPLER || t1->class == HLSL_CLASS_TEXTURE || t1->class == HLSL_CLASS_UAV) { if (t1->sampler_dim != t2->sampler_dim) return false; - if ((t1->class == HLSL_CLASS_TEXTURE || t1->base_type == HLSL_TYPE_UAV) + if ((t1->class == HLSL_CLASS_TEXTURE || t1->class == HLSL_CLASS_UAV) && t1->sampler_dim != HLSL_SAMPLER_DIM_GENERIC && !hlsl_types_are_equal(t1->e.resource.format, t2->e.resource.format)) return false; - if (t1->base_type == HLSL_TYPE_UAV && t1->e.resource.rasteriser_ordered != t2->e.resource.rasteriser_ordered) + if (t1->class == HLSL_CLASS_UAV && t1->e.resource.rasteriser_ordered != t2->e.resource.rasteriser_ordered) return false; } if ((t1->modifiers & HLSL_MODIFIER_ROW_MAJOR) @@ -1102,6 +1082,9 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, break; }
+ case HLSL_CLASS_UAV: + type->e.resource.rasteriser_ordered = old->e.resource.rasteriser_ordered; + /* fall through */ case HLSL_CLASS_TEXTURE: type->e.resource.format = old->e.resource.format; break; @@ -1109,11 +1092,6 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, case HLSL_CLASS_OBJECT: if (type->base_type == HLSL_TYPE_TECHNIQUE) type->e.version = old->e.version; - if (old->base_type == HLSL_TYPE_UAV) - { - type->e.resource.format = old->e.resource.format; - type->e.resource.rasteriser_ordered = old->e.resource.rasteriser_ordered; - } break;
default: @@ -1688,7 +1666,7 @@ bool hlsl_index_is_resource_access(struct hlsl_ir_index *index) { const struct hlsl_type *type = index->val.node->data_type;
- return type->class == HLSL_CLASS_TEXTURE || (type->class == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_UAV); + return type->class == HLSL_CLASS_TEXTURE || type->class == HLSL_CLASS_UAV; }
bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index) @@ -1709,7 +1687,7 @@ struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *v if (!(index = hlsl_alloc(ctx, sizeof(*index)))) return NULL;
- if (type->class == HLSL_CLASS_TEXTURE || type->class == HLSL_CLASS_OBJECT) + if (type->class == HLSL_CLASS_TEXTURE || type->class == HLSL_CLASS_UAV) type = type->e.resource.format; else if (type->class == HLSL_CLASS_MATRIX) type = hlsl_get_vector_type(ctx, type->base_type, type->dimx); @@ -2363,29 +2341,21 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru } return string;
- case HLSL_CLASS_OBJECT: - { - switch (type->base_type) + case HLSL_CLASS_UAV: + if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER) + vkd3d_string_buffer_printf(string, "RWBuffer"); + else if (type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER) + vkd3d_string_buffer_printf(string, "RWStructuredBuffer"); + else + vkd3d_string_buffer_printf(string, "RWTexture%s", dimensions[type->sampler_dim]); + if ((inner_string = hlsl_type_to_string(ctx, type->e.resource.format))) { - case HLSL_TYPE_UAV: - if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER) - vkd3d_string_buffer_printf(string, "RWBuffer"); - else if (type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER) - vkd3d_string_buffer_printf(string, "RWStructuredBuffer"); - else - vkd3d_string_buffer_printf(string, "RWTexture%s", dimensions[type->sampler_dim]); - if ((inner_string = hlsl_type_to_string(ctx, type->e.resource.format))) - { - vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer); - hlsl_release_string_buffer(ctx, inner_string); - } - return string; - - default: - break; + vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer); + hlsl_release_string_buffer(ctx, inner_string); } - } + return string;
+ case HLSL_CLASS_OBJECT: case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_VOID: diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 9f333fd33..0ce0c5bcd 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -82,6 +82,7 @@ enum hlsl_type_class HLSL_CLASS_SAMPLER, HLSL_CLASS_STRING, HLSL_CLASS_TEXTURE, + HLSL_CLASS_UAV, HLSL_CLASS_VOID, };
@@ -94,7 +95,6 @@ enum hlsl_base_type HLSL_TYPE_UINT, HLSL_TYPE_BOOL, HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL, - HLSL_TYPE_UAV, HLSL_TYPE_PIXELSHADER, HLSL_TYPE_VERTEXSHADER, HLSL_TYPE_PASS, @@ -153,7 +153,7 @@ struct hlsl_type /* If class is HLSL_CLASS_SAMPLER, then sampler_dim is <= HLSL_SAMPLER_DIM_LAST_SAMPLER. * If class is HLSL_CLASS_TEXTURE, then sampler_dim can be any value of the enum except * HLSL_SAMPLER_DIM_GENERIC and HLSL_SAMPLER_DIM_COMPARISON. - * If base_type is HLSL_TYPE_UAV, then sampler_dim must be one of HLSL_SAMPLER_DIM_1D, + * If class is HLSL_CLASS_UAV, then sampler_dim must be one of HLSL_SAMPLER_DIM_1D, * HLSL_SAMPLER_DIM_2D, HLSL_SAMPLER_DIM_3D, HLSL_SAMPLER_DIM_1DARRAY, HLSL_SAMPLER_DIM_2DARRAY, * HLSL_SAMPLER_DIM_BUFFER, or HLSL_SAMPLER_DIM_STRUCTURED_BUFFER. * Otherwise, sampler_dim is not used */ @@ -171,8 +171,6 @@ struct hlsl_type * If type is HLSL_CLASS_MATRIX, then dimx is the number of columns, and dimy the number of rows. * If type is HLSL_CLASS_ARRAY, then dimx and dimy have the same value as in the type of the array elements. * If type is HLSL_CLASS_STRUCT, then dimx is the sum of (dimx * dimy) of every component, and dimy = 1. - * If type is HLSL_CLASS_OBJECT, dimx and dimy depend on the base_type: - * If base_type is HLSL_TYPE_UAV, then dimx is the dimx of e.resource_format, and dimy = 1. * Otherwise both dimx = 1 and dimy = 1. */ unsigned int dimx; unsigned int dimy; @@ -194,8 +192,8 @@ struct hlsl_type /* Array length, or HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT if it is not known yet at parse time. */ unsigned int elements_count; } array; - /* Additional information if the base_type is HLSL_TYPE_TEXTURE or - * HLSL_TYPE_UAV. */ + /* Additional information if the class is HLSL_CLASS_TEXTURE or + * HLSL_CLASS_UAV. */ struct { /* Format of the data contained within the type. */ diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 1832aa8b8..d3b8d5f23 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -833,8 +833,7 @@ static bool add_array_access(struct hlsl_ctx *ctx, struct hlsl_block *block, str const struct hlsl_type *expr_type = array->data_type, *index_type = index->data_type; struct hlsl_ir_node *return_index, *cast;
- if ((expr_type->class == HLSL_CLASS_TEXTURE - || (expr_type->class == HLSL_CLASS_OBJECT && expr_type->base_type == HLSL_TYPE_UAV)) + if ((expr_type->class == HLSL_CLASS_TEXTURE || expr_type->class == HLSL_CLASS_UAV) && expr_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC) { unsigned int dim_count = hlsl_sampler_dim_count(expr_type->sampler_dim); @@ -1941,10 +1940,9 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct hlsl_blo return NULL;
resource_type = hlsl_deref_get_type(ctx, &resource_deref); - assert(resource_type->class == HLSL_CLASS_OBJECT); - assert(resource_type->class == HLSL_CLASS_TEXTURE || resource_type->base_type == HLSL_TYPE_UAV); + assert(resource_type->class == HLSL_CLASS_TEXTURE || resource_type->class == HLSL_CLASS_UAV);
- if (resource_type->base_type != HLSL_TYPE_UAV) + if (resource_type->class != HLSL_CLASS_UAV) hlsl_error(ctx, &lhs->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Read-only resources cannot be stored to.");
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index e6c8dab9c..f6cccfe8b 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1627,6 +1627,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, case HLSL_CLASS_VECTOR: case HLSL_CLASS_SAMPLER: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: case HLSL_CLASS_OBJECT: break;
diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index db4e5e2fb..6ee06c02d 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3011,6 +3011,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type) case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_UAV: case HLSL_CLASS_VOID: break; } @@ -3119,15 +3120,8 @@ static D3D_SHADER_INPUT_TYPE sm4_resource_type(const struct hlsl_type *type) return D3D_SIT_SAMPLER; case HLSL_CLASS_TEXTURE: return D3D_SIT_TEXTURE; - case HLSL_CLASS_OBJECT: - switch (type->base_type) - { - case HLSL_TYPE_UAV: - return D3D_SIT_UAV_RWTYPED; - default: - break; - } - + case HLSL_CLASS_UAV: + return D3D_SIT_UAV_RWTYPED; default: break; }