[PATCH vkd3d 1/8] vkd3d-shader: Read the resource index from idx[1] instead of idx[0] when looking up SM5.1 bindings.
Zebediah Figura
zfigura at codeweavers.com
Fri May 22 15:25:36 CDT 2020
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
We still use the first index to uniquely identify the register in vkd3d_symbol,
only changing which field is used to declare it.
One alternative to the "resource_idx" field of struct vkd3d_shader_register
could be to store that long with "register_space", and pass it as an extra
parameter to vkd3d_dxbc_compiler_get_descriptor_binding().
More generally, there may be something to be said for exposing fields with
specific meaning from vkd3d_shader_register, instead of a flat array idx[3], so
as to hide the differences between SM5 and SM5.1 from spirv.c. If an SM1-3
frontend is added as well, this may be an even greater help (mostly considering
constant buffers.) In that case, resource_idx could become one such field.
This patch does not handle descriptor arrays.
libs/vkd3d-shader/dxbc.c | 15 +++++++++++++++
libs/vkd3d-shader/spirv.c | 6 +++---
libs/vkd3d-shader/vkd3d_shader_private.h | 1 +
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c
index 5e504dc..6d0d995 100644
--- a/libs/vkd3d-shader/dxbc.c
+++ b/libs/vkd3d-shader/dxbc.c
@@ -582,6 +582,14 @@ static void shader_sm4_read_shader_data(struct vkd3d_shader_instruction *ins,
ins->declaration.icb = &priv->icb;
}
+static void shader_sm4_map_resource_idx(struct vkd3d_shader_register *reg, const struct vkd3d_sm4_data *priv)
+{
+ if (shader_is_sm_5_1(priv))
+ reg->u.resource_idx = reg->idx[1].offset;
+ else
+ reg->u.resource_idx = reg->idx[0].offset;
+}
+
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)
@@ -604,6 +612,7 @@ static void shader_sm4_read_dcl_resource(struct vkd3d_shader_instruction *ins,
}
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);
+ shader_sm4_map_resource_idx(&ins->declaration.semantic.reg.reg, priv);
components = *tokens++;
if ((components & 0xfff0) != (components & 0xf) * 0x1110)
@@ -633,6 +642,7 @@ static void shader_sm4_read_dcl_constant_buffer(struct vkd3d_shader_instruction
const DWORD *end = &tokens[token_count];
shader_sm4_read_src_param(priv, &tokens, end, VKD3D_DATA_FLOAT, &ins->declaration.cb.src);
+ shader_sm4_map_resource_idx(&ins->declaration.cb.src.reg, priv);
if (opcode_token & VKD3D_SM4_INDEX_TYPE_MASK)
ins->flags |= VKD3DSI_INDEXED_DYNAMIC;
@@ -662,6 +672,7 @@ static void shader_sm4_read_dcl_sampler(struct vkd3d_shader_instruction *ins,
if (ins->flags & ~VKD3D_SM4_SAMPLER_COMPARISON)
FIXME("Unhandled sampler mode %#x.\n", ins->flags);
shader_sm4_read_src_param(priv, &tokens, end, VKD3D_DATA_SAMPLER, &ins->declaration.sampler.src);
+ shader_sm4_map_resource_idx(&ins->declaration.sampler.src.reg, priv);
shader_sm4_read_register_space(priv, &tokens, end, &ins->declaration.sampler.register_space);
}
@@ -861,6 +872,7 @@ static void shader_sm5_read_dcl_uav_raw(struct vkd3d_shader_instruction *ins,
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &ins->declaration.raw_resource.dst);
+ shader_sm4_map_resource_idx(&ins->declaration.raw_resource.dst.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);
}
@@ -872,6 +884,7 @@ static void shader_sm5_read_dcl_uav_structured(struct vkd3d_shader_instruction *
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_UAV, &ins->declaration.structured_resource.reg);
+ shader_sm4_map_resource_idx(&ins->declaration.structured_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)
@@ -908,6 +921,7 @@ static void shader_sm5_read_dcl_resource_structured(struct vkd3d_shader_instruct
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &ins->declaration.structured_resource.reg);
+ 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);
@@ -921,6 +935,7 @@ static void shader_sm5_read_dcl_resource_raw(struct vkd3d_shader_instruction *in
const DWORD *end = &tokens[token_count];
shader_sm4_read_dst_param(priv, &tokens, end, VKD3D_DATA_RESOURCE, &ins->declaration.dst);
+ shader_sm4_map_resource_idx(&ins->declaration.dst.reg, priv);
shader_sm4_read_register_space(priv, &tokens, end, &ins->declaration.raw_resource.register_space);
}
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c
index ba21113..a8b2a50 100644
--- a/libs/vkd3d-shader/spirv.c
+++ b/libs/vkd3d-shader/spirv.c
@@ -2233,7 +2233,7 @@ static bool vkd3d_dxbc_compiler_check_shader_visibility(const struct vkd3d_dxbc_
static struct vkd3d_push_constant_buffer_binding *vkd3d_dxbc_compiler_find_push_constant_buffer(
const struct vkd3d_dxbc_compiler *compiler, const struct vkd3d_shader_register *reg)
{
- unsigned int reg_idx = reg->idx[0].offset;
+ unsigned int reg_idx = reg->u.resource_idx;
unsigned int i;
for (i = 0; i < compiler->shader_interface.push_constant_buffer_count; ++i)
@@ -2280,13 +2280,13 @@ static bool vkd3d_dxbc_compiler_has_combined_sampler(const struct vkd3d_dxbc_com
static struct vkd3d_shader_descriptor_binding vkd3d_dxbc_compiler_get_descriptor_binding(
struct vkd3d_dxbc_compiler *compiler, const struct vkd3d_shader_register *reg,
- enum vkd3d_shader_resource_type resource_type, bool is_uav_counter)
+ unsigned int register_space, enum vkd3d_shader_resource_type resource_type, bool is_uav_counter)
{
const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface;
enum vkd3d_shader_descriptor_type descriptor_type;
enum vkd3d_shader_binding_flag resource_type_flag;
struct vkd3d_shader_descriptor_binding binding;
- unsigned int reg_idx = reg->idx[0].offset;
+ unsigned int reg_idx = reg->u.resource_idx;
unsigned int i;
descriptor_type = VKD3D_SHADER_DESCRIPTOR_TYPE_UNKNOWN;
diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h
index 100d515..9157a5a 100644
--- a/libs/vkd3d-shader/vkd3d_shader_private.h
+++ b/libs/vkd3d-shader/vkd3d_shader_private.h
@@ -565,6 +565,7 @@ struct vkd3d_shader_register
DWORD immconst_uint[VKD3D_VEC4_SIZE];
float immconst_float[VKD3D_VEC4_SIZE];
unsigned fp_body_idx;
+ unsigned int resource_idx;
} u;
};
--
2.26.2
More information about the wine-devel
mailing list