mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/glsl: Implement support for static texel offsets in shader_glsl_sample().
This commit is contained in:
parent
6ae4da02c9
commit
3dbaf11f8c
Notes:
Henri Verbeet
2024-11-06 23:02:41 +01:00
Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1232
@ -763,6 +763,27 @@ static void shader_glsl_default(struct vkd3d_glsl_generator *gen)
|
|||||||
vkd3d_string_buffer_printf(gen->buffer, "default:\n");
|
vkd3d_string_buffer_printf(gen->buffer, "default:\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void shader_glsl_print_texel_offset(struct vkd3d_string_buffer *buffer, struct vkd3d_glsl_generator *gen,
|
||||||
|
unsigned int offset_size, const struct vkd3d_shader_texel_offset *offset)
|
||||||
|
{
|
||||||
|
switch (offset_size)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
vkd3d_string_buffer_printf(buffer, "%d", offset->u);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
vkd3d_string_buffer_printf(buffer, "ivec2(%d, %d)", offset->u, offset->v);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
|
||||||
|
"Internal compiler error: Invalid texel offset size %u.", offset_size);
|
||||||
|
/* fall through */
|
||||||
|
case 3:
|
||||||
|
vkd3d_string_buffer_printf(buffer, "ivec3(%d, %d, %d)", offset->u, offset->v, offset->w);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void shader_glsl_ld(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
|
static void shader_glsl_ld(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
|
||||||
{
|
{
|
||||||
const struct glsl_resource_type_info *resource_type_info;
|
const struct glsl_resource_type_info *resource_type_info;
|
||||||
@ -868,7 +889,7 @@ static void shader_glsl_print_shadow_coord(struct vkd3d_string_buffer *buffer, s
|
|||||||
|
|
||||||
static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
|
static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
|
||||||
{
|
{
|
||||||
bool shadow_sampler, array, bias, gather, grad, lod, lod_zero, offset, shadow;
|
bool shadow_sampler, array, bias, dynamic_offset, gather, grad, lod, lod_zero, offset, shadow;
|
||||||
const struct glsl_resource_type_info *resource_type_info;
|
const struct glsl_resource_type_info *resource_type_info;
|
||||||
const struct vkd3d_shader_src_param *resource, *sampler;
|
const struct vkd3d_shader_src_param *resource, *sampler;
|
||||||
unsigned int resource_id, resource_idx, resource_space;
|
unsigned int resource_id, resource_idx, resource_space;
|
||||||
@ -882,19 +903,16 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
|
|||||||
struct glsl_dst dst;
|
struct glsl_dst dst;
|
||||||
|
|
||||||
bias = ins->opcode == VKD3DSIH_SAMPLE_B;
|
bias = ins->opcode == VKD3DSIH_SAMPLE_B;
|
||||||
|
dynamic_offset = ins->opcode == VKD3DSIH_GATHER4_PO;
|
||||||
gather = ins->opcode == VKD3DSIH_GATHER4 || ins->opcode == VKD3DSIH_GATHER4_PO;
|
gather = ins->opcode == VKD3DSIH_GATHER4 || ins->opcode == VKD3DSIH_GATHER4_PO;
|
||||||
grad = ins->opcode == VKD3DSIH_SAMPLE_GRAD;
|
grad = ins->opcode == VKD3DSIH_SAMPLE_GRAD;
|
||||||
lod = ins->opcode == VKD3DSIH_SAMPLE_LOD || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
|
lod = ins->opcode == VKD3DSIH_SAMPLE_LOD || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
|
||||||
lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
|
lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
|
||||||
offset = ins->opcode == VKD3DSIH_GATHER4_PO;
|
offset = dynamic_offset || vkd3d_shader_instruction_has_texel_offset(ins);
|
||||||
shadow = ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
|
shadow = ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
|
||||||
|
|
||||||
resource = &ins->src[1 + offset];
|
resource = &ins->src[1 + dynamic_offset];
|
||||||
sampler = &ins->src[2 + offset];
|
sampler = &ins->src[2 + dynamic_offset];
|
||||||
|
|
||||||
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 (resource->reg.idx[0].rel_addr || resource->reg.idx[1].rel_addr
|
if (resource->reg.idx[0].rel_addr || resource->reg.idx[1].rel_addr
|
||||||
|| sampler->reg.idx[0].rel_addr || sampler->reg.idx[1].rel_addr)
|
|| sampler->reg.idx[0].rel_addr || sampler->reg.idx[1].rel_addr)
|
||||||
@ -963,13 +981,14 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
|
|||||||
sample = vkd3d_string_buffer_get(&gen->string_buffers);
|
sample = vkd3d_string_buffer_get(&gen->string_buffers);
|
||||||
|
|
||||||
if (gather)
|
if (gather)
|
||||||
vkd3d_string_buffer_printf(sample, "textureGather%s(", offset ? "Offset" : "");
|
vkd3d_string_buffer_printf(sample, "textureGather");
|
||||||
else if (grad)
|
else if (grad)
|
||||||
vkd3d_string_buffer_printf(sample, "textureGrad(");
|
vkd3d_string_buffer_printf(sample, "textureGrad");
|
||||||
else if (lod)
|
else 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");
|
||||||
|
vkd3d_string_buffer_printf(sample, "%s(", offset ? "Offset" : "");
|
||||||
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 (shadow)
|
if (shadow)
|
||||||
@ -990,7 +1009,7 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
|
|||||||
{
|
{
|
||||||
vkd3d_string_buffer_printf(sample, ", 0.0");
|
vkd3d_string_buffer_printf(sample, ", 0.0");
|
||||||
}
|
}
|
||||||
else if (bias || lod)
|
else if (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);
|
||||||
@ -998,10 +1017,18 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
|
|||||||
if (offset)
|
if (offset)
|
||||||
{
|
{
|
||||||
vkd3d_string_buffer_printf(sample, ", ");
|
vkd3d_string_buffer_printf(sample, ", ");
|
||||||
shader_glsl_print_src(sample, gen, &ins->src[1],
|
if (dynamic_offset)
|
||||||
vkd3d_write_mask_from_component_count(coord_size - array), ins->src[1].reg.data_type);
|
shader_glsl_print_src(sample, gen, &ins->src[1],
|
||||||
|
vkd3d_write_mask_from_component_count(coord_size - array), ins->src[1].reg.data_type);
|
||||||
|
else
|
||||||
|
shader_glsl_print_texel_offset(sample, gen, coord_size - array, &ins->texel_offset);
|
||||||
}
|
}
|
||||||
if (gather)
|
if (bias)
|
||||||
|
{
|
||||||
|
vkd3d_string_buffer_printf(sample, ", ");
|
||||||
|
shader_glsl_print_src(sample, gen, &ins->src[3], VKD3DSP_WRITEMASK_0, ins->src[3].reg.data_type);
|
||||||
|
}
|
||||||
|
else if (gather)
|
||||||
{
|
{
|
||||||
if ((component_idx = vsir_swizzle_get_component(sampler->swizzle, 0)))
|
if ((component_idx = vsir_swizzle_get_component(sampler->swizzle, 0)))
|
||||||
vkd3d_string_buffer_printf(sample, ", %d", component_idx);
|
vkd3d_string_buffer_printf(sample, ", %d", component_idx);
|
||||||
|
@ -23,7 +23,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.1, 0.2, 0.2, 0.1)
|
probe (0, 0) rgba (0.1, 0.2, 0.2, 0.1)
|
||||||
|
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.0, 0.1, 0.1, 0.0)
|
probe (0, 0) rgba (0.0, 0.1, 0.1, 0.0)
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.2, 0.2, 0.1, 0.1)
|
probe (0, 0) rgba (0.2, 0.2, 0.1, 0.1)
|
||||||
|
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.1, 0.1, 0.0, 0.0)
|
probe (0, 0) rgba (0.1, 0.1, 0.0, 0.0)
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.5, 0.0, 0.5, 0.0)
|
probe (0, 0) rgba (0.5, 0.0, 0.5, 0.0)
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.0, 0.4, 0.0, 0.4)
|
probe (0, 0) rgba (0.0, 0.4, 0.0, 0.4)
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.1, 0.2, 0.5, 0.0)
|
probe (0, 0) rgba (0.1, 0.2, 0.5, 0.0)
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.2, 0.2, 0.0, 0.4)
|
probe (0, 0) rgba (0.2, 0.2, 0.0, 0.4)
|
||||||
|
|
||||||
|
|
||||||
@ -50,5 +50,5 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo(glsl | msl) draw quad
|
todo(msl) draw quad
|
||||||
probe (0, 0) rgba (0.0, 0.2, 0.0, 0.4)
|
probe (0, 0) rgba (0.0, 0.2, 0.0, 0.4)
|
||||||
|
Loading…
Reference in New Issue
Block a user