vkd3d-shader/hlsl: Handle snorm/unorm types as resource formats.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2024-10-15 13:20:15 +02:00 committed by Henri Verbeet
parent 6fd1a1ce7e
commit fb2b974466
Notes: Henri Verbeet 2024-10-22 20:53:53 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1189
7 changed files with 97 additions and 9 deletions

View File

@ -265,6 +265,7 @@ vkd3d_shader_tests = \
tests/hlsl/unbounded-array-5.1.shader_test \ tests/hlsl/unbounded-array-5.1.shader_test \
tests/hlsl/uniform-parameters.shader_test \ tests/hlsl/uniform-parameters.shader_test \
tests/hlsl/uniform-semantics.shader_test \ tests/hlsl/uniform-semantics.shader_test \
tests/hlsl/unorm-snorm.shader_test \
tests/hlsl/unroll.shader_test \ tests/hlsl/unroll.shader_test \
tests/hlsl/unsigned.shader_test \ tests/hlsl/unsigned.shader_test \
tests/hlsl/vector-indexing-uniform.shader_test \ tests/hlsl/vector-indexing-uniform.shader_test \

View File

@ -410,10 +410,12 @@ struct hlsl_attribute
#define HLSL_MODIFIER_SINGLE 0x00020000 #define HLSL_MODIFIER_SINGLE 0x00020000
#define HLSL_MODIFIER_EXPORT 0x00040000 #define HLSL_MODIFIER_EXPORT 0x00040000
#define HLSL_STORAGE_ANNOTATION 0x00080000 #define HLSL_STORAGE_ANNOTATION 0x00080000
#define HLSL_MODIFIER_UNORM 0x00100000
#define HLSL_MODIFIER_SNORM 0x00200000
#define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_MODIFIER_VOLATILE | \ #define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_MODIFIER_VOLATILE | \
HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \ HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \
HLSL_MODIFIER_COLUMN_MAJOR) HLSL_MODIFIER_COLUMN_MAJOR | HLSL_MODIFIER_UNORM | HLSL_MODIFIER_SNORM)
#define HLSL_INTERPOLATION_MODIFIERS_MASK (HLSL_STORAGE_NOINTERPOLATION | HLSL_STORAGE_CENTROID | \ #define HLSL_INTERPOLATION_MODIFIERS_MASK (HLSL_STORAGE_NOINTERPOLATION | HLSL_STORAGE_CENTROID | \
HLSL_STORAGE_NOPERSPECTIVE | HLSL_STORAGE_LINEAR) HLSL_STORAGE_NOPERSPECTIVE | HLSL_STORAGE_LINEAR)

View File

@ -142,6 +142,7 @@ samplerCUBE {return KW_SAMPLERCUBE; }
SamplerState {return KW_SAMPLER; } SamplerState {return KW_SAMPLER; }
sampler_state {return KW_SAMPLER_STATE; } sampler_state {return KW_SAMPLER_STATE; }
shared {return KW_SHARED; } shared {return KW_SHARED; }
snorm {return KW_SNORM; }
stateblock {return KW_STATEBLOCK; } stateblock {return KW_STATEBLOCK; }
stateblock_state {return KW_STATEBLOCK_STATE; } stateblock_state {return KW_STATEBLOCK_STATE; }
static {return KW_STATIC; } static {return KW_STATIC; }
@ -171,6 +172,7 @@ true {return KW_TRUE; }
typedef {return KW_TYPEDEF; } typedef {return KW_TYPEDEF; }
unsigned {return KW_UNSIGNED; } unsigned {return KW_UNSIGNED; }
uniform {return KW_UNIFORM; } uniform {return KW_UNIFORM; }
unorm {return KW_UNORM; }
vector {return KW_VECTOR; } vector {return KW_VECTOR; }
VertexShader {return KW_VERTEXSHADER; } VertexShader {return KW_VERTEXSHADER; }
vertexshader {return KW_VERTEXSHADER; } vertexshader {return KW_VERTEXSHADER; }

