vkd3d-shader/ir: Lower VSIR_OP_NRM instructions.

This commit is contained in:
Henri Verbeet
2025-11-23 01:12:00 +01:00
parent 2b31efe03a
commit fdfb74b20b
Notes: Henri Verbeet 2025-11-27 22:06:01 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1847
3 changed files with 90 additions and 12 deletions

View File

@@ -1323,6 +1323,62 @@ static enum vkd3d_result vsir_program_lower_ifc(struct vsir_program *program,
return VKD3D_OK;
}
static enum vkd3d_result vsir_program_lower_nrm(struct vsir_program *program, struct vsir_program_iterator *nrm)
{
struct vkd3d_shader_instruction *ins = vsir_program_iterator_current(nrm);
const struct vkd3d_shader_location location = ins->location;
const struct vkd3d_shader_src_param *src = ins->src;
const struct vkd3d_shader_dst_param *dst = ins->dst;
unsigned int dot_id, rsq_id, mul_id;
struct vsir_program_iterator it;
/* nrm DST, SRC
* ->
* dp3 srDOT, SRC, SRC
* rsq srRSQ, srDOT
* mul srMUL, srRSQ, SRC
* movc DST, srDOT, srMUL, srDOT */
if (!(ins = vsir_program_iterator_insert_before(nrm, &it, 3)))
return VKD3D_ERROR_OUT_OF_MEMORY;
if (!vsir_instruction_init_with_params(program, ins, &location, VSIR_OP_DP3, 1, 2))
goto fail;
dot_id = program->ssa_count++;
dst_param_init_ssa(&ins->dst[0], dot_id, src[0].reg.data_type, VSIR_DIMENSION_SCALAR);
ins->src[0] = src[0];
ins->src[1] = src[0];
ins = vsir_program_iterator_next(&it);
if (!vsir_instruction_init_with_params(program, ins, &location, VSIR_OP_RSQ, 1, 1))
goto fail;
rsq_id = program->ssa_count++;
dst_param_init_ssa(&ins->dst[0], rsq_id, src[0].reg.data_type, VSIR_DIMENSION_SCALAR);
src_param_init_ssa(&ins->src[0], dot_id, src[0].reg.data_type, VSIR_DIMENSION_SCALAR);
ins = vsir_program_iterator_next(&it);
if (!vsir_instruction_init_with_params(program, ins, &location, VSIR_OP_MUL, 1, 2))
goto fail;
mul_id = program->ssa_count++;
dst_param_init_ssa(&ins->dst[0], mul_id, src[0].reg.data_type, dst[0].reg.dimension);
src_param_init_ssa(&ins->src[0], rsq_id, src[0].reg.data_type, VSIR_DIMENSION_SCALAR);
ins->src[1] = src[0];
ins = vsir_program_iterator_next(&it);
if (!vsir_instruction_init_with_params(program, ins, &location, VSIR_OP_MOVC, 1, 3))
goto fail;
ins->dst[0] = dst[0];
src_param_init_ssa(&ins->src[0], dot_id, VSIR_DATA_U32, VSIR_DIMENSION_SCALAR);
src_param_init_ssa(&ins->src[1], mul_id, src[0].reg.data_type, dst[0].reg.dimension);
src_param_init_ssa(&ins->src[2], dot_id, src[0].reg.data_type, VSIR_DIMENSION_SCALAR);
return VKD3D_OK;
fail:
vsir_program_iterator_nop_range(&it, nrm, &location);
return VKD3D_ERROR_OUT_OF_MEMORY;
}
static enum vkd3d_result vsir_program_lower_texkill(struct vsir_program *program,
struct vsir_program_iterator *it, unsigned int *tmp_idx)
{
@@ -2364,6 +2420,10 @@ static enum vkd3d_result vsir_program_lower_d3dbc_instructions(struct vsir_progr
ret = vsir_program_lower_ifc(program, &it, &tmp_idx, message_context);
break;
case VSIR_OP_NRM:
ret = vsir_program_lower_nrm(program, &it);
break;
case VSIR_OP_SINCOS:
ret = vsir_program_lower_sm1_sincos(program, &it);
break;

View File

@@ -1572,6 +1572,24 @@ static inline struct vkd3d_shader_instruction *vsir_program_iterator_insert_befo
return vsir_program_iterator_current(it);
}
static inline void vsir_program_iterator_nop_range(const struct vsir_program_iterator *first,
const struct vsir_program_iterator *last, const struct vkd3d_shader_location *location)
{
const struct vkd3d_shader_instruction_array *array = first->array;
size_t first_idx = first->idx;
size_t last_idx = last->idx;
size_t idx;
VKD3D_ASSERT(last->array == array);
VKD3D_ASSERT(last_idx < array->count);
VKD3D_ASSERT(first_idx <= last_idx);
for (idx = first_idx; idx <= last_idx; ++idx)
{
vsir_instruction_init(&array->elements[idx], location, VSIR_OP_NOP);
}
}
enum vkd3d_shader_config_flags
{
VKD3D_SHADER_CONFIG_FLAG_FORCE_VALIDATION = 0x00000001,

View File

@@ -24,7 +24,7 @@ ffff0300 % ps_3_0
0000ffff % end
[test]
todo draw quad
draw quad
probe (320, 240) f32(.707106769, .707106769, 0, .707106769)
[pixel shader d3dbc-hex]
@@ -38,7 +38,7 @@ ffff0300 % ps_3_0
[test]
uniform 0 float4 .1 .1 .1 .1
todo draw quad
draw quad
probe (320, 240) f32(.707106769, .707106769, .1, .1)
[pixel shader d3dbc-hex]
@@ -49,7 +49,7 @@ ffff0300 % ps_3_0
0000ffff % end
[test]
todo draw quad
draw quad
probe (320, 240) f32(0, .957826257, .287347883, .478913128)
[pixel shader d3dbc-hex]
@@ -60,7 +60,7 @@ ffff0300 % ps_3_0
0000ffff % end
[test]
todo draw quad
draw quad
probe (320, 240) f32(0, .957826257, .287347883, .478913128)
[pixel shader d3dbc-hex]
@@ -73,7 +73,7 @@ ffff0300 % ps_3_0
0000ffff % end
[test]
todo draw quad
draw quad
probe (320, 240) f32(0, .957826257, .1, .1)
[pixel shader d3dbc-hex]
@@ -85,7 +85,7 @@ ffff0300 % ps_3_0
0000ffff % end
[test]
todo draw quad
draw quad
probe (320, 240) f32(0, .707106769, .707106769, .707106769)
[pixel shader d3dbc-hex]
@@ -97,7 +97,7 @@ ffff0300 % ps_3_0
0000ffff % end
[test]
todo draw quad
draw quad
probe (320, 240) f32(.816496611, .408248276, .408248276, .1) 1
[pixel shader d3dbc-hex]
@@ -109,7 +109,7 @@ ffff0300 % ps_3_0
0000ffff % end
[test]
todo draw quad
draw quad
probe (320, 240) f32(0, .707106769, .707106769, .707106769)
[pixel shader d3dbc-hex]
@@ -121,13 +121,13 @@ ffff0300 % ps_3_0
[test]
uniform 0 float4 0 0 0 0
todo draw quad
draw quad
probe (320, 240) f32(0, 0, 0, 0)
uniform 0 float4 2.0 0.0 0.0 0.5
todo draw quad
draw quad
probe (320, 240) f32(1.0, 0.0, .25, .25)
uniform 0 float4 1.0 1.0 1.0 1.0
todo draw quad
draw quad
probe (320, 240) f32(.577350259, .577350259, .577350259, .577350259)
[pixel shader d3dbc-hex]
@@ -138,5 +138,5 @@ ffff0300 % ps_3_0
[test]
uniform 0 float4 1.0 1.0 0.0 2.0
todo draw quad
draw quad
probe (320, 240) f32(.447213590, 0, .894427180, .447213590)