[PATCH vkd3d 2/6] vkd3d-shader: Write empty SM1 shaders.

Zebediah Figura zfigura at codeweavers.com
Wed Apr 14 00:03:12 CDT 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 Makefile.am                      |   1 +
 include/vkd3d_d3d9types.h        | 121 +++++++++++++++++++++++++++++++
 libs/vkd3d-shader/hlsl.c         |   2 +-
 libs/vkd3d-shader/hlsl.h         |   3 +-
 libs/vkd3d-shader/hlsl_codegen.c |  55 +++++++++++++-
 5 files changed, 178 insertions(+), 4 deletions(-)
 create mode 100644 include/vkd3d_d3d9types.h

diff --git a/Makefile.am b/Makefile.am
index a79ad02f..2ab2233a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,7 @@ vkd3d_public_headers = \
 	include/vkd3d.h \
 	include/vkd3d_d3d12.h \
 	include/vkd3d_d3d12sdklayers.h \
+	include/vkd3d_d3d9types.h \
 	include/vkd3d_d3dcommon.h \
 	include/vkd3d_d3dcompiler.h \
 	include/vkd3d_dxgibase.h \
diff --git a/include/vkd3d_d3d9types.h b/include/vkd3d_d3d9types.h
new file mode 100644
index 00000000..11d2e2fc
--- /dev/null
+++ b/include/vkd3d_d3d9types.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2002-2003 Jason Edmeades
+ * Copyright 2002-2003 Raphael Junqueira
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef __VKD3D_D3D9TYPES_H
+#define __VKD3D_D3D9TYPES_H
+#ifndef _d3d9TYPES_H_
+
+#define D3DPS_VERSION(major, minor) (0xffff0000 | ((major) << 8) | (minor))
+#define D3DVS_VERSION(major, minor) (0xfffe0000 | ((major) << 8) | (minor))
+
+typedef enum _D3DSHADER_INSTRUCTION_OPCODE_TYPE
+{
+    D3DSIO_NOP          =  0,
+    D3DSIO_MOV          =  1,
+    D3DSIO_ADD          =  2,
+    D3DSIO_SUB          =  3,
+    D3DSIO_MAD          =  4,
+    D3DSIO_MUL          =  5,
+    D3DSIO_RCP          =  6,
+    D3DSIO_RSQ          =  7,
+    D3DSIO_DP3          =  8,
+    D3DSIO_DP4          =  9,
+    D3DSIO_MIN          = 10,
+    D3DSIO_MAX          = 11,
+    D3DSIO_SLT          = 12,
+    D3DSIO_SGE          = 13,
+    D3DSIO_EXP          = 14,
+    D3DSIO_LOG          = 15,
+    D3DSIO_LIT          = 16,
+    D3DSIO_DST          = 17,
+    D3DSIO_LRP          = 18,
+    D3DSIO_FRC          = 19,
+    D3DSIO_M4x4         = 20,
+    D3DSIO_M4x3         = 21,
+    D3DSIO_M3x4         = 22,
+    D3DSIO_M3x3         = 23,
+    D3DSIO_M3x2         = 24,
+    D3DSIO_CALL         = 25,
+    D3DSIO_CALLNZ       = 26,
+    D3DSIO_LOOP         = 27,
+    D3DSIO_RET          = 28,
+    D3DSIO_ENDLOOP      = 29,
+    D3DSIO_LABEL        = 30,
+    D3DSIO_DCL          = 31,
+    D3DSIO_POW          = 32,
+    D3DSIO_CRS          = 33,
+    D3DSIO_SGN          = 34,
+    D3DSIO_ABS          = 35,
+    D3DSIO_NRM          = 36,
+    D3DSIO_SINCOS       = 37,
+    D3DSIO_REP          = 38,
+    D3DSIO_ENDREP       = 39,
+    D3DSIO_IF           = 40,
+    D3DSIO_IFC          = 41,
+    D3DSIO_ELSE         = 42,
+    D3DSIO_ENDIF        = 43,
+    D3DSIO_BREAK        = 44,
+    D3DSIO_BREAKC       = 45,
+    D3DSIO_MOVA         = 46,
+    D3DSIO_DEFB         = 47,
+    D3DSIO_DEFI         = 48,
+
+    D3DSIO_TEXCOORD     = 64,
+    D3DSIO_TEXKILL      = 65,
+    D3DSIO_TEX          = 66,
+    D3DSIO_TEXBEM       = 67,
+    D3DSIO_TEXBEML      = 68,
+    D3DSIO_TEXREG2AR    = 69,
+    D3DSIO_TEXREG2GB    = 70,
+    D3DSIO_TEXM3x2PAD   = 71,
+    D3DSIO_TEXM3x2TEX   = 72,
+    D3DSIO_TEXM3x3PAD   = 73,
+    D3DSIO_TEXM3x3TEX   = 74,
+    D3DSIO_TEXM3x3DIFF  = 75,
+    D3DSIO_TEXM3x3SPEC  = 76,
+    D3DSIO_TEXM3x3VSPEC = 77,
+    D3DSIO_EXPP         = 78,
+    D3DSIO_LOGP         = 79,
+    D3DSIO_CND          = 80,
+    D3DSIO_DEF          = 81,
+    D3DSIO_TEXREG2RGB   = 82,
+    D3DSIO_TEXDP3TEX    = 83,
+    D3DSIO_TEXM3x2DEPTH = 84,
+    D3DSIO_TEXDP3       = 85,
+    D3DSIO_TEXM3x3      = 86,
+    D3DSIO_TEXDEPTH     = 87,
+    D3DSIO_CMP          = 88,
+    D3DSIO_BEM          = 89,
+    D3DSIO_DP2ADD       = 90,
+    D3DSIO_DSX          = 91,
+    D3DSIO_DSY          = 92,
+    D3DSIO_TEXLDD       = 93,
+    D3DSIO_SETP         = 94,
+    D3DSIO_TEXLDL       = 95,
+    D3DSIO_BREAKP       = 96,
+
+    D3DSIO_PHASE        = 0xfffd,
+    D3DSIO_COMMENT      = 0xfffe,
+    D3DSIO_END          = 0xffff,
+
+    D3DSIO_FORCE_DWORD  = 0x7fffffff,
+} D3DSHADER_INSTRUCTION_OPCODE_TYPE;
+
+#endif  /* _d3d9TYPES_H_ */
+#endif  /* __VKD3D_D3D9TYPES_H */
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index d797aa10..10105eaf 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -1671,7 +1671,7 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d
         hlsl_error(&ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
                 "Entry point \"%s\" is missing a return value semantic.", entry_point);
 
