Based on a vkd3d-proton patch by Joshua Ashton.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d-shader/dxbc.c | 1 + libs/vkd3d-shader/sm4.h | 1 + libs/vkd3d-shader/spirv.c | 30 ++++++++++++++++++++++++ libs/vkd3d-shader/trace.c | 1 + libs/vkd3d-shader/vkd3d_shader_private.h | 1 + tests/d3d12.c | 2 +- 6 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index fab19046..0c590563 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -807,6 +807,7 @@ static const struct vkd3d_sm4_opcode_info opcode_table[] = {VKD3D_SM5_OP_DNE, VKD3DSIH_DNE, "u", "dd"}, {VKD3D_SM5_OP_DMOV, VKD3DSIH_DMOV, "d", "d"}, {VKD3D_SM5_OP_DMOVC, VKD3DSIH_DMOVC, "d", "udd"}, + {VKD3D_SM5_OP_FTOD, VKD3DSIH_FTOD, "d", "f"}, {VKD3D_SM5_OP_EVAL_SAMPLE_INDEX, VKD3DSIH_EVAL_SAMPLE_INDEX, "f", "fi"}, {VKD3D_SM5_OP_EVAL_CENTROID, VKD3DSIH_EVAL_CENTROID, "f", "f"}, {VKD3D_SM5_OP_DCL_GS_INSTANCES, VKD3DSIH_DCL_GS_INSTANCES, "", "", diff --git a/libs/vkd3d-shader/sm4.h b/libs/vkd3d-shader/sm4.h index 335f0161..5f4f22db 100644 --- a/libs/vkd3d-shader/sm4.h +++ b/libs/vkd3d-shader/sm4.h @@ -327,6 +327,7 @@ enum vkd3d_sm4_opcode VKD3D_SM5_OP_DNE = 0xc6, VKD3D_SM5_OP_DMOV = 0xc7, VKD3D_SM5_OP_DMOVC = 0xc8, + VKD3D_SM5_OP_FTOD = 0xca, VKD3D_SM5_OP_EVAL_SAMPLE_INDEX = 0xcc, VKD3D_SM5_OP_EVAL_CENTROID = 0xcd, VKD3D_SM5_OP_DCL_GS_INSTANCES = 0xce, diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 5729ea1a..fef81c7b 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -9322,6 +9322,33 @@ static void vkd3d_dxbc_compiler_emit_cut_stream(struct vkd3d_dxbc_compiler *comp vkd3d_spirv_build_op_end_primitive(builder); }
+static void vkd3d_dxbc_compiler_emit_double_conversion(struct vkd3d_dxbc_compiler *compiler, + const struct vkd3d_shader_instruction *instruction) +{ + struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; + const struct vkd3d_shader_dst_param *dst = instruction->dst; + const struct vkd3d_shader_src_param *src = instruction->src; + uint32_t src_id, val_id, type_id; + SpvOp op; + + switch (instruction->handler_idx) + { + case VKD3DSIH_FTOD: op = SpvOpFConvert; break; + default: + ERR("Unexpected instruction %#x.\n", instruction->handler_idx); + return; + } + + src_id = vkd3d_dxbc_compiler_emit_load_src(compiler, src, dst->write_mask); + + type_id = vkd3d_spirv_get_type_id(builder, vkd3d_component_type_from_data_type(dst->reg.data_type), + vkd3d_write_mask_component_count(dst->write_mask)); + + val_id = vkd3d_spirv_build_op_trv(builder, &builder->function_stream, op, type_id, &src_id, 1); + + vkd3d_dxbc_compiler_emit_store_dst(compiler, dst, val_id); +} + static void vkd3d_dxbc_compiler_emit_hull_shader_inputs(struct vkd3d_dxbc_compiler *compiler) { const struct vkd3d_shader_signature *signature = compiler->input_signature; @@ -9730,6 +9757,9 @@ int vkd3d_dxbc_compiler_handle_instruction(struct vkd3d_dxbc_compiler *compiler, case VKD3DSIH_CUT_STREAM: vkd3d_dxbc_compiler_emit_cut_stream(compiler, instruction); break; + case VKD3DSIH_FTOD: + vkd3d_dxbc_compiler_emit_double_conversion(compiler, instruction); + break; case VKD3DSIH_DCL_HS_MAX_TESSFACTOR: case VKD3DSIH_HS_DECLS: case VKD3DSIH_NOP: diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 830a5fc7..8f93e1bd 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -147,6 +147,7 @@ static const char * const shader_opcode_names[] = /* VKD3DSIH_FIRSTBIT_LO */ "firstbit_lo", /* VKD3DSIH_FIRSTBIT_SHI */ "firstbit_shi", /* VKD3DSIH_FRC */ "frc", + /* VKD3DSIH_FTOD */ "ftod", /* VKD3DSIH_FTOI */ "ftoi", /* VKD3DSIH_FTOU */ "ftou", /* VKD3DSIH_GATHER4 */ "gather4", diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 9948045e..7400be51 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -236,6 +236,7 @@ enum vkd3d_shader_opcode VKD3DSIH_FIRSTBIT_LO, VKD3DSIH_FIRSTBIT_SHI, VKD3DSIH_FRC, + VKD3DSIH_FTOD, VKD3DSIH_FTOI, VKD3DSIH_FTOU, VKD3DSIH_GATHER4, diff --git a/tests/d3d12.c b/tests/d3d12.c index 2b1830bd..4c03b81e 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -10032,7 +10032,7 @@ static void test_shader_instructions(void) {&ps_dtof, {.d = {{ 1.5}}}, {.f = {1.5f, -1.5f}}, true, true}, {&ps_utod, {.u = {{3, 0xffffffff}}}, {.d = {3.0, 4294967295.0}}, true, true}, {&ps_itod, {.u = {{3, INT_MIN}}}, {.d = {3.0, -2147483648.0}}, true, true}, - {&ps_ftod, {.f = {{-2.5f, -2.5f}}}, {.d = {-2.5, 2.5}}, true, true}, + {&ps_ftod, {.f = {{-2.5f, -2.5f}}}, {.d = {-2.5, 2.5}}, true}, {&ps_dmul, {.d = {{ 1.5, 3.0}}}, {.d = { 4.5, -4.5}}, true}, {&ps_ddiv, {.d = {{ 2.0, 4.0}}}, {.d = { 0.5, 2.0}}, true}, {&ps_ddiv, {.d = {{ 2.0, -4.0}}}, {.d = {-0.5, -2.0}}, true},