vkd3d-shader/msl: Implement VKD3DSIH_SAMPLE_GRAD.

This commit is contained in:
Henri Verbeet
2025-05-26 10:12:51 +02:00
parent db89687807
commit 46265061c3
Notes: Henri Verbeet 2025-06-23 20:18:16 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1565
2 changed files with 30 additions and 19 deletions

View File

@@ -61,8 +61,8 @@ struct msl_resource_type_info
bool array; bool array;
/* Whether the resource type has a shadow/comparison variant. */ /* Whether the resource type has a shadow/comparison variant. */
bool comparison; bool comparison;
/* The type suffix for the resource type. I.e., the "2d" part of /* The type suffix for the resource type. I.e., the "2d_ms" part of
* "texture2d" or "depth2d". */ * "texture2d_ms_array" or "depth2d_ms_array". */
const char *type_suffix; const char *type_suffix;
}; };
@@ -91,10 +91,10 @@ static const struct msl_resource_type_info *msl_get_resource_type_info(enum vkd3
[VKD3D_SHADER_RESOURCE_TEXTURE_2DMS] = {2, 0, 1, "2d_ms"}, [VKD3D_SHADER_RESOURCE_TEXTURE_2DMS] = {2, 0, 1, "2d_ms"},
[VKD3D_SHADER_RESOURCE_TEXTURE_3D] = {3, 0, 0, "3d"}, [VKD3D_SHADER_RESOURCE_TEXTURE_3D] = {3, 0, 0, "3d"},
[VKD3D_SHADER_RESOURCE_TEXTURE_CUBE] = {3, 0, 1, "cube"}, [VKD3D_SHADER_RESOURCE_TEXTURE_CUBE] = {3, 0, 1, "cube"},
[VKD3D_SHADER_RESOURCE_TEXTURE_1DARRAY] = {1, 1, 0, "1d_array"}, [VKD3D_SHADER_RESOURCE_TEXTURE_1DARRAY] = {1, 1, 0, "1d"},
[VKD3D_SHADER_RESOURCE_TEXTURE_2DARRAY] = {2, 1, 1, "2d_array"}, [VKD3D_SHADER_RESOURCE_TEXTURE_2DARRAY] = {2, 1, 1, "2d"},
[VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY] = {2, 1, 1, "2d_ms_array"}, [VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY] = {2, 1, 1, "2d_ms"},
[VKD3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY] = {3, 1, 1, "cube_array"}, [VKD3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY] = {3, 1, 1, "cube"},
}; };
if (!t || t >= ARRAY_SIZE(info)) if (!t || t >= ARRAY_SIZE(info))
@@ -310,8 +310,9 @@ static void msl_print_sampler_name(struct vkd3d_string_buffer *buffer, unsigned
static void msl_print_srv_name(struct vkd3d_string_buffer *buffer, struct msl_generator *gen, unsigned int binding, static void msl_print_srv_name(struct vkd3d_string_buffer *buffer, struct msl_generator *gen, unsigned int binding,
const struct msl_resource_type_info *resource_type_info, enum vkd3d_data_type resource_data_type, bool compare) const struct msl_resource_type_info *resource_type_info, enum vkd3d_data_type resource_data_type, bool compare)
{ {
vkd3d_string_buffer_printf(buffer, "descriptors[%u].as<%s%s<", vkd3d_string_buffer_printf(buffer, "descriptors[%u].as<%s%s%s<",
binding, compare ? "depth" : "texture", resource_type_info->type_suffix); binding, compare ? "depth" : "texture", resource_type_info->type_suffix,
resource_type_info->array ? "_array" : "");
msl_print_resource_datatype(gen, buffer, resource_data_type); msl_print_resource_datatype(gen, buffer, resource_data_type);
vkd3d_string_buffer_printf(buffer, ">>()"); vkd3d_string_buffer_printf(buffer, ">>()");
} }
@@ -964,9 +965,9 @@ static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_inst
{ {
const struct msl_resource_type_info *resource_type_info; const struct msl_resource_type_info *resource_type_info;
unsigned int resource_id, resource_idx, resource_space; unsigned int resource_id, resource_idx, resource_space;
bool bias, compare, comparison_sampler, grad, lod_zero;
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;
bool bias, compare, comparison_sampler, lod_zero;
const struct vkd3d_shader_descriptor_info1 *d; const struct vkd3d_shader_descriptor_info1 *d;
enum vkd3d_shader_resource_type resource_type; enum vkd3d_shader_resource_type resource_type;
unsigned int srv_binding, sampler_binding; unsigned int srv_binding, sampler_binding;
@@ -977,6 +978,7 @@ 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_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ; compare = ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
grad = ins->opcode == VKD3DSIH_SAMPLE_GRAD;
lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ; lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
if (vkd3d_shader_instruction_has_texel_offset(ins)) if (vkd3d_shader_instruction_has_texel_offset(ins))
@@ -1013,7 +1015,7 @@ static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_inst
"Sampling resource type %#x is not supported.", resource_type); "Sampling resource type %#x is not supported.", resource_type);
if ((resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_1D || resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_1DARRAY) if ((resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_1D || resource_type == VKD3D_SHADER_RESOURCE_TEXTURE_1DARRAY)
&& (bias || lod_zero)) && (bias || grad || lod_zero))
msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_UNSUPPORTED, msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_UNSUPPORTED,
"Resource type %#x does not support mipmapping.", resource_type); "Resource type %#x does not support mipmapping.", resource_type);
@@ -1104,6 +1106,14 @@ static void msl_sample(struct msl_generator *gen, const struct vkd3d_shader_inst
vkd3d_string_buffer_printf(sample, ", "); vkd3d_string_buffer_printf(sample, ", ");
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);
} }
if (grad)
{
vkd3d_string_buffer_printf(sample, ", gradient%s(", resource_type_info->type_suffix);
msl_print_src_with_type(sample, gen, &ins->src[3], coord_mask, ins->src[3].reg.data_type);
vkd3d_string_buffer_printf(sample, ", ");
msl_print_src_with_type(sample, gen, &ins->src[4], coord_mask, ins->src[4].reg.data_type);
vkd3d_string_buffer_printf(sample, ")");
}
if (lod_zero) if (lod_zero)
{ {
vkd3d_string_buffer_printf(sample, ", level(0.0f)"); vkd3d_string_buffer_printf(sample, ", level(0.0f)");
@@ -1296,6 +1306,7 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d
case VKD3DSIH_SAMPLE_B: case VKD3DSIH_SAMPLE_B:
case VKD3DSIH_SAMPLE_C: case VKD3DSIH_SAMPLE_C:
case VKD3DSIH_SAMPLE_C_LZ: case VKD3DSIH_SAMPLE_C_LZ:
case VKD3DSIH_SAMPLE_GRAD:
msl_sample(gen, ins); msl_sample(gen, ins);
break; break;
case VKD3DSIH_GEO: case VKD3DSIH_GEO:

View File

@@ -26,13 +26,13 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 0.0 0.0 0.0 0.0 uniform 0 float4 0.0 0.0 0.0 0.0
todo(msl) draw quad draw quad
probe (0,0) rgba (1.0, 0.0, 1.0, 0.0) probe (0,0) rgba (1.0, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 1.0 1.0 1.0 uniform 0 float4 1.0 1.0 1.0 1.0
todo(msl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
uniform 0 float4 2.0 2.0 2.0 2.0 uniform 0 float4 2.0 2.0 2.0 2.0
todo(msl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
[pixel shader fail(sm>=5.1) todo(sm>=5.1)] [pixel shader fail(sm>=5.1) todo(sm>=5.1)]
@@ -46,13 +46,13 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 0.0 0.0 0.0 0.0 uniform 0 float4 0.0 0.0 0.0 0.0
todo(msl) draw quad draw quad
probe (0,0) rgba (1.0, 0.0, 1.0, 0.0) probe (0,0) rgba (1.0, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 1.0 1.0 1.0 uniform 0 float4 1.0 1.0 1.0 1.0
todo(msl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
uniform 0 float4 2.0 2.0 2.0 2.0 uniform 0 float4 2.0 2.0 2.0 2.0
todo(msl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
[require] [require]
@@ -70,11 +70,11 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 0.0 0.0 0.0 0.0 uniform 0 float4 0.0 0.0 0.0 0.0
todo(msl) draw quad draw quad
probe (0, 0) rgba (1.0, 0.0, 1.0, 0.0) probe (0, 0) rgba (1.0, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 1.0 1.0 1.0 uniform 0 float4 1.0 1.0 1.0 1.0
todo(msl) draw quad draw quad
probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0) probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0)
uniform 0 float4 2.0 2.0 2.0 2.0 uniform 0 float4 2.0 2.0 2.0 2.0
todo(msl) draw quad draw quad
probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0) probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0)