[PATCH vkd3d 4/5] vkd3d-shader: Implement DRCP instruction.

Conor McCarthy cmccarthy at codeweavers.com
Tue Aug 10 20:53:01 CDT 2021


Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
 libs/vkd3d-shader/dxbc.c                 |  1 +
 libs/vkd3d-shader/sm4.h                  |  1 +
 libs/vkd3d-shader/spirv.c                | 10 +++++++---
 libs/vkd3d-shader/trace.c                |  1 +
 libs/vkd3d-shader/vkd3d_shader_private.h |  1 +
 tests/d3d12.c                            |  2 +-
 6 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c
index ed7a01a4..8e0f8cbd 100644
--- a/libs/vkd3d-shader/dxbc.c
+++ b/libs/vkd3d-shader/dxbc.c
@@ -812,6 +812,7 @@ static const struct vkd3d_sm4_opcode_info opcode_table[] =
             shader_sm4_read_declaration_count},
     {VKD3D_SM5_OP_DDIV,                             VKD3DSIH_DDIV,                             "d",    "dd"},
     {VKD3D_SM5_OP_DFMA,                             VKD3DSIH_DFMA,                             "d",    "ddd"},
+    {VKD3D_SM5_OP_DRCP,                             VKD3DSIH_DRCP,                             "d",    "d"},
 };
 
 static const enum vkd3d_shader_register_type register_type_table[] =
diff --git a/libs/vkd3d-shader/sm4.h b/libs/vkd3d-shader/sm4.h
index aba7d276..0c56a0cd 100644
--- a/libs/vkd3d-shader/sm4.h
+++ b/libs/vkd3d-shader/sm4.h
@@ -331,6 +331,7 @@ enum vkd3d_sm4_opcode
     VKD3D_SM5_OP_DCL_GS_INSTANCES                 = 0xce,
     VKD3D_SM5_OP_DDIV                             = 0xd2,
     VKD3D_SM5_OP_DFMA                             = 0xd3,
+    VKD3D_SM5_OP_DRCP                             = 0xd4,
 };
 
 enum vkd3d_sm4_instruction_modifier
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c
index 3db100e1..37c3b310 100644
--- a/libs/vkd3d-shader/spirv.c
+++ b/libs/vkd3d-shader/spirv.c
@@ -7078,15 +7078,18 @@ static void vkd3d_dxbc_compiler_emit_rcp(struct vkd3d_dxbc_compiler *compiler,
     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 type_id, src_id, val_id;
+    uint32_t type_id, src_id, val_id, div_id;
     unsigned int component_count;
 
     component_count = vkd3d_write_mask_component_count(dst->write_mask);
     type_id = vkd3d_dxbc_compiler_get_type_id_for_dst(compiler, dst);
 
     src_id = vkd3d_dxbc_compiler_emit_load_src(compiler, src, dst->write_mask);
-    val_id = vkd3d_spirv_build_op_fdiv(builder, type_id,
-            vkd3d_dxbc_compiler_get_constant_float_vector(compiler, 1.0f, component_count), src_id);
+    if (src->reg.data_type == VKD3D_DATA_DOUBLE)
+        div_id = vkd3d_dxbc_compiler_get_constant_double_vector(compiler, 1.0, component_count);
+    else
+        div_id = vkd3d_dxbc_compiler_get_constant_float_vector(compiler, 1.0f, component_count);
+    val_id = vkd3d_spirv_build_op_fdiv(builder, type_id, div_id, src_id);
     vkd3d_dxbc_compiler_emit_store_dst(compiler, dst, val_id);
 }
 
@@ -9568,6 +9571,7 @@ int vkd3d_dxbc_compiler_handle_instruction(struct vkd3d_dxbc_compiler *compiler,
         case VKD3DSIH_DP2:
             vkd3d_dxbc_compiler_emit_dot(compiler, instruction);
             break;
+        case VKD3DSIH_DRCP:
         case VKD3DSIH_RCP:
             vkd3d_dxbc_compiler_emit_rcp(compiler, instruction);
             break;
diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c
index a7294307..2af3a769 100644
--- a/libs/vkd3d-shader/trace.c
+++ b/libs/vkd3d-shader/trace.c
@@ -119,6 +119,7 @@ static const char * const shader_opcode_names[] =
     /* VKD3DSIH_DP2ADD                           */ "dp2add",
     /* VKD3DSIH_DP3                              */ "dp3",
     /* VKD3DSIH_DP4                              */ "dp4",
+    /* VKD3DSIH_DRCP                             */ "drcp",
     /* VKD3DSIH_DST                              */ "dst",
     /* VKD3DSIH_DSX                              */ "dsx",
     /* VKD3DSIH_DSX_COARSE                       */ "deriv_rtx_coarse",
diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h
index 56a4dde5..94daa08f 100644
--- a/libs/vkd3d-shader/vkd3d_shader_private.h
+++ b/libs/vkd3d-shader/vkd3d_shader_private.h
@@ -208,6 +208,7 @@ enum vkd3d_shader_opcode
     VKD3DSIH_DP2ADD,
     VKD3DSIH_DP3,
     VKD3DSIH_DP4,
+    VKD3DSIH_DRCP,
     VKD3DSIH_DST,
     VKD3DSIH_DSX,
     VKD3DSIH_DSX_COARSE,
diff --git a/tests/d3d12.c b/tests/d3d12.c
index e7a273e6..b8d53424 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -10010,7 +10010,7 @@ static void test_shader_instructions(void)
         {&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},
-        {&ps_drcp, {.d = {{ 2.0,   -0.5}}},  {.d = { 0.5, -2.0}}, true, true},
+        {&ps_drcp, {.d = {{ 2.0,   -0.5}}},  {.d = { 0.5, -2.0}}, true},
 
         {
             &ps_swapc0,
-- 
2.32.0




More information about the wine-devel mailing list