vkd3d-shader/msl: Implement VKD3DSIH_GATHER4_PO.

This commit is contained in:
Henri Verbeet
2025-05-27 23:42:48 +02:00
parent 449804623a
commit 6f8ce6df72
Notes: Henri Verbeet 2025-06-24 16:32:54 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1593
2 changed files with 27 additions and 12 deletions

View File

@@ -965,8 +965,9 @@ static void msl_ld(struct msl_generator *gen, const struct vkd3d_shader_instruct
static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_instruction *ins) static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_instruction *ins)
{ {
bool bias, compare, comparison_sampler, gather, grad, lod, lod_zero; bool bias, compare, comparison_sampler, gather, grad, lod, lod_zero, offset;
const struct msl_resource_type_info *resource_type_info; const struct msl_resource_type_info *resource_type_info;
const struct vkd3d_shader_src_param *resource, *sampler;
unsigned int resource_id, resource_idx, resource_space; unsigned int resource_id, resource_idx, resource_space;
const struct vkd3d_shader_descriptor_binding *binding; const struct vkd3d_shader_descriptor_binding *binding;
unsigned int sampler_id, sampler_idx, sampler_space; unsigned int sampler_id, sampler_idx, sampler_space;
@@ -982,22 +983,27 @@ static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_inst
bias = ins->opcode == VKD3DSIH_SAMPLE_B; bias = ins->opcode == VKD3DSIH_SAMPLE_B;
compare = ins->opcode == VKD3DSIH_GATHER4_C || ins->opcode == VKD3DSIH_SAMPLE_C compare = ins->opcode == VKD3DSIH_GATHER4_C || ins->opcode == VKD3DSIH_SAMPLE_C
|| ins->opcode == VKD3DSIH_SAMPLE_C_LZ; || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
gather = ins->opcode == VKD3DSIH_GATHER4 || ins->opcode == VKD3DSIH_GATHER4_C; gather = ins->opcode == VKD3DSIH_GATHER4 || ins->opcode == VKD3DSIH_GATHER4_C
|| ins->opcode == VKD3DSIH_GATHER4_PO;
grad = ins->opcode == VKD3DSIH_SAMPLE_GRAD; grad = ins->opcode == VKD3DSIH_SAMPLE_GRAD;
lod = ins->opcode == VKD3DSIH_SAMPLE_LOD; lod = ins->opcode == VKD3DSIH_SAMPLE_LOD;
lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ; lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
offset = ins->opcode == VKD3DSIH_GATHER4_PO;
resource = &ins->src[1 + offset];
sampler = &ins->src[2 + offset];
if (vkd3d_shader_instruction_has_texel_offset(ins)) if (vkd3d_shader_instruction_has_texel_offset(ins))
msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_INTERNAL, msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_INTERNAL,
"Internal compiler error: Unhandled texel sample offset."); "Internal compiler error: Unhandled texel sample offset.");
if (ins->src[1].reg.idx[0].rel_addr || ins->src[1].reg.idx[1].rel_addr if (resource->reg.idx[0].rel_addr || resource->reg.idx[1].rel_addr
|| ins->src[2].reg.idx[0].rel_addr || ins->src[2].reg.idx[1].rel_addr) || sampler->reg.idx[0].rel_addr || sampler->reg.idx[1].rel_addr)
msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_UNSUPPORTED, msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_UNSUPPORTED,
"Descriptor indexing is not supported."); "Descriptor indexing is not supported.");
resource_id = ins->src[1].reg.idx[0].offset; resource_id = resource->reg.idx[0].offset;
resource_idx = ins->src[1].reg.idx[1].offset; resource_idx = resource->reg.idx[1].offset;
if ((d = vkd3d_shader_find_descriptor(&gen->program->descriptors, if ((d = vkd3d_shader_find_descriptor(&gen->program->descriptors,
VKD3D_SHADER_DESCRIPTOR_TYPE_SRV, resource_id))) VKD3D_SHADER_DESCRIPTOR_TYPE_SRV, resource_id)))
{ {
@@ -1050,8 +1056,8 @@ static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_inst
srv_binding = 0; srv_binding = 0;
} }
sampler_id = ins->src[2].reg.idx[0].offset; sampler_id = sampler->reg.idx[0].offset;
sampler_idx = ins->src[2].reg.idx[1].offset; sampler_idx = sampler->reg.idx[1].offset;
if ((d = vkd3d_shader_find_descriptor(&gen->program->descriptors, if ((d = vkd3d_shader_find_descriptor(&gen->program->descriptors,
VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, sampler_id))) VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, sampler_id)))
{ {
@@ -1145,9 +1151,17 @@ static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_inst
msl_print_src_with_type(sample, gen, &ins->src[3], VKD3DSP_WRITEMASK_0, ins->src[3].reg.data_type); msl_print_src_with_type(sample, gen, &ins->src[3], VKD3DSP_WRITEMASK_0, ins->src[3].reg.data_type);
vkd3d_string_buffer_printf(sample, ")"); vkd3d_string_buffer_printf(sample, ")");
} }
if (gather && !compare && (component_idx = vsir_swizzle_get_component(ins->src[2].swizzle, 0))) if (offset)
{ {
if (resource_type_info->offset) if (!resource_type_info->offset)
msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_UNSUPPORTED,
"Texel sample offsets are not supported with resource type %#x.", resource_type);
vkd3d_string_buffer_printf(sample, ", ");
msl_print_src_with_type(sample, gen, &ins->src[1], coord_mask, ins->src[1].reg.data_type);
}
if (gather && !compare && (component_idx = vsir_swizzle_get_component(sampler->swizzle, 0)))
{
if (!offset && resource_type_info->offset)
vkd3d_string_buffer_printf(sample, ", int2(0)"); vkd3d_string_buffer_printf(sample, ", int2(0)");
vkd3d_string_buffer_printf(sample, ", component::%c", "xyzw"[component_idx]); vkd3d_string_buffer_printf(sample, ", component::%c", "xyzw"[component_idx]);
} }
@@ -1155,7 +1169,7 @@ static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_inst
if (ins->dst[0].reg.data_type == VKD3D_DATA_UINT) if (ins->dst[0].reg.data_type == VKD3D_DATA_UINT)
vkd3d_string_buffer_printf(sample, ")"); vkd3d_string_buffer_printf(sample, ")");
if (!compare || gather) if (!compare || gather)
msl_print_swizzle(sample, ins->src[1].swizzle, ins->dst[0].write_mask); msl_print_swizzle(sample, resource->swizzle, ins->dst[0].write_mask);
msl_print_assignment(gen, &dst, "%s", sample->buffer); msl_print_assignment(gen, &dst, "%s", sample->buffer);
@@ -1300,6 +1314,7 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d
break; break;
case VKD3DSIH_GATHER4: case VKD3DSIH_GATHER4:
case VKD3DSIH_GATHER4_C: case VKD3DSIH_GATHER4_C:
case VKD3DSIH_GATHER4_PO:
case VKD3DSIH_SAMPLE: case VKD3DSIH_SAMPLE:
case VKD3DSIH_SAMPLE_B: case VKD3DSIH_SAMPLE_B:
case VKD3DSIH_SAMPLE_C: case VKD3DSIH_SAMPLE_C:

View File

@@ -113,5 +113,5 @@ float4 main() : sv_target
[test] [test]
uniform 0 int4 1 0 0 0 uniform 0 int4 1 0 0 0
todo(msl) draw quad draw quad
bug(d3d12 & mvk) probe (0, 0) rgba (0.1, 0.2, 0.2, 0.1) bug(d3d12 & mvk) probe (0, 0) rgba (0.1, 0.2, 0.2, 0.1)