-    ret = hlsl_emit_dxbc(&ctx, entry_func);
+    ret = hlsl_emit_dxbc(&ctx, entry_func, dxbc);
 
     hlsl_ctx_cleanup(&ctx);
     return ret;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 923eff55..8493f749 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -530,7 +530,8 @@ bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var
 
 void hlsl_dump_function(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
 
-int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func) DECLSPEC_HIDDEN;
+int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func,
+        struct vkd3d_shader_code *out) DECLSPEC_HIDDEN;
 
 void hlsl_free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
 void hlsl_free_instr_list(struct list *list) DECLSPEC_HIDDEN;
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 81e60101..2656db33 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -20,6 +20,7 @@
 
 #include "hlsl.h"
 #include <stdio.h>
+#include "vkd3d_d3d9types.h"
 
 /* Split uniforms into two variables representing the constant and temp
  * registers, and copy the former to the latter, so that writes to uniforms
@@ -873,7 +874,53 @@ static void allocate_temp_registers(struct hlsl_ir_function_decl *entry_func)
     allocate_temp_registers_recurse(entry_func->body, &liveness);
 }
 
-int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func)
+struct bytecode_buffer
+{
+    DWORD *data;
+    size_t count, size;
+    int status;
+};
+
+static void put_dword(struct bytecode_buffer *buffer, DWORD value)
+{
+    if (buffer->status)
+        return;
+
+    if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->size, buffer->count + 1, sizeof(*buffer->data)))
+    {
+        buffer->status = VKD3D_ERROR_OUT_OF_MEMORY;
+        return;
+    }
+    buffer->data[buffer->count++] = value;
+}
+
+static DWORD sm1_version(enum vkd3d_shader_type type, unsigned int major, unsigned int minor)
+{
+    if (type == VKD3D_SHADER_TYPE_VERTEX)
+        return D3DVS_VERSION(major, minor);
+    else
+        return D3DPS_VERSION(major, minor);
+}
+
+static int write_sm1_shader(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func,
+        struct vkd3d_shader_code *out)
+{
+    struct bytecode_buffer buffer = {0};
+    int ret;
+
+    put_dword(&buffer, sm1_version(ctx->profile->type, ctx->profile->major_version, ctx->profile->minor_version));
+
+    put_dword(&buffer, D3DSIO_END);
+
+    if (!(ret = buffer.status))
+    {
+        out->code = buffer.data;
+        out->size = buffer.count * sizeof(DWORD);
+    }
+    return ret;
+}
+
+int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, struct vkd3d_shader_code *out)
 {
     struct hlsl_ir_var *var;
 
@@ -916,5 +963,9 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
 
     if (ctx->failed)
         return VKD3D_ERROR_INVALID_SHADER;
-    return VKD3D_ERROR_NOT_IMPLEMENTED;
+
+    if (ctx->profile->major_version < 4)
+        return write_sm1_shader(ctx, entry_func, out);
+    else
+        return VKD3D_ERROR_NOT_IMPLEMENTED;
 }
-- 
2.31.1




More information about the wine-devel mailing list