From: Francisco Casas fcasas@codeweavers.com
So we have to explicitily enumerate the sampler dimensions that don't call raise_invalid_method_object_type().
Also, call hlsl_sampler_dim_count() and hlsl_offset_dim_count() after type checking, to avoid reaching unreacheable cases. --- libs/vkd3d-shader/hlsl.y | 92 +++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 24 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5f6334a4d..8b4754bbf 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4252,18 +4252,25 @@ static bool add_load_method_call(struct hlsl_ctx *ctx, struct hlsl_block *block, const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { const struct hlsl_type *object_type = object->data_type; - const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); - const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_LOAD}; + unsigned int sampler_dim, offset_dim; struct hlsl_ir_node *load; bool multisampled;
- if (object_type->sampler_dim == HLSL_SAMPLER_DIM_CUBE - || object_type->sampler_dim == HLSL_SAMPLER_DIM_CUBEARRAY) + if (object_type->sampler_dim != HLSL_SAMPLER_DIM_1D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_3D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_1DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY) { return raise_invalid_method_object_type(ctx, object_type, name, loc); }
+ sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); + offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + multisampled = object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY;
@@ -4311,18 +4318,25 @@ static bool add_sample_method_call(struct hlsl_ctx *ctx, struct hlsl_block *bloc const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { const struct hlsl_type *object_type = object->data_type; - const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); - const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_SAMPLE}; + unsigned int sampler_dim, offset_dim; const struct hlsl_type *sampler_type; struct hlsl_ir_node *load;
- if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS - || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY) + if (object_type->sampler_dim != HLSL_SAMPLER_DIM_1D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_3D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE + && object_type->sampler_dim != HLSL_SAMPLER_DIM_1DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBEARRAY) { return raise_invalid_method_object_type(ctx, object_type, name, loc); }
+ sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); + offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + if (params->args_count < 2 || params->args_count > 4 + !!offset_dim) { hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, @@ -4375,18 +4389,25 @@ static bool add_sample_cmp_method_call(struct hlsl_ctx *ctx, struct hlsl_block * const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { const struct hlsl_type *object_type = object->data_type; - const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); - const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); struct hlsl_resource_load_params load_params = { 0 }; + unsigned int sampler_dim, offset_dim; const struct hlsl_type *sampler_type; struct hlsl_ir_node *load;
- if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS - || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY) + if (object_type->sampler_dim != HLSL_SAMPLER_DIM_1D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_3D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE + && object_type->sampler_dim != HLSL_SAMPLER_DIM_1DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBEARRAY) { return raise_invalid_method_object_type(ctx, object_type, name, loc); }
+ sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); + offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + if (!strcmp(name, "SampleCmpLevelZero")) load_params.type = HLSL_RESOURCE_SAMPLE_CMP_LZ; else @@ -4449,13 +4470,11 @@ static bool add_gather_method_call(struct hlsl_ctx *ctx, struct hlsl_block *bloc const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { const struct hlsl_type *object_type = object->data_type; - const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); - const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); struct hlsl_resource_load_params load_params = {0}; + unsigned int sampler_dim, offset_dim; const struct hlsl_type *sampler_type; struct hlsl_ir_node *load; unsigned int read_channel; - if (object_type->sampler_dim != HLSL_SAMPLER_DIM_2D && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE @@ -4464,6 +4483,9 @@ static bool add_gather_method_call(struct hlsl_ctx *ctx, struct hlsl_block *bloc return raise_invalid_method_object_type(ctx, object_type, name, loc); }
+ sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); + offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + if (!strcmp(name, "GatherGreen")) { load_params.type = HLSL_RESOURCE_GATHER_GREEN; @@ -4616,7 +4638,15 @@ static bool add_getdimensions_method_call(struct hlsl_ctx *ctx, struct hlsl_bloc }; const struct overload *o = NULL;
- if (object_type->sampler_dim > HLSL_SAMPLER_DIM_LAST_TEXTURE) + if (object_type->sampler_dim != HLSL_SAMPLER_DIM_1D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_3D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE + && object_type->sampler_dim != HLSL_SAMPLER_DIM_1DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBEARRAY) { hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "GetDimensions() is not defined for this type."); } @@ -4732,17 +4762,24 @@ static bool add_sample_lod_method_call(struct hlsl_ctx *ctx, struct hlsl_block * { const struct hlsl_type *object_type = object->data_type; struct hlsl_resource_load_params load_params = { 0 }; - const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); - const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + unsigned int sampler_dim, offset_dim; const struct hlsl_type *sampler_type; struct hlsl_ir_node *load;
- if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS - || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY) + if (object_type->sampler_dim != HLSL_SAMPLER_DIM_1D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_3D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE + && object_type->sampler_dim != HLSL_SAMPLER_DIM_1DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBEARRAY) { return raise_invalid_method_object_type(ctx, object_type, name, loc); }
+ sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); + offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + if (!strcmp(name, "SampleLevel")) load_params.type = HLSL_RESOURCE_SAMPLE_LOD; else @@ -4802,17 +4839,24 @@ static bool add_sample_grad_method_call(struct hlsl_ctx *ctx, struct hlsl_block { const struct hlsl_type *object_type = object->data_type; struct hlsl_resource_load_params load_params = { 0 }; - const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); - const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + unsigned int sampler_dim, offset_dim; const struct hlsl_type *sampler_type; struct hlsl_ir_node *load;
- if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS - || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY) + if (object_type->sampler_dim != HLSL_SAMPLER_DIM_1D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_3D + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE + && object_type->sampler_dim != HLSL_SAMPLER_DIM_1DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY + && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBEARRAY) { return raise_invalid_method_object_type(ctx, object_type, name, loc); }
+ sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); + offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); + load_params.type = HLSL_RESOURCE_SAMPLE_GRAD;
if (params->args_count < 4 || params->args_count > 5 + !!offset_dim)