vkd3d-shader/glsl: Implement VKD3DSIH_SAMPLE_LOD.

This commit is contained in:
Henri Verbeet 2024-10-18 20:45:57 +02:00
parent 85697d76be
commit d58282c6d1
Notes: Henri Verbeet 2024-10-24 21:02:25 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1211
2 changed files with 24 additions and 18 deletions

View File

@ -865,6 +865,7 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
const struct glsl_resource_type_info *resource_type_info; const struct glsl_resource_type_info *resource_type_info;
unsigned int resource_id, resource_idx, resource_space; unsigned int resource_id, resource_idx, resource_space;
unsigned int sampler_id, sampler_idx, sampler_space; unsigned int sampler_id, sampler_idx, sampler_space;
bool shadow_sampler, bias, lod, lod_zero, shadow;
const struct vkd3d_shader_descriptor_info1 *d; const struct vkd3d_shader_descriptor_info1 *d;
enum vkd3d_shader_component_type sampled_type; enum vkd3d_shader_component_type sampled_type;
enum vkd3d_shader_resource_type resource_type; enum vkd3d_shader_resource_type resource_type;
@ -872,7 +873,11 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
enum vkd3d_data_type data_type; enum vkd3d_data_type data_type;
unsigned int coord_size; unsigned int coord_size;
struct glsl_dst dst; struct glsl_dst dst;
bool shadow;
bias = ins->opcode == VKD3DSIH_SAMPLE_B;
lod = ins->opcode == VKD3DSIH_SAMPLE_LOD || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
shadow = ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
if (vkd3d_shader_instruction_has_texel_offset(ins)) if (vkd3d_shader_instruction_has_texel_offset(ins))
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
@ -917,17 +922,17 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
if ((d = shader_glsl_get_descriptor_by_id(gen, VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, sampler_id))) if ((d = shader_glsl_get_descriptor_by_id(gen, VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, sampler_id)))
{ {
sampler_space = d->register_space; sampler_space = d->register_space;
shadow = d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_SAMPLER_COMPARISON_MODE; shadow_sampler = d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_SAMPLER_COMPARISON_MODE;
if (ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ) if (shadow)
{ {
if (!shadow) if (!shadow_sampler)
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
"Internal compiler error: Sampler %u is not a comparison sampler.", sampler_id); "Internal compiler error: Sampler %u is not a comparison sampler.", sampler_id);
} }
else else
{ {
if (shadow) if (shadow_sampler)
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
"Internal compiler error: Sampler %u is a comparison sampler.", sampler_id); "Internal compiler error: Sampler %u is a comparison sampler.", sampler_id);
} }
@ -942,26 +947,26 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
glsl_dst_init(&dst, gen, ins, &ins->dst[0]); glsl_dst_init(&dst, gen, ins, &ins->dst[0]);
sample = vkd3d_string_buffer_get(&gen->string_buffers); sample = vkd3d_string_buffer_get(&gen->string_buffers);
if (ins->opcode == VKD3DSIH_SAMPLE_C_LZ) if (lod)
vkd3d_string_buffer_printf(sample, "textureLod("); vkd3d_string_buffer_printf(sample, "textureLod(");
else else
vkd3d_string_buffer_printf(sample, "texture("); vkd3d_string_buffer_printf(sample, "texture(");
shader_glsl_print_combined_sampler_name(sample, gen, resource_idx, resource_space, sampler_idx, sampler_space); shader_glsl_print_combined_sampler_name(sample, gen, resource_idx, resource_space, sampler_idx, sampler_space);
vkd3d_string_buffer_printf(sample, ", "); vkd3d_string_buffer_printf(sample, ", ");
if (ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ) if (shadow)
shader_glsl_print_shadow_coord(sample, gen, &ins->src[0], &ins->src[3], coord_size); shader_glsl_print_shadow_coord(sample, gen, &ins->src[0], &ins->src[3], coord_size);
else else
shader_glsl_print_src(sample, gen, &ins->src[0], shader_glsl_print_src(sample, gen, &ins->src[0],
vkd3d_write_mask_from_component_count(coord_size), ins->src[0].reg.data_type); vkd3d_write_mask_from_component_count(coord_size), ins->src[0].reg.data_type);
if (ins->opcode == VKD3DSIH_SAMPLE_B) if (lod_zero)
{
vkd3d_string_buffer_printf(sample, ", 0.0");
}
else if (bias || lod)
{ {
vkd3d_string_buffer_printf(sample, ", "); vkd3d_string_buffer_printf(sample, ", ");
shader_glsl_print_src(sample, gen, &ins->src[3], VKD3DSP_WRITEMASK_0, ins->src[3].reg.data_type); shader_glsl_print_src(sample, gen, &ins->src[3], VKD3DSP_WRITEMASK_0, ins->src[3].reg.data_type);
} }
else if (ins->opcode == VKD3DSIH_SAMPLE_C_LZ)
{
vkd3d_string_buffer_printf(sample, ", 0.0");
}
vkd3d_string_buffer_printf(sample, ")"); vkd3d_string_buffer_printf(sample, ")");
shader_glsl_print_swizzle(sample, ins->src[1].swizzle, ins->dst[0].write_mask); shader_glsl_print_swizzle(sample, ins->src[1].swizzle, ins->dst[0].write_mask);
@ -1559,6 +1564,7 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
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_LOD:
shader_glsl_sample(gen, ins); shader_glsl_sample(gen, ins);
break; break;
case VKD3DSIH_SQRT: case VKD3DSIH_SQRT:

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(sm<4 | glsl) draw quad todo(sm<4) 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 0.5 0.0 0.0 0.0 uniform 0 float4 0.5 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad todo(sm<4) draw quad
probe (0, 0) rgba (0.5, 0.0, 1.0, 0.0) probe (0, 0) rgba (0.5, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 0.0 0.0 0.0 uniform 0 float4 1.0 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad todo(sm<4) 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]
@ -50,11 +50,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(sm<4 | glsl) draw quad todo(sm<4) 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 0.5 0.0 0.0 0.0 uniform 0 float4 0.5 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad todo(sm<4) draw quad
probe (0, 0) rgba (0.5, 0.0, 1.0, 0.0) probe (0, 0) rgba (0.5, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 0.0 0.0 0.0 uniform 0 float4 1.0 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad todo(sm<4) 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)