Ivan Gyurdiev : wined3d: Create fake input semantics for d3d8 shaders.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jul 7 11:10:27 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 899c8cdb64b6950c37ba875e3c9611337c127452
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=899c8cdb64b6950c37ba875e3c9611337c127452

Author: Ivan Gyurdiev <ivg231 at gmail.com>
Date:   Fri Jul  7 00:28:30 2006 -0600

wined3d: Create fake input semantics for d3d8 shaders.

Use them to remove the need for loading arrays in two different places.

---

 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 25e2c1e..1a1d01e 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,




More information about the wine-cvs mailing list