mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/ir: Lower tpf SINCOS to the new COS and SIN instructions.
This commit is contained in:
committed by
Henri Verbeet
parent
37c2f709d1
commit
93e1a8c784
Notes:
Henri Verbeet
2025-06-19 20:51:53 +02:00
Approved-by: Elizabeth Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1557
@@ -606,14 +606,20 @@ static void src_param_init_ssa_float(struct vkd3d_shader_src_param *src, unsigne
|
||||
src_param_init_ssa_scalar(src, idx, VKD3D_DATA_FLOAT);
|
||||
}
|
||||
|
||||
static void src_param_init_ssa_float4(struct vkd3d_shader_src_param *src, unsigned int idx)
|
||||
static void src_param_init_ssa_vec4(struct vkd3d_shader_src_param *src, unsigned int idx,
|
||||
enum vkd3d_data_type data_type)
|
||||
{
|
||||
vsir_src_param_init(src, VKD3DSPR_SSA, VKD3D_DATA_FLOAT, 1);
|
||||
vsir_src_param_init(src, VKD3DSPR_SSA, data_type, 1);
|
||||
src->reg.idx[0].offset = idx;
|
||||
src->reg.dimension = VSIR_DIMENSION_VEC4;
|
||||
src->swizzle = VKD3D_SHADER_NO_SWIZZLE;
|
||||
}
|
||||
|
||||
static void src_param_init_ssa_float4(struct vkd3d_shader_src_param *src, unsigned int idx)
|
||||
{
|
||||
src_param_init_ssa_vec4(src, idx, VKD3D_DATA_FLOAT);
|
||||
}
|
||||
|
||||
static void src_param_init_temp_bool(struct vkd3d_shader_src_param *src, unsigned int idx)
|
||||
{
|
||||
vsir_src_param_init(src, VKD3DSPR_TEMP, VKD3D_DATA_BOOL, 1);
|
||||
@@ -681,14 +687,20 @@ static void dst_param_init_ssa_float(struct vkd3d_shader_dst_param *dst, unsigne
|
||||
dst_param_init_ssa_scalar(dst, idx, VKD3D_DATA_FLOAT);
|
||||
}
|
||||
|
||||
static void dst_param_init_ssa_float4(struct vkd3d_shader_dst_param *dst, unsigned int idx)
|
||||
static void dst_param_init_ssa_vec4(struct vkd3d_shader_dst_param *dst, unsigned int idx,
|
||||
enum vkd3d_data_type data_type)
|
||||
{
|
||||
vsir_dst_param_init(dst, VKD3DSPR_SSA, VKD3D_DATA_FLOAT, 1);
|
||||
vsir_dst_param_init(dst, VKD3DSPR_SSA, data_type, 1);
|
||||
dst->reg.idx[0].offset = idx;
|
||||
dst->reg.dimension = VSIR_DIMENSION_VEC4;
|
||||
dst->write_mask = VKD3DSP_WRITEMASK_ALL;
|
||||
}
|
||||
|
||||
static void dst_param_init_ssa_float4(struct vkd3d_shader_dst_param *dst, unsigned int idx)
|
||||
{
|
||||
dst_param_init_ssa_vec4(dst, idx, VKD3D_DATA_FLOAT);
|
||||
}
|
||||
|
||||
static void dst_param_init_temp_bool(struct vkd3d_shader_dst_param *dst, unsigned int idx)
|
||||
{
|
||||
vsir_dst_param_init(dst, VKD3DSPR_TEMP, VKD3D_DATA_BOOL, 1);
|
||||
@@ -1094,9 +1106,6 @@ static enum vkd3d_result vsir_program_lower_sm1_sincos(struct vsir_program *prog
|
||||
struct vkd3d_shader_instruction *ins, *mov;
|
||||
unsigned int s, count;
|
||||
|
||||
if (sincos->dst_count != 1)
|
||||
return VKD3D_OK;
|
||||
|
||||
count = 1 + vkd3d_popcount(sincos->dst[0].write_mask & (VKD3DSP_WRITEMASK_0 | VKD3DSP_WRITEMASK_1));
|
||||
|
||||
if (!shader_instruction_array_insert_at(instructions, pos + 1, count))
|
||||
@@ -1154,6 +1163,74 @@ static enum vkd3d_result vsir_program_lower_sm1_sincos(struct vsir_program *prog
|
||||
return VKD3D_OK;
|
||||
}
|
||||
|
||||
static enum vkd3d_result vsir_program_lower_sm4_sincos(struct vsir_program *program,
|
||||
struct vkd3d_shader_instruction *sincos, struct vsir_transformation_context *ctx)
|
||||
{
|
||||
struct vkd3d_shader_instruction_array *instructions = &program->instructions;
|
||||
size_t pos = sincos - instructions->elements;
|
||||
struct vkd3d_shader_instruction *ins, *mov;
|
||||
unsigned int count = 1;
|
||||
|
||||
if (sincos->dst_count != 2)
|
||||
{
|
||||
vkd3d_shader_error(ctx->message_context, &sincos->location,
|
||||
VKD3D_SHADER_ERROR_VSIR_INVALID_DEST_COUNT,
|
||||
"Internal compiler error: invalid destination count %u for SINCOS.",
|
||||
sincos->dst_count);
|
||||
return VKD3D_ERROR;
|
||||
}
|
||||
|
||||
if (sincos->dst[0].reg.type != VKD3DSPR_NULL)
|
||||
++count;
|
||||
if (sincos->dst[1].reg.type != VKD3DSPR_NULL)
|
||||
++count;
|
||||
|
||||
if (!shader_instruction_array_insert_at(instructions, pos + 1, count))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
sincos = &instructions->elements[pos];
|
||||
|
||||
ins = &instructions->elements[pos + 1];
|
||||
|
||||
/* Save the source in a SSA in case a destination collides with the source. */
|
||||
mov = ins++;
|
||||
if (!(vsir_instruction_init_with_params(program, mov, &sincos->location, VKD3DSIH_MOV, 1, 1)))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mov->src[0] = sincos->src[0];
|
||||
dst_param_init_ssa_vec4(&mov->dst[0], program->ssa_count, sincos->src[0].reg.data_type);
|
||||
|
||||
if (sincos->dst[0].reg.type != VKD3DSPR_NULL)
|
||||
{
|
||||
if (!(vsir_instruction_init_with_params(program, ins, &sincos->location, VKD3DSIH_SIN, 1, 1)))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
ins->flags = sincos->flags;
|
||||
|
||||
src_param_init_ssa_vec4(&ins->src[0], program->ssa_count, sincos->src[0].reg.data_type);
|
||||
ins->dst[0] = sincos->dst[0];
|
||||
|
||||
++ins;
|
||||
}
|
||||
|
||||
if (sincos->dst[1].reg.type != VKD3DSPR_NULL)
|
||||
{
|
||||
if (!(vsir_instruction_init_with_params(program, ins, &sincos->location, VKD3DSIH_COS, 1, 1)))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
ins->flags = sincos->flags;
|
||||
|
||||
src_param_init_ssa_vec4(&ins->src[0], program->ssa_count, sincos->src[0].reg.data_type);
|
||||
ins->dst[0] = sincos->dst[1];
|
||||
|
||||
++ins;
|
||||
}
|
||||
|
||||
vkd3d_shader_instruction_make_nop(sincos);
|
||||
++program->ssa_count;
|
||||
|
||||
return VKD3D_OK;
|
||||
}
|
||||
|
||||
static enum vkd3d_result vsir_program_lower_texldp(struct vsir_program *program,
|
||||
struct vkd3d_shader_instruction *tex, unsigned int *tmp_idx)
|
||||
{
|
||||
@@ -1402,8 +1479,16 @@ static enum vkd3d_result vsir_program_lower_instructions(struct vsir_program *pr
|
||||
break;
|
||||
|
||||
case VKD3DSIH_SINCOS:
|
||||
if ((ret = vsir_program_lower_sm1_sincos(program, ins)) < 0)
|
||||
return ret;
|
||||
if (ins->dst_count == 1)
|
||||
{
|
||||
if ((ret = vsir_program_lower_sm1_sincos(program, ins)) < 0)
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ret = vsir_program_lower_sm4_sincos(program, ins, ctx)) < 0)
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case VKD3DSIH_TEXLD:
|
||||
|
@@ -2485,18 +2485,6 @@ static uint32_t vkd3d_spirv_build_op_glsl_std450_fabs(struct vkd3d_spirv_builder
|
||||
return vkd3d_spirv_build_op_glsl_std450_tr1(builder, GLSLstd450FAbs, result_type, operand);
|
||||
}
|
||||
|
||||
static uint32_t vkd3d_spirv_build_op_glsl_std450_sin(struct vkd3d_spirv_builder *builder,
|
||||
uint32_t result_type, uint32_t operand)
|
||||
{
|
||||
return vkd3d_spirv_build_op_glsl_std450_tr1(builder, GLSLstd450Sin, result_type, operand);
|
||||
}
|
||||
|
||||
static uint32_t vkd3d_spirv_build_op_glsl_std450_cos(struct vkd3d_spirv_builder *builder,
|
||||
uint32_t result_type, uint32_t operand)
|
||||
{
|
||||
return vkd3d_spirv_build_op_glsl_std450_tr1(builder, GLSLstd450Cos, result_type, operand);
|
||||
}
|
||||
|
||||
static uint32_t vkd3d_spirv_build_op_glsl_std450_max(struct vkd3d_spirv_builder *builder,
|
||||
uint32_t result_type, uint32_t x, uint32_t y)
|
||||
{
|
||||
@@ -8027,41 +8015,6 @@ static void spirv_compiler_emit_rcp(struct spirv_compiler *compiler,
|
||||
spirv_compiler_emit_store_dst(compiler, dst, val_id);
|
||||
}
|
||||
|
||||
static void spirv_compiler_emit_sincos(struct spirv_compiler *compiler,
|
||||
const struct vkd3d_shader_instruction *instruction)
|
||||
{
|
||||
const struct vkd3d_shader_dst_param *dst_sin = &instruction->dst[0];
|
||||
const struct vkd3d_shader_dst_param *dst_cos = &instruction->dst[1];
|
||||
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
|
||||
const struct vkd3d_shader_src_param *src = instruction->src;
|
||||
uint32_t type_id, src_id, sin_id = 0, cos_id = 0;
|
||||
|
||||
if (dst_sin->reg.type != VKD3DSPR_NULL)
|
||||
{
|
||||
type_id = spirv_compiler_get_type_id_for_dst(compiler, dst_sin);
|
||||
src_id = spirv_compiler_emit_load_src(compiler, src, dst_sin->write_mask);
|
||||
|
||||
sin_id = vkd3d_spirv_build_op_glsl_std450_sin(builder, type_id, src_id);
|
||||
}
|
||||
|
||||
if (dst_cos->reg.type != VKD3DSPR_NULL)
|
||||
{
|
||||
if (dst_sin->reg.type == VKD3DSPR_NULL || dst_cos->write_mask != dst_sin->write_mask)
|
||||
{
|
||||
type_id = spirv_compiler_get_type_id_for_dst(compiler, dst_cos);
|
||||
src_id = spirv_compiler_emit_load_src(compiler, src, dst_cos->write_mask);
|
||||
}
|
||||
|
||||
cos_id = vkd3d_spirv_build_op_glsl_std450_cos(builder, type_id, src_id);
|
||||
}
|
||||
|
||||
if (sin_id)
|
||||
spirv_compiler_emit_store_dst(compiler, dst_sin, sin_id);
|
||||
|
||||
if (cos_id)
|
||||
spirv_compiler_emit_store_dst(compiler, dst_cos, cos_id);
|
||||
}
|
||||
|
||||
static void spirv_compiler_emit_imul(struct spirv_compiler *compiler,
|
||||
const struct vkd3d_shader_instruction *instruction)
|
||||
{
|
||||
@@ -10778,9 +10731,6 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler,
|
||||
case VKD3DSIH_RCP:
|
||||
spirv_compiler_emit_rcp(compiler, instruction);
|
||||
break;
|
||||
case VKD3DSIH_SINCOS:
|
||||
spirv_compiler_emit_sincos(compiler, instruction);
|
||||
break;
|
||||
case VKD3DSIH_IMUL:
|
||||
case VKD3DSIH_UMUL:
|
||||
spirv_compiler_emit_imul(compiler, instruction);
|
||||
|
Reference in New Issue
Block a user