wined3d: Correctly handle modifiers on instructions with multiple destination registers.

Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Matteo Bruni 2021-03-05 17:06:22 +01:00 committed by Alexandre Julliard
parent d49cbc7f14
commit 65b3279bae
1 changed files with 57 additions and 51 deletions

View File

@ -2541,9 +2541,9 @@ static void shader_generate_glsl_declarations(const struct wined3d_context_gl *c
shader_addline(buffer, "vec4 tmp0;\n");
shader_addline(buffer, "vec4 tmp1;\n");
if (gl_info->supported[ARB_GPU_SHADER5])
shader_addline(buffer, "precise vec4 tmp_precise;\n");
shader_addline(buffer, "precise vec4 tmp_precise[2];\n");
else
shader_addline(buffer, "/* precise */ vec4 tmp_precise;\n");
shader_addline(buffer, "/* precise */ vec4 tmp_precise[2];\n");
if (!shader->load_local_constsF)
{
@ -3270,7 +3270,7 @@ static DWORD shader_glsl_add_dst_param(const struct wined3d_shader_instruction *
/* Append the destination part of the instruction to the buffer, return the effective write mask */
static DWORD shader_glsl_append_dst_ext(struct wined3d_string_buffer *buffer,
const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *dst,
enum wined3d_data_type data_type)
unsigned int dst_idx, enum wined3d_data_type data_type)
{
struct glsl_dst_param glsl_dst;
DWORD mask;
@ -3278,7 +3278,7 @@ static DWORD shader_glsl_append_dst_ext(struct wined3d_string_buffer *buffer,
if ((mask = shader_glsl_add_dst_param(ins, dst, &glsl_dst)))
{
if (ins->flags & WINED3DSI_PRECISE_XYZW)
sprintf(glsl_dst.reg_name, "tmp_precise");
sprintf(glsl_dst.reg_name, "tmp_precise[%u]", dst_idx);
switch (data_type)
{
@ -3312,44 +3312,50 @@ static DWORD shader_glsl_append_dst_ext(struct wined3d_string_buffer *buffer,
/* Append the destination part of the instruction to the buffer, return the effective write mask */
static DWORD shader_glsl_append_dst(struct wined3d_string_buffer *buffer, const struct wined3d_shader_instruction *ins)
{
return shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], ins->dst[0].reg.data_type);
return shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, ins->dst[0].reg.data_type);
}
/** Process GLSL instruction modifiers */
static void shader_glsl_add_instruction_modifiers(const struct wined3d_shader_instruction *ins)
{
const struct wined3d_shader_dst_param *dst;
struct glsl_dst_param dst_param;
DWORD modifiers;
unsigned int i;
if (!ins->dst_count) return;
if (ins->flags & WINED3DSI_PRECISE_XYZW)
for (i = 0; i < ins->dst_count; ++i)
{
shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
shader_addline(ins->ctx->buffer, "%s%s = tmp_precise%s;\n",
dst_param.reg_name, dst_param.mask_str, dst_param.mask_str);
}
if ((dst = &ins->dst[i])->reg.type == WINED3DSPR_NULL)
continue;
modifiers = ins->dst[0].modifiers;
if (!modifiers) return;
if (ins->flags & WINED3DSI_PRECISE_XYZW)
{
shader_glsl_add_dst_param(ins, dst, &dst_param);
shader_addline(ins->ctx->buffer, "%s%s = tmp_precise[%u]%s;\n",
dst_param.reg_name, dst_param.mask_str, i, dst_param.mask_str);
}
shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
if (!(modifiers = dst->modifiers))
continue;
if (modifiers & WINED3DSPDM_SATURATE)
{
/* _SAT means to clamp the value of the register to between 0 and 1 */
shader_addline(ins->ctx->buffer, "%s%s = clamp(%s%s, 0.0, 1.0);\n", dst_param.reg_name,
dst_param.mask_str, dst_param.reg_name, dst_param.mask_str);
}
shader_glsl_add_dst_param(ins, dst, &dst_param);
if (modifiers & WINED3DSPDM_MSAMPCENTROID)
{
FIXME("_centroid modifier not handled\n");
}
if (modifiers & WINED3DSPDM_SATURATE)
{
/* _SAT means to clamp the value of the register to between 0 and 1 */
shader_addline(ins->ctx->buffer, "%s%s = clamp(%s%s, 0.0, 1.0);\n", dst_param.reg_name,
dst_param.mask_str, dst_param.reg_name, dst_param.mask_str);
}
if (modifiers & WINED3DSPDM_PARTIALPRECISION)
{
/* MSDN says this modifier can be safely ignored, so that's what we'll do. */
if (modifiers & WINED3DSPDM_MSAMPCENTROID)
{
FIXME("_centroid modifier not handled\n");
}
if (modifiers & WINED3DSPDM_PARTIALPRECISION)
{
/* MSDN says this modifier can be safely ignored, so that's what we'll do. */
}
}
}
@ -3606,7 +3612,7 @@ static void PRINTF_ATTR(9, 10) shader_glsl_gen_sample_code(const struct wined3d_
fixup = COLOR_FIXUP_IDENTITY;
}
shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], sample_function->data_type);
shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], 0, sample_function->data_type);
if (sample_function->output_single_component)
shader_addline(ins->ctx->buffer, "vec4(");
@ -3837,7 +3843,7 @@ static void shader_glsl_mul_extended(const struct wined3d_shader_instruction *in
if (ins->dst[1].reg.type != WINED3DSPR_NULL)
{
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], ins->dst[1].reg.data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
@ -3864,17 +3870,17 @@ static void shader_glsl_udiv(const struct wined3d_shader_instruction *ins)
shader_addline(buffer, "tmp0%s = uintBitsToFloat(%s / %s);\n",
dst_mask, src0_param.param_str, src1_param.param_str);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], ins->dst[1].reg.data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
shader_addline(buffer, "%s %% %s);\n", src0_param.param_str, src1_param.param_str);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], WINED3D_DATA_FLOAT);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, WINED3D_DATA_FLOAT);
shader_addline(buffer, "tmp0%s);\n", dst_mask);
}
else
{
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], ins->dst[0].reg.data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, ins->dst[0].reg.data_type);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
shader_addline(buffer, "%s / %s);\n", src0_param.param_str, src1_param.param_str);
@ -3882,7 +3888,7 @@ static void shader_glsl_udiv(const struct wined3d_shader_instruction *ins)
}
else if (ins->dst[1].reg.type != WINED3DSPR_NULL)
{
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], ins->dst[1].reg.data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
shader_addline(buffer, "%s %% %s);\n", src0_param.param_str, src1_param.param_str);
@ -4106,7 +4112,7 @@ static void shader_glsl_float16(const struct wined3d_shader_instruction *ins)
{
dst.write_mask = ins->dst[0].write_mask & (WINED3DSP_WRITEMASK_0 << i);
if (!(write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins,
&dst, dst.reg.data_type)))
&dst, 0, dst.reg.data_type)))
continue;
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src);
@ -4149,7 +4155,7 @@ static void shader_glsl_bitwise_op(const struct wined3d_shader_instruction *ins)
if (tmp_dst && (write_mask = shader_glsl_get_write_mask(&dst, mask_char)))
shader_addline(buffer, "tmp0%s = %sBitsToFloat(", mask_char,
dst.reg.data_type == WINED3D_DATA_INT ? "int" : "uint");
else if (!(write_mask = shader_glsl_append_dst_ext(buffer, ins, &dst, dst.reg.data_type)))
else if (!(write_mask = shader_glsl_append_dst_ext(buffer, ins, &dst, 0, dst.reg.data_type)))
continue;
for (j = 0; j < ins->src_count; ++j)
@ -4162,7 +4168,7 @@ static void shader_glsl_bitwise_op(const struct wined3d_shader_instruction *ins)
if (tmp_dst)
{
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], WINED3D_DATA_FLOAT);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, WINED3D_DATA_FLOAT);
shader_glsl_get_write_mask(&ins->dst[0], mask_char);
shader_addline(buffer, "tmp0%s);\n", mask_char);
}
@ -4395,7 +4401,7 @@ static void shader_glsl_swapc(const struct wined3d_shader_instruction *ins)
dst[j].write_mask = ins->dst[j].write_mask & (WINED3DSP_WRITEMASK_0 << i);
if (tmp_dst[j] && (write_mask = shader_glsl_get_write_mask(&dst[j], mask_char)))
shader_addline(buffer, "tmp%u%s = (", j, mask_char);
else if (!(write_mask = shader_glsl_append_dst_ext(buffer, ins, &dst[j], dst[j].reg.data_type)))
else if (!(write_mask = shader_glsl_append_dst_ext(buffer, ins, &dst[j], j, dst[j].reg.data_type)))
continue;
for (k = 0; k < ARRAY_SIZE(src); ++k)
@ -4411,7 +4417,7 @@ static void shader_glsl_swapc(const struct wined3d_shader_instruction *ins)
if (tmp_dst[i])
{
shader_glsl_get_write_mask(&ins->dst[i], mask_char);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[i], ins->dst[i].reg.data_type);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[i], i, ins->dst[i].reg.data_type);
shader_addline(buffer, "tmp%u%s);\n", i, mask_char);
}
}
@ -4501,7 +4507,7 @@ static void shader_glsl_conditional_move(const struct wined3d_shader_instruction
continue;
shader_addline(ins->ctx->buffer, "tmp0%s = (", mask_char);
}
else if (!(write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst, dst.reg.data_type)))
else if (!(write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst, 0, dst.reg.data_type)))
continue;
shader_glsl_add_src_param(ins, &ins->src[0], cmp_channel, &src0_param);
@ -4779,23 +4785,23 @@ static void shader_glsl_sincos(const struct wined3d_shader_instruction *ins)
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_addline(buffer, "tmp0%s = sin(%s);\n", dst_mask, src0_param.param_str);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], ins->dst[1].reg.data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_addline(buffer, "cos(%s));\n", src0_param.param_str);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], ins->dst[0].reg.data_type);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, ins->dst[0].reg.data_type);
shader_addline(buffer, "tmp0%s);\n", dst_mask);
}
else
{
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], ins->dst[0].reg.data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, ins->dst[0].reg.data_type);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_addline(buffer, "sin(%s));\n", src0_param.param_str);
}
}
else if (ins->dst[1].reg.type != WINED3DSPR_NULL)
{
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], ins->dst[1].reg.data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
shader_addline(buffer, "cos(%s));\n", src0_param.param_str);
}
@ -5461,7 +5467,7 @@ static void shader_glsl_atomic(const struct wined3d_shader_instruction *ins)
}
if (is_imm_instruction)
shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], data_type);
shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], 0, data_type);
if (is_tgsm)
shader_addline(buffer, "%s(%s_%s%u[%s], ",
@ -5525,7 +5531,7 @@ static void shader_glsl_ld_uav(const struct wined3d_shader_instruction *ins)
data_type = reg_maps->uav_resource_info[uav_idx].data_type;
coord_mask = (1u << resource_type_info[resource_type].coord_size) - 1;
write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], data_type);
write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], 0, data_type);
shader_glsl_get_swizzle(&ins->src[1], FALSE, write_mask, dst_swizzle);
shader_glsl_add_src_param(ins, &ins->src[0], coord_mask, &image_coord_param);
@ -5605,7 +5611,7 @@ static void shader_glsl_ld_raw_structured(const struct wined3d_shader_instructio
for (i = 0; i < 4; ++i)
{
dst.write_mask = ins->dst[0].write_mask & (WINED3DSP_WRITEMASK_0 << i);
if (!shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst, dst.reg.data_type))
if (!shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst, 0, dst.reg.data_type))
continue;
swizzle = shader_glsl_swizzle_get_component(src->swizzle, i);
@ -5856,7 +5862,7 @@ static void shader_glsl_resinfo(const struct wined3d_shader_instruction *ins)
return;
}
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], dst_data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, dst_data_type);
shader_glsl_get_swizzle(&ins->src[1], FALSE, write_mask, dst_swizzle);
if (dst_data_type == WINED3D_DATA_UINT)
@ -5924,7 +5930,7 @@ static void shader_glsl_sample_info(const struct wined3d_shader_instruction *ins
else if (ins->flags)
FIXME("Unhandled flags %#x.\n", ins->flags);
write_mask = shader_glsl_append_dst_ext(buffer, ins, dst, dst_data_type);
write_mask = shader_glsl_append_dst_ext(buffer, ins, dst, 0, dst_data_type);
shader_glsl_get_swizzle(src, FALSE, write_mask, dst_swizzle);
if (dst_data_type == WINED3D_DATA_UINT)
@ -6093,7 +6099,7 @@ static void shader_glsl_gen_sample_c_lz_emulation(const struct wined3d_shader_in
WARN("Emitting textureGrad() for sample_c_lz.\n");
shader_glsl_swizzle_to_str(WINED3DSP_NOSWIZZLE, FALSE, ins->dst[0].write_mask, dst_swizzle);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], sample_function->data_type);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, sample_function->data_type);
shader_addline(buffer, "vec4(textureGrad%s(%s_sampler%u, vec%u(%s, %s), vec%u(0.0), vec%u(0.0)",
sample_function->offset_size ? "Offset" : "",
shader_glsl_get_prefix(version->type), sampler_bind_idx,
@ -6197,7 +6203,7 @@ static void shader_glsl_gather4(const struct wined3d_shader_instruction *ins)
shader_glsl_get_coord_size(resource_info->type, &coord_size, &offset_size);
shader_glsl_swizzle_to_str(ins->src[resource_param_idx].swizzle, FALSE, ins->dst[0].write_mask, dst_swizzle);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], resource_info->data_type);
shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, resource_info->data_type);
shader_glsl_add_src_param(ins, &ins->src[0], (1u << coord_size) - 1, &coord_param);