-- v2: vkd3d-shader/sm4: Write sample count field for multisampled texture declaration. vkd3d-shader/hlsl: Parse multisample texture type names. vkd3d-shader/trace: Output sample count for multisampled resources.
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/dxbc.c | 7 +++++++ libs/vkd3d-shader/sm4.h | 3 +++ libs/vkd3d-shader/trace.c | 6 ++++++ libs/vkd3d-shader/vkd3d_shader_private.h | 1 + 4 files changed, 17 insertions(+)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index d8eef8a5..35f0d066 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -288,6 +288,13 @@ static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins, u { semantic->resource_type = resource_type_table[resource_type]; } + + if (semantic->resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMS + || semantic->resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY) + { + semantic->sample_count = (opcode_token & VKD3D_SM4_RESOURCE_SAMPLE_COUNT_MASK) >> VKD3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT; + } + reg_data_type = opcode == VKD3D_SM4_OP_DCL_RESOURCE ? VKD3D_DATA_RESOURCE : VKD3D_DATA_UAV; shader_sm4_read_dst_param(priv, &tokens, end, reg_data_type, &semantic->resource.reg); shader_sm4_set_descriptor_register_range(priv, &semantic->resource.reg.reg, &semantic->resource.range); diff --git a/libs/vkd3d-shader/sm4.h b/libs/vkd3d-shader/sm4.h index fd388c81..5ec4ee17 100644 --- a/libs/vkd3d-shader/sm4.h +++ b/libs/vkd3d-shader/sm4.h @@ -56,6 +56,9 @@ #define VKD3D_SM4_RESOURCE_TYPE_SHIFT 11 #define VKD3D_SM4_RESOURCE_TYPE_MASK (0xfu << VKD3D_SM4_RESOURCE_TYPE_SHIFT)
+#define VKD3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT 16 +#define VKD3D_SM4_RESOURCE_SAMPLE_COUNT_MASK (0xfu << VKD3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT) + #define VKD3D_SM4_PRIMITIVE_TYPE_SHIFT 11 #define VKD3D_SM4_PRIMITIVE_TYPE_MASK (0x3fu << VKD3D_SM4_PRIMITIVE_TYPE_SHIFT)
diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index f32f26a7..6cd2dcb2 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -663,8 +663,14 @@ static void shader_dump_decl_usage(struct vkd3d_d3d_asm_compiler *compiler, shader_addline(buffer, "_resource_");
shader_dump_resource_type(compiler, semantic->resource_type); + if (semantic->resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMS + || semantic->resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY) + { + shader_addline(buffer, "(%u)", semantic->sample_count); + } if (semantic->resource.reg.reg.type == VKD3DSPR_UAV) shader_dump_uav_flags(compiler, flags); + shader_addline(buffer, " "); shader_dump_data_type(compiler, semantic->resource_data_type); } else diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 78a48e55..13d793b2 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -741,6 +741,7 @@ struct vkd3d_shader_semantic enum vkd3d_decl_usage usage; unsigned int usage_idx; enum vkd3d_shader_resource_type resource_type; + unsigned int sample_count; enum vkd3d_data_type resource_data_type[VKD3D_VEC4_SIZE]; struct vkd3d_shader_resource resource; };
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/hlsl.h | 2 ++ libs/vkd3d-shader/hlsl.y | 55 +++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 24d0f517..e97c2521 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -166,6 +166,8 @@ struct hlsl_type * Otherwise both dimx = 1 and dimy = 1. */ unsigned int dimx; unsigned int dimy; + /* Sample count for HLSL_SAMPLER_DIM_2DMS or HLSL_SAMPLER_DIM_2DMSARRAY. */ + unsigned int sample_count;
union { diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index e011ea24..3d7be51a 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1122,7 +1122,7 @@ static struct list *make_list(struct hlsl_ctx *ctx, struct hlsl_ir_node *node) return list; }
-static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node) +static unsigned int evaluate_static_expression(struct hlsl_ir_node *node) { if (node->data_type->type != HLSL_CLASS_SCALAR) return 0; @@ -3729,6 +3729,21 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl } }
+static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type *format, + const struct vkd3d_shader_location *loc) +{ + if (format->type > HLSL_CLASS_VECTOR) + { + struct vkd3d_string_buffer *string; + + string = hlsl_type_to_string(ctx, format); + if (string) + 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); + } +} + }
%locations @@ -3949,7 +3964,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
%type <reg_reservation> register_opt
-%type <sampler_dim> texture_type uav_type +%type <sampler_dim> texture_type texture_ms_type uav_type
%type <semantic> semantic
@@ -4562,6 +4577,16 @@ texture_type: $$ = HLSL_SAMPLER_DIM_CUBEARRAY; }
+texture_ms_type: + KW_TEXTURE2DMS + { + $$ = HLSL_SAMPLER_DIM_2DMS; + } + | KW_TEXTURE2DMSARRAY + { + $$ = HLSL_SAMPLER_DIM_2DMSARRAY; + } + uav_type: KW_RWTEXTURE1D { @@ -4667,18 +4692,24 @@ type_no_void: } | texture_type '<' type '>' { - if ($3->type > HLSL_CLASS_VECTOR) - { - struct vkd3d_string_buffer *string; + validate_texture_format_type(ctx, $3, &@3); + $$ = hlsl_new_texture_type(ctx, $1, $3); + } + | texture_ms_type '<' type '>' + { + validate_texture_format_type(ctx, $3, &@3);
- string = hlsl_type_to_string(ctx, $3); - if (string) - hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, - "Texture data type %s is not scalar or vector.", string->buffer); - hlsl_release_string_buffer(ctx, string); - } + /* TODO: unspecified sample count is not allowed for all targets */ $$ = hlsl_new_texture_type(ctx, $1, $3); } + | texture_ms_type '<' type ',' shift_expr '>' + { + unsigned int sample_count = evaluate_static_expression(node_from_list($5)); + destroy_instr_list($5); + + if (($$ = hlsl_new_texture_type(ctx, $1, $3))) + $$->sample_count = sample_count; + } | uav_type '<' type '>' { if ($3->type > HLSL_CLASS_VECTOR) @@ -4868,7 +4899,7 @@ arrays: } | '[' expr ']' arrays { - unsigned int size = evaluate_array_dimension(node_from_list($2)); + unsigned int size = evaluate_static_expression(node_from_list($2)); uint32_t *new_array;
destroy_instr_list($2);
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/hlsl_sm4.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 3e1769ac..f81be3e9 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1164,7 +1164,7 @@ static void write_sm4_dcl_sampler(struct vkd3d_bytecode_buffer *buffer, const st static void write_sm4_dcl_texture(struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_var *var) { bool uav = (var->data_type->base_type == HLSL_TYPE_UAV); - const struct sm4_instruction instr = + struct sm4_instruction instr = { .opcode = (uav ? VKD3D_SM5_OP_DCL_UAV_TYPED : VKD3D_SM4_OP_DCL_RESOURCE) | (sm4_resource_dimension(var->data_type) << VKD3D_SM4_RESOURCE_TYPE_SHIFT), @@ -1177,6 +1177,13 @@ static void write_sm4_dcl_texture(struct vkd3d_bytecode_buffer *buffer, const st .idx[0] = sm4_resource_format(var->data_type) * 0x1111, .idx_count = 1, }; + + if (var->data_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS + || var->data_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY) + { + instr.opcode |= var->data_type->sample_count << VKD3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT; + } + write_sm4_instruction(buffer, &instr); }
Zebediah Figura (@zfigura) commented about libs/vkd3d-shader/hlsl.y:
string = hlsl_type_to_string(ctx, $3);
if (string)
hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Texture data type %s is not scalar or vector.", string->buffer);
hlsl_release_string_buffer(ctx, string);
}
/* TODO: unspecified sample count is not allowed for all targets */ $$ = hlsl_new_texture_type(ctx, $1, $3); }
- | texture_ms_type '<' type ',' shift_expr '>'
{
unsigned int sample_count = evaluate_static_expression(node_from_list($5));
destroy_instr_list($5);
if (($$ = hlsl_new_texture_type(ctx, $1, $3)))
$$->sample_count = sample_count;
This works, but I'd rather make the sample count an extra argument to hlsl_new_texture_type().