[PATCH] wined3d: Implement SM5 f32tof16 opcode in glsl.
Guillaume Charifi
guillaume.charifi at sfr.fr
Fri Jul 15 06:37:06 CDT 2016
Signed-off-by: Guillaume Charifi <guillaume.charifi at sfr.fr>
---
dlls/wined3d/arb_program_shader.c | 1 +
dlls/wined3d/glsl_shader.c | 38 ++++++++++++++++++++++++++++++++++++++
dlls/wined3d/shader_sm4.c | 2 ++
dlls/wined3d/wined3d_private.h | 1 +
4 files changed, 42 insertions(+)
diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 24c1194..9aa4252 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -5286,6 +5286,7 @@ static const SHADER_HANDLER shader_arb_instruction_handler_table[WINED3DSIH_TABL
/* WINED3DSIH_EQ */ NULL,
/* WINED3DSIH_EXP */ shader_hw_scalar_op,
/* WINED3DSIH_EXPP */ shader_hw_scalar_op,
+ /* WINED3DSIH_F32TOF16 */ NULL,
/* WINED3DSIH_FRC */ shader_hw_map2gl,
/* WINED3DSIH_FTOI */ NULL,
/* WINED3DSIH_FTOU */ NULL,
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 376d110..d8edfdc 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -4343,6 +4343,43 @@ static void shader_glsl_ifc(const struct wined3d_shader_instruction *ins)
src0_param.param_str, shader_glsl_get_rel_op(ins->flags), src1_param.param_str);
}
+static void shader_glsl_f32tof16(const struct wined3d_shader_instruction *ins)
+{
+#define NB_COMPS 4
+ const DWORD write_masks[NB_COMPS] = {
+ WINED3DSP_WRITEMASK_0,
+ WINED3DSP_WRITEMASK_1,
+ WINED3DSP_WRITEMASK_2,
+ WINED3DSP_WRITEMASK_3,
+ };
+ const char dst_masks[NB_COMPS] = { 'x', 'y', 'z', 'w' };
+ struct glsl_src_param src_param;
+ DWORD write_mask;
+ char dst_mask[6];
+ char *dst_mask_ptr = dst_mask;
+
+ write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
+
+ for (int i = 0; i < NB_COMPS; i++)
+ {
+ if (write_mask & write_masks[i])
+ {
+ shader_glsl_add_src_param(ins, &ins->src[0], write_masks[i], &src_param);
+ shader_addline(ins->ctx->buffer, "unpackHalf2x16(floatBitsToUint(%s)).x", src_param.param_str);
+ *dst_mask_ptr++ = dst_masks[i];
+ } else
+ shader_addline(ins->ctx->buffer, "0");
+
+ if(i != NB_COMPS - 1)
+ shader_addline(ins->ctx->buffer, ",");
+ shader_addline(ins->ctx->buffer, "\n");
+ }
+
+ *dst_mask_ptr++ = '\0';
+ shader_addline(ins->ctx->buffer, ")%s);\n", dst_mask);
+#undef NB_COMPS
+}
+
static void shader_glsl_else(const struct wined3d_shader_instruction *ins)
{
shader_addline(ins->ctx->buffer, "} else {\n");
@@ -8704,6 +8741,7 @@ static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TAB
/* WINED3DSIH_EQ */ shader_glsl_relop,
/* WINED3DSIH_EXP */ shader_glsl_scalar_op,
/* WINED3DSIH_EXPP */ shader_glsl_expp,
+ /* WINED3DSIH_F32TOF16 */ shader_glsl_f32tof16,
/* WINED3DSIH_FRC */ shader_glsl_map2gl,
/* WINED3DSIH_FTOI */ shader_glsl_to_int,
/* WINED3DSIH_FTOU */ shader_glsl_to_uint,
diff --git a/dlls/wined3d/shader_sm4.c b/dlls/wined3d/shader_sm4.c
index c8fdb32..6c15751 100644
--- a/dlls/wined3d/shader_sm4.c
+++ b/dlls/wined3d/shader_sm4.c
@@ -215,6 +215,7 @@ enum wined3d_sm4_opcode
WINED3D_SM5_OP_DERIV_RTY_COARSE = 0x7c,
WINED3D_SM5_OP_DERIV_RTY_FINE = 0x7d,
WINED3D_SM5_OP_GATHER4_C = 0x7e,
+ WINED3D_SM5_OP_F32TOF16 = 0x82,
WINED3D_SM5_OP_BFI = 0x8c,
WINED3D_SM5_OP_BFREV = 0x8d,
WINED3D_SM5_OP_SWAPC = 0x8e,
@@ -811,6 +812,7 @@ static const struct wined3d_sm4_opcode_info opcode_table[] =
{WINED3D_SM5_OP_DERIV_RTY_COARSE, WINED3DSIH_DSY_COARSE, "f", "f"},
{WINED3D_SM5_OP_DERIV_RTY_FINE, WINED3DSIH_DSY_FINE, "f", "f"},
{WINED3D_SM5_OP_GATHER4_C, WINED3DSIH_GATHER4_C, "f", "fRSf"},
+ {WINED3D_SM5_OP_F32TOF16, WINED3DSIH_F32TOF16, "f", "f"},
{WINED3D_SM5_OP_BFI, WINED3DSIH_BFI, "u", "uuuu"},
{WINED3D_SM5_OP_BFREV, WINED3DSIH_BFREV, "u", "u"},
{WINED3D_SM5_OP_SWAPC, WINED3DSIH_SWAPC, "ff", "uff"},
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 41c127b..6f95a46 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -631,6 +631,7 @@ enum WINED3D_SHADER_INSTRUCTION_HANDLER
WINED3DSIH_EQ,
WINED3DSIH_EXP,
WINED3DSIH_EXPP,
+ WINED3DSIH_F32TOF16,
WINED3DSIH_FRC,
WINED3DSIH_FTOI,
WINED3DSIH_FTOU,
--
2.7.4
More information about the wine-patches
mailing list