View File

@ -6479,6 +6479,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim,
%token KW_SAMPLER_STATE %token KW_SAMPLER_STATE
%token KW_SAMPLERCOMPARISONSTATE %token KW_SAMPLERCOMPARISONSTATE
%token KW_SHARED %token KW_SHARED
%token KW_SNORM
%token KW_STATEBLOCK %token KW_STATEBLOCK
%token KW_STATEBLOCK_STATE %token KW_STATEBLOCK_STATE
%token KW_STATIC %token KW_STATIC
@ -6503,6 +6504,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim,
%token KW_TYPEDEF %token KW_TYPEDEF
%token KW_UNSIGNED %token KW_UNSIGNED
%token KW_UNIFORM %token KW_UNIFORM
%token KW_UNORM
%token KW_VECTOR %token KW_VECTOR
%token KW_VERTEXSHADER %token KW_VERTEXSHADER
%token KW_VOID %token KW_VOID
@ -6642,6 +6644,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim,
%type <type> type %type <type> type
%type <type> type_no_void %type <type> type_no_void
%type <type> typedef_type %type <type> typedef_type
%type <type> resource_format
%type <variable_def> state_block_list %type <variable_def> state_block_list
%type <variable_def> type_spec %type <variable_def> type_spec
@ -7637,6 +7640,15 @@ rov_type:
$$ = HLSL_SAMPLER_DIM_3D; $$ = HLSL_SAMPLER_DIM_3D;
} }
resource_format:
var_modifiers type
{
uint32_t modifiers = $1;
if (!($$ = apply_type_modifiers(ctx, $2, &modifiers, false, &@1)))
YYABORT;
}
type_no_void: type_no_void:
KW_VECTOR '<' type ',' C_INTEGER '>' KW_VECTOR '<' type ',' C_INTEGER '>'
{ {
@ -7730,18 +7742,18 @@ type_no_void:
{ {
$$ = hlsl_new_texture_type(ctx, $1, hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, 4), 0); $$ = hlsl_new_texture_type(ctx, $1, hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, 4), 0);
} }
| texture_type '<' type '>' | texture_type '<' resource_format '>'
{ {
validate_texture_format_type(ctx, $3, &@3); validate_texture_format_type(ctx, $3, &@3);
$$ = hlsl_new_texture_type(ctx, $1, $3, 0); $$ = hlsl_new_texture_type(ctx, $1, $3, 0);
} }
| texture_ms_type '<' type '>' | texture_ms_type '<' resource_format '>'
{ {
validate_texture_format_type(ctx, $3, &@3); validate_texture_format_type(ctx, $3, &@3);
$$ = hlsl_new_texture_type(ctx, $1, $3, 0); $$ = hlsl_new_texture_type(ctx, $1, $3, 0);
} }
| texture_ms_type '<' type ',' shift_expr '>' | texture_ms_type '<' resource_format ',' shift_expr '>'
{ {
unsigned int sample_count; unsigned int sample_count;
struct hlsl_block block; struct hlsl_block block;
@ -7757,14 +7769,14 @@ type_no_void:
$$ = hlsl_new_texture_type(ctx, $1, $3, sample_count); $$ = hlsl_new_texture_type(ctx, $1, $3, sample_count);
} }
| uav_type '<' type '>' | uav_type '<' resource_format '>'
{ {
validate_uav_type(ctx, $1, $3, &@3); validate_uav_type(ctx, $1, $3, &@3);
$$ = hlsl_new_uav_type(ctx, $1, $3, false); $$ = hlsl_new_uav_type(ctx, $1, $3, false);
} }
| rov_type '<' type '>' | rov_type '<' resource_format '>'
{ {
validate_uav_type(ctx, $1, $3, &@3); validate_uav_type(ctx, $1, $3, &@4);
$$ = hlsl_new_uav_type(ctx, $1, $3, true); $$ = hlsl_new_uav_type(ctx, $1, $3, true);
} }
| KW_STRING | KW_STRING
@ -8314,6 +8326,14 @@ var_modifiers:
{ {
$$ = add_modifiers(ctx, $2, HLSL_MODIFIER_EXPORT, &@1); $$ = add_modifiers(ctx, $2, HLSL_MODIFIER_EXPORT, &@1);
} }
| KW_UNORM var_modifiers
{
$$ = add_modifiers(ctx, $2, HLSL_MODIFIER_UNORM, &@1);
}
| KW_SNORM var_modifiers
{
$$ = add_modifiers(ctx, $2, HLSL_MODIFIER_SNORM, &@1);
}
| var_identifier var_modifiers | var_identifier var_modifiers
{ {
$$ = $2; $$ = $2;

View File

@ -3430,13 +3430,19 @@ static D3D_SHADER_INPUT_TYPE sm4_resource_type(const struct hlsl_type *type)
static enum vkd3d_sm4_data_type sm4_data_type(const struct hlsl_type *type) static enum vkd3d_sm4_data_type sm4_data_type(const struct hlsl_type *type)
{ {
switch (type->e.resource.format->e.numeric.type) const struct hlsl_type *format = type->e.resource.format;
switch (format->e.numeric.type)
{ {
case HLSL_TYPE_DOUBLE: case HLSL_TYPE_DOUBLE:
return VKD3D_SM4_DATA_DOUBLE; return VKD3D_SM4_DATA_DOUBLE;
case HLSL_TYPE_FLOAT: case HLSL_TYPE_FLOAT:
case HLSL_TYPE_HALF: case HLSL_TYPE_HALF:
if (format->modifiers & HLSL_MODIFIER_UNORM)
return VKD3D_SM4_DATA_UNORM;
if (format->modifiers & HLSL_MODIFIER_SNORM)
return VKD3D_SM4_DATA_SNORM;
return VKD3D_SM4_DATA_FLOAT; return VKD3D_SM4_DATA_FLOAT;
case HLSL_TYPE_INT: case HLSL_TYPE_INT:

View File

@ -0,0 +1,43 @@
[require]
shader model >= 5.0
[pixel shader fail todo]
unorm uint4 var;
float4 main() : sv_target
{
return 0;
}
[pixel shader fail]
float4 unorm;
float4 main() : sv_target
{
return 0;
}
[pixel shader fail]
float4 snorm;
float4 main() : sv_target
{
return 0;
}
[pixel shader]
unorm float var;
float4 main() : sv_target
{
return var;
}
[pixel shader]
RWTexture2D<unorm float> u;
float4 main() : sv_target
{
u[uint2(0, 0)] = 0.7;
return 0;
}

View File

@ -1506,6 +1506,13 @@ static void test_reflection(void)
" Texture1DArray<float> b;\n" " Texture1DArray<float> b;\n"
" struct { SamplerState a; } c;\n" " struct { SamplerState a; } c;\n"
"} k;\n" "} k;\n"
"struct\n"
"{\n"
" Texture2D<snorm float4> a;\n"
" Texture2D<unorm float4> b;\n"
" RWTexture2D<snorm float4> c;\n"
" RWTexture2D<unorm float4> d;\n"
"} l;\n"
"cbuffer buf : register(b3[-1])\n" "cbuffer buf : register(b3[-1])\n"
"{\n" "{\n"
" float4 v;\n" " float4 v;\n"
@ -1516,8 +1523,11 @@ static void test_reflection(void)
"};\n" "};\n"
"float4 main(float2 pos : texcoord) : SV_TARGET\n" "float4 main(float2 pos : texcoord) : SV_TARGET\n"
"{\n" "{\n"
" l.c[uint2(0,0)] = 0;\n"
" l.d[uint2(0,0)] = 0;\n"
" return a.Sample(b, pos) + a.Sample(c, pos) + a.Sample(d, pos) + tex2D(f, pos) + tex2D(e, pos)" " return a.Sample(b, pos) + a.Sample(c, pos) + a.Sample(d, pos) + tex2D(f, pos) + tex2D(e, pos)"
" + tex2D(g, pos) + h.b.Load(h.c).x + k.b.Sample(k.c.a, pos) + v + vv;\n" " + tex2D(g, pos) + h.b.Load(h.c).x + k.b.Sample(k.c.a, pos) + v + vv + l.a.Load(int3(0,0,0))"
" + l.b.Load(int3(0,0,0));\n"
"}"; "}";
static const D3D12_SHADER_INPUT_BIND_DESC ps_bindings[] = static const D3D12_SHADER_INPUT_BIND_DESC ps_bindings[] =
@ -1535,6 +1545,10 @@ static void test_reflection(void)
{"a", D3D_SIT_TEXTURE, 3, 1, D3D_SIF_TEXTURE_COMPONENTS, D3D_RETURN_TYPE_FLOAT, D3D_SRV_DIMENSION_TEXTURE2D, ~0u, 0, 3}, {"a", D3D_SIT_TEXTURE, 3, 1, D3D_SIF_TEXTURE_COMPONENTS, D3D_RETURN_TYPE_FLOAT, D3D_SRV_DIMENSION_TEXTURE2D, ~0u, 0, 3},
{"k.b", D3D_SIT_TEXTURE, 5, 1, 0, D3D_RETURN_TYPE_FLOAT, D3D_SRV_DIMENSION_TEXTURE1DARRAY, ~0u, 0, 5}, {"k.b", D3D_SIT_TEXTURE, 5, 1, 0, D3D_RETURN_TYPE_FLOAT, D3D_SRV_DIMENSION_TEXTURE1DARRAY, ~0u, 0, 5},
{"h.b", D3D_SIT_TEXTURE, 7, 1, D3D_SIF_USERPACKED | D3D_SIF_TEXTURE_COMPONENT_0, D3D_RETURN_TYPE_SINT, D3D_SRV_DIMENSION_TEXTURE1D, ~0u, 0, 7}, {"h.b", D3D_SIT_TEXTURE, 7, 1, D3D_SIF_USERPACKED | D3D_SIF_TEXTURE_COMPONENT_0, D3D_RETURN_TYPE_SINT, D3D_SRV_DIMENSION_TEXTURE1D, ~0u, 0, 7},
{"l.a", D3D_SIT_TEXTURE, 9, 1, D3D_SIF_TEXTURE_COMPONENTS, D3D_RETURN_TYPE_SNORM, D3D_SRV_DIMENSION_TEXTURE2D, ~0u, 0, 9},
{"l.b", D3D_SIT_TEXTURE, 10, 1, D3D_SIF_TEXTURE_COMPONENTS, D3D_RETURN_TYPE_UNORM, D3D_SRV_DIMENSION_TEXTURE2D, ~0u, 0, 10},
{"l.c", D3D_SIT_UAV_RWTYPED, 1, 1, D3D_SIF_TEXTURE_COMPONENTS, D3D_RETURN_TYPE_SNORM, D3D_SRV_DIMENSION_TEXTURE2D, ~0u, 0, 1},
{"l.d", D3D_SIT_UAV_RWTYPED, 2, 1, D3D_SIF_TEXTURE_COMPONENTS, D3D_RETURN_TYPE_UNORM, D3D_SRV_DIMENSION_TEXTURE2D, ~0u, 0, 2},
{"buf2", D3D_SIT_CBUFFER, 0, 1, D3D_SIF_USERPACKED, .uID = 0}, {"buf2", D3D_SIT_CBUFFER, 0, 1, D3D_SIF_USERPACKED, .uID = 0},
{"$Globals", D3D_SIT_CBUFFER, 1, 1, .uID = 1}, {"$Globals", D3D_SIT_CBUFFER, 1, 1, .uID = 1},
{"buf", D3D_SIT_CBUFFER, 3, 1, D3D_SIF_USERPACKED, .uID = 3}, {"buf", D3D_SIT_CBUFFER, 3, 1, D3D_SIF_USERPACKED, .uID = 3},