vkd3d-shader/hlsl: Parse SRV structured buffers.

This commit is contained in:
Victor Chiletto
2025-02-25 16:58:14 -03:00
committed by Henri Verbeet
parent 161d463f3c
commit 5dbf859029
Notes: Henri Verbeet 2025-08-05 16:40:11 +02:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1457
4 changed files with 37 additions and 13 deletions

View File

@@ -3219,12 +3219,14 @@ static void hlsl_dump_type(struct vkd3d_string_buffer *buffer, const struct hlsl
return;
}
VKD3D_ASSERT(hlsl_is_numeric_type(type->e.resource.format));
VKD3D_ASSERT(type->e.resource.format->e.numeric.type < ARRAY_SIZE(base_types));
if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER)
{
vkd3d_string_buffer_printf(buffer, "Buffer<");
}
else if (type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
{
vkd3d_string_buffer_printf(buffer, "StructuredBuffer<");
}
else
{
VKD3D_ASSERT(type->sampler_dim < ARRAY_SIZE(dimensions));

View File

@@ -158,6 +158,7 @@ static {return KW_STATIC; }
string {return KW_STRING; }
String {return KW_STRING; }
struct {return KW_STRUCT; }
StructuredBuffer {return KW_STRUCTUREDBUFFER; }
switch {return KW_SWITCH; }
tbuffer {return KW_TBUFFER; }
(?i:technique) {return KW_TECHNIQUE; }

View File

@@ -5637,6 +5637,7 @@ static unsigned int hlsl_offset_dim_count(enum hlsl_sampler_dim dim)
case HLSL_SAMPLER_DIM_CUBEARRAY:
case HLSL_SAMPLER_DIM_BUFFER:
case HLSL_SAMPLER_DIM_RAW_BUFFER:
case HLSL_SAMPLER_DIM_STRUCTURED_BUFFER:
/* Offset parameters not supported for these types. */
return 0;
default:
@@ -6554,19 +6555,25 @@ static bool add_object_property_access(struct hlsl_ctx *ctx,
return false;
}
static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type *format,
const struct vkd3d_shader_location *loc)
static void validate_texture_format_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim,
struct hlsl_type *format, const struct vkd3d_shader_location *loc)
{
if (format->class > HLSL_CLASS_VECTOR)
{
struct vkd3d_string_buffer *string;
struct vkd3d_string_buffer *string;
string = hlsl_type_to_string(ctx, format);
if (string)
if (!(string = hlsl_type_to_string(ctx, format)))
return;
if (dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
{
if (!type_contains_only_numerics(format))
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Texture data type %s is not scalar or vector.", string->buffer);
hlsl_release_string_buffer(ctx, string);
"SRV type %s is not numeric.", string->buffer);
}
else if (format->class > HLSL_CLASS_VECTOR)
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Texture data type %s is not scalar or vector.", string->buffer);
hlsl_release_string_buffer(ctx, string);
}
static bool check_continue(struct hlsl_ctx *ctx, const struct hlsl_scope *scope, const struct vkd3d_shader_location *loc)
@@ -6834,6 +6841,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim,
%token KW_STATIC
%token KW_STRING
%token KW_STRUCT
%token KW_STRUCTUREDBUFFER
%token KW_SWITCH
%token KW_TBUFFER
%token KW_TECHNIQUE
@@ -7921,6 +7929,10 @@ texture_type:
{
$$ = HLSL_SAMPLER_DIM_BUFFER;
}
| KW_STRUCTUREDBUFFER
{
$$ = HLSL_SAMPLER_DIM_STRUCTURED_BUFFER;
}
| KW_TEXTURE1D
{
$$ = HLSL_SAMPLER_DIM_1D;
@@ -8144,16 +8156,19 @@ type_no_void:
}
| texture_type
{
if ($1 == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Structured buffer type requires an explicit format.");
$$ = hlsl_new_texture_type(ctx, $1, hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, 4), 0);
}
| texture_type '<' resource_format '>'
{
validate_texture_format_type(ctx, $3, &@3);
validate_texture_format_type(ctx, $1, $3, &@3);
$$ = hlsl_new_texture_type(ctx, $1, $3, 0);
}
| texture_ms_type '<' resource_format '>'
{
validate_texture_format_type(ctx, $3, &@3);
validate_texture_format_type(ctx, $1, $3, &@3);
$$ = hlsl_new_texture_type(ctx, $1, $3, 0);
}

View File

@@ -11106,6 +11106,12 @@ static bool sm4_generate_vsir_instr_ld(struct hlsl_ctx *ctx,
VKD3D_ASSERT(load->load_type == HLSL_RESOURCE_LOAD);
if (resource_type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
{
hlsl_fixme(ctx, &load->node.loc, "Structured buffer loads.");
return false;
}
multisampled = resource_type->class == HLSL_CLASS_TEXTURE
&& (resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
|| resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY);