vkd3d-shader/hlsl: Support the .Length property for Textures.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57686
This commit is contained in:
Francisco Casas
2025-04-07 18:55:04 -04:00
committed by Henri Verbeet
parent 2dce34d7e0
commit 7b21059ee5
Notes: Henri Verbeet 2025-04-14 17:16:49 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1452
2 changed files with 71 additions and 8 deletions

View File

@@ -6322,6 +6322,66 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct hlsl_block *block, stru
} }
} }
static bool add_object_property_access(struct hlsl_ctx *ctx,
struct hlsl_block *block, struct hlsl_ir_node *object, const char *name,
const struct vkd3d_shader_location *loc)
{
const struct hlsl_type *object_type = object->data_type;
struct hlsl_resource_load_params load_params;
struct hlsl_ir_node *zero;
unsigned int sampler_dim;
if (!strcmp(name, "Length"))
{
if (object_type->class != HLSL_CLASS_TEXTURE && object_type->class != HLSL_CLASS_UAV)
return false;
sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim);
switch (object_type->sampler_dim)
{
case HLSL_SAMPLER_DIM_1D:
case HLSL_SAMPLER_DIM_2D:
case HLSL_SAMPLER_DIM_3D:
case HLSL_SAMPLER_DIM_1DARRAY:
case HLSL_SAMPLER_DIM_2DARRAY:
case HLSL_SAMPLER_DIM_2DMS:
case HLSL_SAMPLER_DIM_2DMSARRAY:
break;
case HLSL_SAMPLER_DIM_BUFFER:
case HLSL_SAMPLER_DIM_STRUCTURED_BUFFER:
hlsl_fixme(ctx, loc, "'Length' property for buffers.");
block->value = ctx->error_instr;
return true;
default:
return false;
}
if (hlsl_version_lt(ctx, 4, 0))
{
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE,
"'Length' property can only be used on profiles 4.0 or higher.");
block->value = ctx->error_instr;
return true;
}
zero = hlsl_block_add_uint_constant(ctx, block, 0, loc);
memset(&load_params, 0, sizeof(load_params));
load_params.type = HLSL_RESOURCE_RESINFO;
load_params.resource = object;
load_params.lod = zero;
load_params.format = hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, sampler_dim);
hlsl_block_add_resource_load(ctx, block, &load_params, loc);
return true;
}
return false;
}
static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type *format, static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type *format,
const struct vkd3d_shader_location *loc) const struct vkd3d_shader_location *loc)
{ {
@@ -9122,6 +9182,9 @@ postfix_expr:
$1->value = ctx->error_instr; $1->value = ctx->error_instr;
} }
} }
else if (add_object_property_access(ctx, $1, node, $3, &@2))
{
}
else if (node->data_type->class != HLSL_CLASS_ERROR) else if (node->data_type->class != HLSL_CLASS_ERROR)
{ {
hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Invalid subscript \"%s\".", $3); hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Invalid subscript \"%s\".", $3);

View File

@@ -1,4 +1,4 @@
[pixel shader fail(sm<4 | sm>=6) todo(sm>=4)] [pixel shader fail(sm<4 | sm>=6)]
Texture1D tex1d; Texture1D tex1d;
Texture1DArray tex1da; Texture1DArray tex1da;
Texture2D tex2d; Texture2D tex2d;
@@ -26,7 +26,7 @@ size (2d, 2, 3)
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
[pixel shader fail(sm<4 | sm>=6) todo(sm>=4)] [pixel shader fail(sm<4 | sm>=6)]
Texture2D t; Texture2D t;
float4 main() : sv_target float4 main() : sv_target
@@ -35,10 +35,10 @@ float4 main() : sv_target
} }
[test] [test]
todo draw quad todo(glsl | msl) draw quad
probe (0, 0) rgba(2, 3, 0, 0) probe (0, 0) rgba(2, 3, 0, 0)
[pixel shader fail(sm<4 | sm>=6) todo(sm>=4)] [pixel shader fail(sm<4 | sm>=6)]
Texture2D t; Texture2D t;
float4 fun(float2 x) { return 1; } float4 fun(float2 x) { return 1; }
@@ -50,7 +50,7 @@ float4 main() : sv_target
} }
[test] [test]
todo draw quad draw quad
probe (0, 0) rgba(2, 2, 2, 2) probe (0, 0) rgba(2, 2, 2, 2)
[pixel shader fail] [pixel shader fail]
@@ -72,7 +72,7 @@ float4 main() : sv_target
[require] [require]
shader model >= 5.0 shader model >= 5.0
[pixel shader fail(sm<4 | sm>=6) todo(sm>=4)] [pixel shader fail(sm<4 | sm>=6)]
RWTexture1D<float> tex1d; RWTexture1D<float> tex1d;
RWTexture1DArray<float> tex1da; RWTexture1DArray<float> tex1da;
RWTexture2D<float> tex2d; RWTexture2D<float> tex2d;
@@ -115,7 +115,7 @@ size (2d, 2, 4)
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
[pixel shader fail(sm>=6) todo] [pixel shader fail(sm>=6)]
RWTexture2D<float> t : register(u1); RWTexture2D<float> t : register(u1);
float4 main() : sv_target float4 main() : sv_target
@@ -124,7 +124,7 @@ float4 main() : sv_target
} }
[test] [test]
todo draw quad todo(glsl | msl) draw quad
probe (0, 0) rgba(2, 4, 0, 0) probe (0, 0) rgba(2, 4, 0, 0)
[uav 1] [uav 1]