[WINED3D 8] Create fake input semantics for d3d8 shaders.

Ivan Gyurdiev ivg231 at gmail.com
Fri Jul 7 01:28:30 CDT 2006


...and use them to remove the need for loading arrays in two different 
places.
primitiveDeclarationConvertToStridedData is not the place to be loading 
arrays - that's already done in loadNumberedArrays.

-------------- next part --------------
>From ca9f4cd8e10f3167b58db5f50813531c4e809498 Mon Sep 17 00:00:00 2001
From: root <root at shark.bluenet>
Date: Wed, 5 Jul 2006 20:40:49 -0600
Subject: [PATCH] Create fake input semantics for d3d8 shaders.

...and use them to remove the need for loading arrays in two different places.
primitiveDeclarationConvertToStridedData is not the place to be loading arrays - that's already done in loadNumberedArrays.
---
 dlls/wined3d/drawprim.c     |   13 -------------
 dlls/wined3d/vertexshader.c |   40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 7177864..68eb70c 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -451,19 +451,6 @@ void primitiveDeclarationConvertToStride
 
         TRACE("Offset %d Stream %d UsageIndex %d\n", element->Offset, element->Stream, element->UsageIndex);
 
-        if (useVertexShaderFunction && reg != -1 && (data || streamVBO) ) {
-            WINED3DGLTYPE glType = glTypeLookup[element->Type];
-
-            TRACE("(%p) : Set vertex attrib pointer: reg 0x%08x, d3d type 0x%08x, stride 0x%08lx, data %p)\n", This, reg, element->Type, stride, data);
-
-            GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, streamVBO));
-            checkGLcall("glBindBufferARB");
-            GL_EXTCALL(glVertexAttribPointerARB(reg, glType.size, glType.glType, glType.normalized, stride, data));
-            checkGLcall("glVertexAttribPointerARB");
-            GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
-            checkGLcall("glEnableVertexAttribArrayARB");
-        }
-
         if (useVertexShaderFunction)
             stride_used = vshader_get_input(This->stateBlock->vertexShader,
                 element->Usage, element->UsageIndex, &idx);
diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c
index 7d452d2..db07675 100644
--- a/dlls/wined3d/vertexshader.c
+++ b/dlls/wined3d/vertexshader.c
@@ -609,6 +609,28 @@ static void vshader_set_limits(
       }
 }
 
+/* This is an internal function,
+ * used to create fake semantics for shaders
+ * that don't have them - d3d8 shaders where the declaration
+ * stores the register for each input
+ */
+static void vshader_set_input(
+    IWineD3DVertexShaderImpl* This,
+    unsigned int regnum,
+    BYTE usage, BYTE usage_idx) {
+
+    /* Fake usage: set reserved bit, usage, usage_idx */
+    DWORD usage_token = (0x1 << 31) |
+        (usage << D3DSP_DCL_USAGE_SHIFT) | (usage_idx << D3DSP_DCL_USAGEINDEX_SHIFT);
+
+    /* Fake register; set reserved bit, regnum, type: input, wmask: all */
+    DWORD reg_token = (0x1 << 31) |
+        D3DSP_WRITEMASK_ALL | (D3DSPR_INPUT << D3DSP_REGTYPE_SHIFT) | regnum;
+
+    This->semantics_in[regnum].usage = usage_token;
+    This->semantics_in[regnum].reg = reg_token;
+}
+
 BOOL vshader_get_input(
     IWineD3DVertexShader* iface,
     BYTE usage_req, BYTE usage_idx_req,
@@ -637,7 +659,13 @@ BOOL vshader_input_is_color(
     IWineD3DVertexShaderImpl* This = (IWineD3DVertexShaderImpl*) iface;
     DWORD usage_token = This->semantics_in[regnum].usage;
     DWORD usage = (usage_token & D3DSP_DCL_USAGE_MASK) >> D3DSP_DCL_USAGE_SHIFT;
-    return usage == D3DDECLUSAGE_COLOR;
+
+    /* FIXME: D3D8 shader: the semantics token is not the way to 
+     * determine color info, since it is just a fake map to shader inputs */
+    if (This->vertexDeclaration != NULL)
+        return FALSE; 
+    else
+        return usage == D3DDECLUSAGE_COLOR;
 }
 
 /** Generate a vertex shader string using either GL_VERTEX_PROGRAM_ARB
@@ -1077,6 +1105,16 @@ static HRESULT WINAPI IWineD3DVertexShad
     shader_trace_init((IWineD3DBaseShader*) This, pFunction);
     vshader_set_limits(This);
 
+    /* Preload semantics for d3d8 shaders */
+    if (This->vertexDeclaration) {
+       IWineD3DVertexDeclarationImpl* vdecl = (IWineD3DVertexDeclarationImpl*) This->vertexDeclaration;
+       int i;
+       for (i = 0; i < vdecl->declarationWNumElements - 1; ++i) {
+           WINED3DVERTEXELEMENT* element = vdecl->pDeclarationWine + i;
+           vshader_set_input(This, element->Reg, element->Usage, element->UsageIndex);
+       }
+    }
+
     /* Second pass: figure out registers used, semantics, etc.. */
     memset(&reg_maps, 0, sizeof(shader_reg_maps));
     shader_get_registers_used((IWineD3DBaseShader*) This, &reg_maps,
-- 
1.4.0



More information about the wine-patches mailing list