[PATCH vkd3d] vkd3d-shader/hlsl: Add support for texture arrays. Replace sampler_dim with resource_dim.
Zebediah Figura
zfigura at codeweavers.com
Tue Dec 7 11:57:58 CST 2021
On 12/6/21 12:28, Francisco Casas wrote:
> New values for enum hlsl_sampler_dim are added in order to represent
> dimension types for textures that don't have their analog sampler,
> like Texture2DArray.
>
> enum hlsl_sampler_dim is then renamed to enum hlsl_resource_dim to
> convey that it no longer represents just sampler types.
>
> Parsing and initialization of Texture2DArray, Texture2DMS,
> Texture2DMSArray, and TextureCubeArray is added.
>
> sampler_dim_count() is moved from hlsl.y to hlsl.h since it can be useful
> in other files, like in write_sm4_ld() in hlsl_sm4.c.
>
> ---
>
> This patch is an alternative to 221390, which proposed to separate
> sampler_dim into sampler_dim and texture_dim.
> It will probably be resent after Matteo's batch is reviewed.
>
> Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
> ---
As one can tell from the commit message, this patch does at least two
things at once, which is at least one too many ;-)
Personally I'm not sure that "sampler_dim" (or any of the associated
names) need to be changed. I may be looking at things with GLSL-coloured
glasses, but it seems to me there's no conceptual reason why a sampler
couldn't have an array dimension; but rather HLSL just doesn't have a
"sample2DArray" keyword.
> @@ -1845,9 +1828,11 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
> /* Only HLSL_IR_LOAD can return an object. */
> object_load = hlsl_ir_load(object);
>
> - if (!strcmp(name, "Load"))
> + if (!strcmp(name, "Load")
> + && object_type->resource_dim != HLSL_RESOURCE_DIM_CUBE
> + && object_type->resource_dim != HLSL_RESOURCE_DIM_CUBEARRAY)
> {
> - const unsigned int sampler_dim = sampler_dim_count(object_type->sampler_dim);
> + const unsigned int sampler_dim = sampler_dim_count(object_type->resource_dim);
> struct hlsl_ir_resource_load *load;
> struct hlsl_ir_node *coords;
>
This should also be a separate patch.
> @@ -1862,7 +1847,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
>
> /* +1 for the mipmap level */
> if (!(coords = add_implicit_conversion(ctx, instrs, params->args[0],
> - hlsl_get_vector_type(ctx, HLSL_TYPE_INT, sampler_dim + 1), loc)))
> + hlsl_get_vector_type(ctx, HLSL_TYPE_INT, (sampler_dim==4)? 4 : sampler_dim + 1), loc)))
> return false;
>
> if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format, HLSL_RESOURCE_LOAD,
This seems redundant; with the above hunk we can't hit this path for
cube arrays.
> @@ -1871,9 +1856,11 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
> list_add_tail(instrs, &load->node.entry);
> return true;
> }
> - else if (!strcmp(name, "Sample"))
> + else if (!strcmp(name, "Sample")
> + && object_type->resource_dim != HLSL_RESOURCE_DIM_2DMS
> + && object_type->resource_dim != HLSL_RESOURCE_DIM_2DMSARRAY)
> {
> - const unsigned int sampler_dim = sampler_dim_count(object_type->sampler_dim);
> + const unsigned int sampler_dim = sampler_dim_count(object_type->resource_dim);
> const struct hlsl_type *sampler_type;
> struct hlsl_ir_resource_load *load;
> struct hlsl_ir_load *sampler_load;
This should also be a separate patch.
> @@ -424,20 +428,34 @@ static D3D_RESOURCE_RETURN_TYPE sm4_resource_format(const struct hlsl_type *type
>
> static D3D_SRV_DIMENSION sm4_rdef_resource_dimension(const struct hlsl_type *type)
> {
> - switch (type->sampler_dim)
> + if (type->base_type == HLSL_TYPE_TEXTURE)
Does this need to be a conditional? Should this just be an assertion
instead?
> {
> - case HLSL_SAMPLER_DIM_1D:
> - return D3D_SRV_DIMENSION_TEXTURE1D;
> - case HLSL_SAMPLER_DIM_2D:
> - return D3D_SRV_DIMENSION_TEXTURE2D;
> - case HLSL_SAMPLER_DIM_3D:
> - return D3D_SRV_DIMENSION_TEXTURE3D;
> - case HLSL_SAMPLER_DIM_CUBE:
> - return D3D_SRV_DIMENSION_TEXTURECUBE;
> - default:
> - assert(0);
> - return D3D_SRV_DIMENSION_UNKNOWN;
> + switch (type->resource_dim)
> + {
> + case HLSL_RESOURCE_DIM_1D:
> + return D3D_SRV_DIMENSION_TEXTURE1D;
> + case HLSL_RESOURCE_DIM_1DARRAY:
> + return D3D_SRV_DIMENSION_TEXTURE1DARRAY;
> + case HLSL_RESOURCE_DIM_2D:
> + return D3D_SRV_DIMENSION_TEXTURE2D;
> + case HLSL_RESOURCE_DIM_2DARRAY:
> + return D3D_SRV_DIMENSION_TEXTURE2DARRAY;
> + case HLSL_RESOURCE_DIM_2DMS:
> + return D3D_SRV_DIMENSION_TEXTURE2DMS;
> + case HLSL_RESOURCE_DIM_2DMSARRAY:
> + return D3D_SRV_DIMENSION_TEXTURE2DMSARRAY;
> + case HLSL_RESOURCE_DIM_3D:
> + return D3D_SRV_DIMENSION_TEXTURE3D;
> + case HLSL_RESOURCE_DIM_CUBE:
> + return D3D_SRV_DIMENSION_TEXTURECUBE;
> + case HLSL_RESOURCE_DIM_CUBEARRAY:
> + return D3D_SRV_DIMENSION_TEXTURECUBEARRAY;
> + default:
> + assert(0);
> + return D3D_SRV_DIMENSION_UNKNOWN;
> + }
> }
> + assert(0);
> }
>
> static int sm4_compare_externs(const struct hlsl_ir_var *a, const struct hlsl_ir_var *b)
> @@ -711,20 +729,34 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc)
>
> static enum vkd3d_sm4_resource_type sm4_resource_dimension(const struct hlsl_type *type)
> {
> - switch (type->sampler_dim)
> - {
> - case HLSL_SAMPLER_DIM_1D:
> - return VKD3D_SM4_RESOURCE_TEXTURE_1D;
> - case HLSL_SAMPLER_DIM_2D:
> - return VKD3D_SM4_RESOURCE_TEXTURE_2D;
> - case HLSL_SAMPLER_DIM_3D:
> - return VKD3D_SM4_RESOURCE_TEXTURE_3D;
> - case HLSL_SAMPLER_DIM_CUBE:
> - return VKD3D_SM4_RESOURCE_TEXTURE_CUBE;
> - default:
> - assert(0);
> - return 0;
> + if (type->base_type == HLSL_TYPE_TEXTURE) {
Same here.
> + switch (type->resource_dim)
> + {
> + case HLSL_RESOURCE_DIM_1D:
> + return VKD3D_SM4_RESOURCE_TEXTURE_1D;
> + case HLSL_RESOURCE_DIM_2D:
> + return VKD3D_SM4_RESOURCE_TEXTURE_2D;
> + case HLSL_RESOURCE_DIM_3D:
> + return VKD3D_SM4_RESOURCE_TEXTURE_3D;
> + case HLSL_RESOURCE_DIM_CUBE:
> + return VKD3D_SM4_RESOURCE_TEXTURE_CUBE;
> + case HLSL_RESOURCE_DIM_1DARRAY:
> + return VKD3D_SM4_RESOURCE_TEXTURE_1DARRAY;
> + case HLSL_RESOURCE_DIM_2DARRAY:
> + return VKD3D_SM4_RESOURCE_TEXTURE_2DARRAY;
> + case HLSL_RESOURCE_DIM_2DMS:
> + return VKD3D_SM4_RESOURCE_TEXTURE_2DMS;
> + case HLSL_RESOURCE_DIM_2DMSARRAY:
> + return VKD3D_SM4_RESOURCE_TEXTURE_2DMSARRAY;
> + case HLSL_RESOURCE_DIM_CUBEARRAY:
> + return VKD3D_SM4_RESOURCE_TEXTURE_CUBEARRAY;
> + default:
> + assert(0);
> + return 0;
> + }
> }
> + assert(0);
> + return 0;
> }
>
> struct sm4_register
More information about the wine-devel
mailing list