mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/glsl: Implement VKD3DSIH_SAMPLE.
This commit is contained in:
parent
eb10f0897e
commit
cf6a3ad676
Notes:
Henri Verbeet
2024-10-03 19:35:31 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1143
@ -727,6 +727,87 @@ static void shader_glsl_ld(struct vkd3d_glsl_generator *gen, const struct vkd3d_
|
||||
glsl_dst_cleanup(&dst, &gen->string_buffers);
|
||||
}
|
||||
|
||||
static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
|
||||
{
|
||||
const struct glsl_resource_type_info *resource_type_info;
|
||||
unsigned int resource_id, resource_idx, resource_space;
|
||||
unsigned int sampler_id, sampler_idx, sampler_space;
|
||||
const struct vkd3d_shader_descriptor_info1 *d;
|
||||
enum vkd3d_shader_component_type sampled_type;
|
||||
enum vkd3d_shader_resource_type resource_type;
|
||||
struct vkd3d_string_buffer *sample;
|
||||
enum vkd3d_data_type data_type;
|
||||
struct glsl_src coord;
|
||||
struct glsl_dst dst;
|
||||
uint32_t coord_mask;
|
||||
|
||||
if (vkd3d_shader_instruction_has_texel_offset(ins))
|
||||
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
|
||||
"Internal compiler error: Unhandled texel sample offset.");
|
||||
|
||||
if (ins->src[1].reg.idx[0].rel_addr || ins->src[1].reg.idx[1].rel_addr
|
||||
|| ins->src[2].reg.idx[0].rel_addr || ins->src[2].reg.idx[1].rel_addr)
|
||||
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_UNSUPPORTED,
|
||||
"Descriptor indexing is not supported.");
|
||||
|
||||
resource_id = ins->src[1].reg.idx[0].offset;
|
||||
resource_idx = ins->src[1].reg.idx[1].offset;
|
||||
if ((d = shader_glsl_get_descriptor_by_id(gen, VKD3D_SHADER_DESCRIPTOR_TYPE_SRV, resource_id)))
|
||||
{
|
||||
resource_type = d->resource_type;
|
||||
resource_space = d->register_space;
|
||||
sampled_type = vkd3d_component_type_from_resource_data_type(d->resource_data_type);
|
||||
data_type = vkd3d_data_type_from_component_type(sampled_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
|
||||
"Internal compiler error: Undeclared resource descriptor %u.", resource_id);
|
||||
resource_space = 0;
|
||||
resource_type = VKD3D_SHADER_RESOURCE_TEXTURE_2D;
|
||||
data_type = VKD3D_DATA_FLOAT;
|
||||
}
|
||||
|
||||
if ((resource_type_info = shader_glsl_get_resource_type_info(resource_type)))
|
||||
{
|
||||
coord_mask = vkd3d_write_mask_from_component_count(resource_type_info->coord_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
|
||||
"Internal compiler error: Unhandled resource type %#x.", resource_type);
|
||||
coord_mask = vkd3d_write_mask_from_component_count(2);
|
||||
}
|
||||
|
||||
sampler_id = ins->src[2].reg.idx[0].offset;
|
||||
sampler_idx = ins->src[2].reg.idx[1].offset;
|
||||
if ((d = shader_glsl_get_descriptor_by_id(gen, VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, sampler_id)))
|
||||
{
|
||||
sampler_space = d->register_space;
|
||||
}
|
||||
else
|
||||
{
|
||||
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
|
||||
"Internal compiler error: Undeclared sampler descriptor %u.", sampler_id);
|
||||
sampler_space = 0;
|
||||
}
|
||||
|
||||
glsl_dst_init(&dst, gen, ins, &ins->dst[0]);
|
||||
glsl_src_init(&coord, gen, &ins->src[0], coord_mask);
|
||||
sample = vkd3d_string_buffer_get(&gen->string_buffers);
|
||||
|
||||
vkd3d_string_buffer_printf(sample, "texture(");
|
||||
shader_glsl_print_combined_sampler_name(sample, gen, resource_idx, resource_space, sampler_idx, sampler_space);
|
||||
vkd3d_string_buffer_printf(sample, ", %s)", coord.str->buffer);
|
||||
shader_glsl_print_swizzle(sample, ins->src[1].swizzle, ins->dst[0].write_mask);
|
||||
|
||||
shader_glsl_print_assignment_ext(gen, &dst, data_type, "%s", sample->buffer);
|
||||
|
||||
vkd3d_string_buffer_release(&gen->string_buffers, sample);
|
||||
glsl_src_cleanup(&coord, &gen->string_buffers);
|
||||
glsl_dst_cleanup(&dst, &gen->string_buffers);
|
||||
}
|
||||
|
||||
static void shader_glsl_unary_op(struct vkd3d_glsl_generator *gen,
|
||||
const struct vkd3d_shader_instruction *ins, const char *op)
|
||||
{
|
||||
@ -1054,6 +1135,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
|
||||
case VKD3DSIH_RSQ:
|
||||
shader_glsl_intrinsic(gen, ins, "inversesqrt");
|
||||
break;
|
||||
case VKD3DSIH_SAMPLE:
|
||||
shader_glsl_sample(gen, ins);
|
||||
break;
|
||||
case VKD3DSIH_SQRT:
|
||||
shader_glsl_intrinsic(gen, ins, "sqrt");
|
||||
break;
|
||||
|
@ -577,7 +577,7 @@ float4 main() : sv_target
|
||||
uniform 0 float4 1.0 0.0 0.0 0.0
|
||||
uniform 4 float4 0.0 2.0 0.0 0.0
|
||||
uniform 8 float4 0.0 0.0 3.0 0.0
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (1.0, 2.0, 0.0, 4.0)
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (0, 0, 0, 1)
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ float4 main() : sv_target
|
||||
|
||||
[test]
|
||||
uniform 0 float4 0.5 0.0 0.0 0.0
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (0.5, 0.5, 0.5, 1.5)
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
if(sm<4) todo probe (0, 0) rgba (1, 1, 1, 11)
|
||||
if(sm>=4) probe (0, 0) rgba (10, 10, 10, 11)
|
||||
|
||||
@ -92,7 +92,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
if(sm<4) todo probe (0, 0) rgba (1, 1, 1, 11)
|
||||
if(sm>=4) probe (0, 0) rgba (10, 10, 10, 11)
|
||||
|
||||
@ -107,7 +107,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (21, 21, 21, 11)
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
if(sm<4) probe (0, 0) rgba (102, 102, 102, 111)
|
||||
if(sm>=4) probe (0, 0) rgba (12, 12, 12, 111)
|
||||
|
||||
@ -139,7 +139,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (104, 104, 104, 111)
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (1, 1, 1, 11)
|
||||
|
||||
|
||||
|
@ -243,10 +243,10 @@ float4 main() : sv_target
|
||||
|
||||
[test]
|
||||
uniform 0 float -2
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (0.0, 0.0, 0.0, 4.0)
|
||||
uniform 0 float 4
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
|
||||
|
||||
|
||||
@ -267,11 +267,11 @@ float4 main() : sv_target
|
||||
|
||||
[test]
|
||||
uniform 0 float 2
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (0.0, 0.0, 0.0, 4.0)
|
||||
uniform 0 float 1
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (1.0, 0.0, 0.0, 4.0)
|
||||
uniform 0 float 0
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (1.0, 1.0, 0.0, 4.0)
|
||||
|
@ -46,7 +46,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (77.77, 77.77, 77.77, 77.77)
|
||||
|
||||
|
||||
|
@ -527,7 +527,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
if(sm<6) probe (0, 0) rgba(2.0, 2.0, 2.0, 2.0)
|
||||
if(sm>=6) probe (0, 0) rgba(0.5, 0.5, 0.5, 0.5)
|
||||
|
||||
|
@ -17,7 +17,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (0.25, 0, 0.25, 0)
|
||||
|
||||
[pixel shader todo(sm<4)]
|
||||
@ -30,7 +30,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (0.25, 0, 0.25, 0)
|
||||
|
||||
[pixel shader fail]
|
||||
|
@ -67,7 +67,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (3.0, 4.0, -1.0, -1.0)
|
||||
|
||||
|
||||
|
@ -147,7 +147,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (1, 2, 3, 4)
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(sm<4 | glsl) draw quad
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) rgba (1, 2, 3, 4)
|
||||
|
||||
|
||||
|
@ -136,7 +136,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (450, 139, 876, 333)
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (450, 138, 796, 333)
|
||||
|
||||
|
||||
@ -242,7 +242,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (478, 913, 256, 333)
|
||||
|
||||
|
||||
@ -275,7 +275,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (215, 215, 215, 111)
|
||||
|
||||
|
||||
@ -305,5 +305,5 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(glsl) draw quad
|
||||
draw quad
|
||||
probe (0, 0) rgba (5, 4, 2, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user