vkd3d-shader: Introduce struct vkd3d_shader_resource.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2020-06-30 15:02:03 +04:30 committed by Alexandre Julliard
parent b7fb3a033b
commit 11980c3944
5 changed files with 92 additions and 106 deletions

View File

@ -594,6 +594,7 @@ static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins,
DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
struct vkd3d_sm4_data *priv)
{
struct vkd3d_shader_semantic *semantic = &ins->declaration.semantic;
enum vkd3d_sm4_resource_type resource_type;
const DWORD *end = &tokens[token_count];
enum vkd3d_sm4_data_type data_type;
@ -604,15 +605,15 @@ static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins,
if (!resource_type || (resource_type >= ARRAY_SIZE(resource_type_table)))
{
FIXME("Unhandled resource type %#x.\n", resource_type);
ins->declaration.semantic.resource_type = VKD3D_SHADER_RESOURCE_NONE;
semantic->resource_type = VKD3D_SHADER_RESOURCE_NONE;
}
else
{
ins->declaration.semantic.resource_type = resource_type_table[resource_type];
semantic->resource_type = resource_type_table[resource_type];
}
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, &ins->declaration.semantic.reg);
ins->declaration.semantic.register_index = shader_sm4_map_resource_idx(&ins->declaration.semantic.reg.reg, priv);
shader_sm4_read_dst_param(priv, &tokens, end, reg_data_type, &semantic->resource.reg);
semantic->resource.register_index = shader_sm4_map_resource_idx(&semantic->resource.reg.reg, priv);
components = *tokens++;
if ((components & 0xfff0) != (components & 0xf) * 0x1110)
@ -622,17 +623,17 @@ static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins,
if (!data_type || (data_type >= ARRAY_SIZE(data_type_table)))
{
FIXME("Unhandled data type %#x.\n", data_type);
ins->declaration.semantic.resource_data_type = VKD3D_DATA_FLOAT;
semantic->resource_data_type = VKD3D_DATA_FLOAT;
}
else
{
ins->declaration.semantic.resource_data_type = data_type_table[data_type];
semantic->resource_data_type = data_type_table[data_type];
}
if (reg_data_type == VKD3D_DATA_UAV)
ins->flags = (opcode_token & VKD3D_SM5_UAV_FLAGS_MASK) >> VKD3D_SM5_UAV_FLAGS_SHIFT;
shader_sm4_read_register_space(priv, &tokens, end, &ins->declaration.semantic.register_space);
shader_sm4_read_register_space(priv, &tokens, end, &semantic->resource.register_space);
}
static void shader_sm4_read_dcl_constant_buffer(struct vkd3d_shader_instruction *ins,
@ -869,29 +870,29 @@ static void shader_sm5_read_dcl_uav_raw(struct vkd3d_shader_instruction *ins,
DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
struct vkd3d_sm4_data *priv)
{
struct vkd3d_shader_raw_resource *resource = &ins->declaration.raw_resource;
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &ins->declaration.raw_resource.dst);
ins->declaration.raw_resource.register_index = shader_sm4_map_resource_idx(
&ins->declaration.raw_resource.dst.reg, priv);
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &resource->resource.reg);
resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv);
ins->flags = (opcode_token & VKD3D_SM5_UAV_FLAGS_MASK) >> VKD3D_SM5_UAV_FLAGS_SHIFT;
shader_sm4_read_register_space(priv, &tokens, end, &ins->declaration.raw_resource.register_space);
shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space);
}
static void shader_sm5_read_dcl_uav_structured(struct vkd3d_shader_instruction *ins,
DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
struct vkd3d_sm4_data *priv)
{
struct vkd3d_shader_structured_resource *resource = &ins->declaration.structured_resource;
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &ins->declaration.structured_resource.reg);
ins->declaration.structured_resource.register_index = shader_sm4_map_resource_idx(
&ins->declaration.structured_resource.reg.reg, priv);
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &resource->resource.reg);
resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv);
ins->flags = (opcode_token & VKD3D_SM5_UAV_FLAGS_MASK) >> VKD3D_SM5_UAV_FLAGS_SHIFT;
ins->declaration.structured_resource.byte_stride = *tokens++;
if (ins->declaration.structured_resource.byte_stride % 4)
FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.structured_resource.byte_stride);
shader_sm4_read_register_space(priv, &tokens, end, &ins->declaration.structured_resource.register_space);
resource->byte_stride = *tokens++;
if (resource->byte_stride % 4)
FIXME("Byte stride %u is not multiple of 4.\n", resource->byte_stride);
shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space);
}
static void shader_sm5_read_dcl_tgsm_raw(struct vkd3d_shader_instruction *ins,
@ -920,26 +921,27 @@ static void shader_sm5_read_dcl_resource_structured(struct vkd3d_shader_instruct
DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
struct vkd3d_sm4_data *priv)
{
struct vkd3d_shader_structured_resource *resource = &ins->declaration.structured_resource;
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &ins->declaration.structured_resource.reg);
ins->declaration.structured_resource.register_index = shader_sm4_map_resource_idx(
&ins->declaration.structured_resource.reg.reg, priv);
ins->declaration.structured_resource.byte_stride = *tokens++;
if (ins->declaration.structured_resource.byte_stride % 4)
FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.structured_resource.byte_stride);
shader_sm4_read_register_space(priv, &tokens, end, &ins->declaration.structured_resource.register_space);
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &resource->resource.reg);
resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv);
resource->byte_stride = *tokens++;
if (resource->byte_stride % 4)
FIXME("Byte stride %u is not multiple of 4.\n", resource->byte_stride);
shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space);
}
static void shader_sm5_read_dcl_resource_raw(struct vkd3d_shader_instruction *ins,
DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
struct vkd3d_sm4_data *priv)
{
struct vkd3d_shader_raw_resource *resource = &ins->declaration.raw_resource;
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &ins->declaration.dst);
ins->declaration.raw_resource.register_index = shader_sm4_map_resource_idx(&ins->declaration.dst.reg, priv);
shader_sm4_read_register_space(priv, &tokens, end, &ins->declaration.raw_resource.register_space);
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &resource->resource.reg);
resource->resource.register_index = shader_sm4_map_resource_idx(&resource->resource.reg.reg, priv);
shader_sm4_read_register_space(priv, &tokens, end, &resource->resource.register_space);
}
static void shader_sm5_read_sync(struct vkd3d_shader_instruction *ins,

View File

@ -5280,14 +5280,16 @@ static void vkd3d_dxbc_compiler_emit_combined_sampler_declarations(struct vkd3d_
}
static void vkd3d_dxbc_compiler_emit_resource_declaration(struct vkd3d_dxbc_compiler *compiler,
const struct vkd3d_shader_register *reg, unsigned int register_space, unsigned int register_index,
enum vkd3d_shader_resource_type resource_type, enum vkd3d_data_type resource_data_type,
unsigned int structure_stride, bool raw)
const struct vkd3d_shader_resource *resource, enum vkd3d_shader_resource_type resource_type,
enum vkd3d_data_type resource_data_type, unsigned int structure_stride, bool raw)
{
uint32_t counter_type_id, type_id, ptr_type_id, var_id, counter_var_id = 0;
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
SpvStorageClass storage_class = SpvStorageClassUniformConstant;
const struct vkd3d_shader_register *reg = &resource->reg.reg;
const struct vkd3d_spirv_resource_type *resource_type_info;
unsigned int register_space = resource->register_space;
unsigned int register_index = resource->register_index;
enum vkd3d_component_type sampled_type;
struct vkd3d_symbol resource_symbol;
bool is_uav;
@ -5373,8 +5375,8 @@ static void vkd3d_dxbc_compiler_emit_dcl_resource(struct vkd3d_dxbc_compiler *co
if (instruction->flags)
FIXME("Unhandled UAV flags %#x.\n", instruction->flags);
vkd3d_dxbc_compiler_emit_resource_declaration(compiler, &semantic->reg.reg, semantic->register_space,
semantic->register_index, semantic->resource_type, semantic->resource_data_type, 0, false);
vkd3d_dxbc_compiler_emit_resource_declaration(compiler, &semantic->resource,
semantic->resource_type, semantic->resource_data_type, 0, false);
}
static void vkd3d_dxbc_compiler_emit_dcl_resource_raw(struct vkd3d_dxbc_compiler *compiler,
@ -5385,22 +5387,21 @@ static void vkd3d_dxbc_compiler_emit_dcl_resource_raw(struct vkd3d_dxbc_compiler
if (instruction->flags)
FIXME("Unhandled UAV flags %#x.\n", instruction->flags);
vkd3d_dxbc_compiler_emit_resource_declaration(compiler, &resource->dst.reg, resource->register_space,
resource->register_index, VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_DATA_UINT, 0, true);
vkd3d_dxbc_compiler_emit_resource_declaration(compiler, &resource->resource,
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_DATA_UINT, 0, true);
}
static void vkd3d_dxbc_compiler_emit_dcl_resource_structured(struct vkd3d_dxbc_compiler *compiler,
const struct vkd3d_shader_instruction *instruction)
{
const struct vkd3d_shader_structured_resource *resource = &instruction->declaration.structured_resource;
const struct vkd3d_shader_register *reg = &resource->reg.reg;
unsigned int stride = resource->byte_stride;
if (instruction->flags)
FIXME("Unhandled UAV flags %#x.\n", instruction->flags);
vkd3d_dxbc_compiler_emit_resource_declaration(compiler, reg, resource->register_space,
resource->register_index, VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_DATA_UINT, stride / 4, false);
vkd3d_dxbc_compiler_emit_resource_declaration(compiler, &resource->resource,
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_DATA_UINT, stride / 4, false);
}
static void vkd3d_dxbc_compiler_emit_workgroup_memory(struct vkd3d_dxbc_compiler *compiler,

View File

@ -569,7 +569,7 @@ static void shader_dump_decl_usage(struct vkd3d_string_buffer *buffer,
{
shader_addline(buffer, "dcl");
if (semantic->reg.reg.type == VKD3DSPR_SAMPLER)
if (semantic->resource.reg.reg.type == VKD3DSPR_SAMPLER)
{
switch (semantic->resource_type)
{
@ -590,9 +590,9 @@ static void shader_dump_decl_usage(struct vkd3d_string_buffer *buffer,
break;
}
}
else if (semantic->reg.reg.type == VKD3DSPR_RESOURCE || semantic->reg.reg.type == VKD3DSPR_UAV)
else if (semantic->resource.reg.reg.type == VKD3DSPR_RESOURCE || semantic->resource.reg.reg.type == VKD3DSPR_UAV)
{
if (semantic->reg.reg.type == VKD3DSPR_RESOURCE)
if (semantic->resource.reg.reg.type == VKD3DSPR_RESOURCE)
shader_addline(buffer, "_resource_");
else
shader_addline(buffer, "_uav_");
@ -642,7 +642,7 @@ static void shader_dump_decl_usage(struct vkd3d_string_buffer *buffer,
shader_addline(buffer, "unknown");
break;
}
if (semantic->reg.reg.type == VKD3DSPR_UAV)
if (semantic->resource.reg.reg.type == VKD3DSPR_UAV)
shader_dump_uav_flags(buffer, flags);
switch (semantic->resource_data_type)
{
@ -1361,10 +1361,10 @@ static void shader_dump_instruction(struct vkd3d_string_buffer *buffer,
case VKD3DSIH_DCL:
case VKD3DSIH_DCL_UAV_TYPED:
shader_dump_decl_usage(buffer, &ins->declaration.semantic, ins->flags, shader_version);
shader_dump_ins_modifiers(buffer, &ins->declaration.semantic.reg);
shader_dump_ins_modifiers(buffer, &ins->declaration.semantic.resource.reg);
shader_addline(buffer, " ");
shader_dump_dst_param(buffer, &ins->declaration.semantic.reg, shader_version);
shader_dump_register_space(buffer, ins->declaration.semantic.register_space, shader_version);
shader_dump_dst_param(buffer, &ins->declaration.semantic.resource.reg, shader_version);
shader_dump_register_space(buffer, ins->declaration.semantic.resource.register_space, shader_version);
break;
case VKD3DSIH_DCL_CONSTANT_BUFFER:
@ -1469,15 +1469,16 @@ static void shader_dump_instruction(struct vkd3d_string_buffer *buffer,
case VKD3DSIH_DCL_RESOURCE_RAW:
shader_addline(buffer, "%s ", shader_opcode_names[ins->handler_idx]);
shader_dump_dst_param(buffer, &ins->declaration.raw_resource.dst, shader_version);
shader_dump_register_space(buffer, ins->declaration.raw_resource.register_space, shader_version);
shader_dump_dst_param(buffer, &ins->declaration.raw_resource.resource.reg, shader_version);
shader_dump_register_space(buffer, ins->declaration.raw_resource.resource.register_space, shader_version);
break;
case VKD3DSIH_DCL_RESOURCE_STRUCTURED:
shader_addline(buffer, "%s ", shader_opcode_names[ins->handler_idx]);
shader_dump_dst_param(buffer, &ins->declaration.structured_resource.reg, shader_version);
shader_dump_dst_param(buffer, &ins->declaration.structured_resource.resource.reg, shader_version);
shader_addline(buffer, ", %u", ins->declaration.structured_resource.byte_stride);
shader_dump_register_space(buffer, ins->declaration.structured_resource.register_space, shader_version);
shader_dump_register_space(buffer,
ins->declaration.structured_resource.resource.register_space, shader_version);
break;
case VKD3DSIH_DCL_SAMPLER:
@ -1537,17 +1538,18 @@ static void shader_dump_instruction(struct vkd3d_string_buffer *buffer,
shader_addline(buffer, "%s", shader_opcode_names[ins->handler_idx]);
shader_dump_uav_flags(buffer, ins->flags);
shader_addline(buffer, " ");
shader_dump_dst_param(buffer, &ins->declaration.raw_resource.dst, shader_version);
shader_dump_register_space(buffer, ins->declaration.raw_resource.register_space, shader_version);
shader_dump_dst_param(buffer, &ins->declaration.raw_resource.resource.reg, shader_version);
shader_dump_register_space(buffer, ins->declaration.raw_resource.resource.register_space, shader_version);
break;
case VKD3DSIH_DCL_UAV_STRUCTURED:
shader_addline(buffer, "%s", shader_opcode_names[ins->handler_idx]);
shader_dump_uav_flags(buffer, ins->flags);
shader_addline(buffer, " ");
shader_dump_dst_param(buffer, &ins->declaration.structured_resource.reg, shader_version);
shader_dump_dst_param(buffer, &ins->declaration.structured_resource.resource.reg, shader_version);
shader_addline(buffer, ", %u", ins->declaration.structured_resource.byte_stride);
shader_dump_register_space(buffer, ins->declaration.structured_resource.register_space, shader_version);
shader_dump_register_space(buffer,
ins->declaration.structured_resource.resource.register_space, shader_version);
break;
case VKD3DSIH_DEF:

View File

@ -320,16 +320,28 @@ static void vkd3d_shader_scan_sampler_declaration(struct vkd3d_shader_scan_conte
}
static void vkd3d_shader_scan_resource_declaration(struct vkd3d_shader_scan_context *context,
const struct vkd3d_shader_resource *resource, enum vkd3d_shader_resource_type resource_type,
enum vkd3d_shader_resource_data_type resource_data_type)
{
enum vkd3d_shader_descriptor_type type;
if (resource->reg.reg.type == VKD3DSPR_UAV)
type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV;
else
type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV;
vkd3d_shader_scan_add_descriptor(context, type, resource->register_space,
resource->register_index, resource_type, resource_data_type, 0);
if (type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV)
vkd3d_shader_scan_add_uav_range(context, resource->reg.reg.idx[0].offset,
context->scan_info->descriptor_count - 1);
}
static void vkd3d_shader_scan_typed_resource_declaration(struct vkd3d_shader_scan_context *context,
const struct vkd3d_shader_instruction *instruction)
{
const struct vkd3d_shader_semantic *semantic = &instruction->declaration.semantic;
enum vkd3d_shader_resource_data_type resource_data_type;
enum vkd3d_shader_descriptor_type type;
if (semantic->reg.reg.type == VKD3DSPR_UAV)
type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV;
else
type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV;
switch (semantic->resource_data_type)
{
case VKD3D_DATA_UNORM:
@ -352,45 +364,8 @@ static void vkd3d_shader_scan_resource_declaration(struct vkd3d_shader_scan_cont
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_FLOAT;
break;
}
vkd3d_shader_scan_add_descriptor(context, type, semantic->register_space,
semantic->register_index, semantic->resource_type, resource_data_type, 0);
if (type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV)
vkd3d_shader_scan_add_uav_range(context, semantic->reg.reg.idx[0].offset,
context->scan_info->descriptor_count - 1);
}
static void vkd3d_shader_scan_resource_declaration_raw(struct vkd3d_shader_scan_context *context,
const struct vkd3d_shader_instruction *instruction)
{
const struct vkd3d_shader_raw_resource *resource = &instruction->declaration.raw_resource;
enum vkd3d_shader_descriptor_type type;
if (resource->dst.reg.type == VKD3DSPR_UAV)
type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV;
else
type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV;
vkd3d_shader_scan_add_descriptor(context, type, resource->register_space,
resource->register_index, VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT, 0);
if (type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV)
vkd3d_shader_scan_add_uav_range(context, resource->dst.reg.idx[0].offset,
context->scan_info->descriptor_count - 1);
}
static void vkd3d_shader_scan_resource_declaration_structured(struct vkd3d_shader_scan_context *context,
const struct vkd3d_shader_instruction *instruction)
{
const struct vkd3d_shader_structured_resource *resource = &instruction->declaration.structured_resource;
enum vkd3d_shader_descriptor_type type;
if (resource->reg.reg.type == VKD3DSPR_UAV)
type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV;
else
type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV;
vkd3d_shader_scan_add_descriptor(context, type, resource->register_space,
resource->register_index, VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT, 0);
if (type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV)
vkd3d_shader_scan_add_uav_range(context, resource->reg.reg.idx[0].offset,
context->scan_info->descriptor_count - 1);
vkd3d_shader_scan_resource_declaration(context, &semantic->resource,
semantic->resource_type, resource_data_type);
}
static void vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *context,
@ -408,15 +383,17 @@ static void vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *cont
break;
case VKD3DSIH_DCL:
case VKD3DSIH_DCL_UAV_TYPED:
vkd3d_shader_scan_resource_declaration(context, instruction);
vkd3d_shader_scan_typed_resource_declaration(context, instruction);
break;
case VKD3DSIH_DCL_RESOURCE_RAW:
case VKD3DSIH_DCL_UAV_RAW:
vkd3d_shader_scan_resource_declaration_raw(context, instruction);
vkd3d_shader_scan_resource_declaration(context, &instruction->declaration.raw_resource.resource,
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT);
break;
case VKD3DSIH_DCL_RESOURCE_STRUCTURED:
case VKD3DSIH_DCL_UAV_STRUCTURED:
vkd3d_shader_scan_resource_declaration_structured(context, instruction);
vkd3d_shader_scan_resource_declaration(context, &instruction->declaration.structured_resource.resource,
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT);
break;
default:
break;

View File

@ -574,6 +574,13 @@ struct vkd3d_shader_index_range
unsigned int register_count;
};
struct vkd3d_shader_resource
{
struct vkd3d_shader_dst_param reg;
unsigned int register_space;
unsigned int register_index;
};
enum vkd3d_decl_usage
{
VKD3D_DECL_USAGE_POSITION = 0,
@ -598,8 +605,7 @@ struct vkd3d_shader_semantic
unsigned int usage_idx;
enum vkd3d_shader_resource_type resource_type;
enum vkd3d_data_type resource_data_type;
struct vkd3d_shader_dst_param reg;
unsigned int register_space, register_index;
struct vkd3d_shader_resource resource;
};
enum vkd3d_shader_input_sysval_semantic
@ -659,15 +665,13 @@ struct vkd3d_shader_constant_buffer
struct vkd3d_shader_structured_resource
{
struct vkd3d_shader_dst_param reg;
struct vkd3d_shader_resource resource;
unsigned int byte_stride;
unsigned int register_space, register_index;
};
struct vkd3d_shader_raw_resource
{
struct vkd3d_shader_dst_param dst;
unsigned int register_space, register_index;
struct vkd3d_shader_resource resource;
};
struct vkd3d_shader_tgsm