[PATCH 1/3] d3dx9_36: Implement ID3DXConstantTableImpl_GetDesc + tests (try 2)

Christian Costa titan.costa at wanadoo.fr
Wed Mar 17 06:20:44 CDT 2010


--

This time remove todo wine test fixed by this patch
---

 dlls/d3dx9_36/shader.c       |   31 ++++++++++++++++++++++++++++---
 dlls/d3dx9_36/tests/shader.c |   14 ++++++++++++--
 2 files changed, 40 insertions(+), 5 deletions(-)
-------------- next part --------------
diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c
index b9deec1..5d2a667 100644
--- a/dlls/d3dx9_36/shader.c
+++ b/dlls/d3dx9_36/shader.c
@@ -281,6 +281,7 @@ typedef struct ID3DXConstantTableImpl {
     LONG ref;
     LPVOID ctab;
     DWORD size;
+    D3DXCONSTANTTABLE_DESC desc;
 } ID3DXConstantTableImpl;
 
 /*** IUnknown methods ***/
@@ -353,9 +354,14 @@ static HRESULT WINAPI ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable* iface,
 {
     ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
 
-    FIXME("(%p)->(%p): stub\n", This, desc);
+    TRACE("(%p)->(%p)\n", This, desc);
 
-    return E_NOTIMPL;
+    if (!desc)
+        return D3DERR_INVALIDCALL;
+
+    memcpy(desc, &This->desc, sizeof(This->desc));
+
+    return D3D_OK;
 }
 
 static HRESULT WINAPI ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable* iface, D3DXHANDLE constant,
@@ -590,10 +596,11 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
                                             DWORD flags,
                                             LPD3DXCONSTANTTABLE* constant_table)
 {
-    ID3DXConstantTableImpl* object;
+    ID3DXConstantTableImpl* object = NULL;
     HRESULT hr;
     LPCVOID data;
     UINT size;
+    D3DXSHADER_CONSTANTTABLE* ctab_header;
 
     FIXME("(%p, %x, %p): semi-stub\n", byte_code, flags, constant_table);
 
@@ -614,6 +621,9 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
     object->lpVtbl = &ID3DXConstantTable_Vtbl;
     object->ref = 1;
 
+    if (size < sizeof(D3DXSHADER_CONSTANTTABLE))
+        goto error;
+
     object->ctab = HeapAlloc(GetProcessHeap(), 0, size);
     if (!object->ctab)
     {
@@ -624,9 +634,24 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
     object->size = size;
     memcpy(object->ctab, data, object->size);
 
+    ctab_header = (D3DXSHADER_CONSTANTTABLE*)data;
+    if (ctab_header->Size != sizeof(D3DXSHADER_CONSTANTTABLE))
+        goto error;
+    object->desc.Creator = ctab_header->Creator ? (LPCSTR)object->ctab + ctab_header->Creator : NULL;
+    object->desc.Version = ctab_header->Version;
+    object->desc.Constants = ctab_header->Constants;
+
     *constant_table = (LPD3DXCONSTANTTABLE)object;
 
     return D3D_OK;
+
+error:
+
+    if (object)
+        HeapFree(GetProcessHeap(), 0, object->ctab);
+    HeapFree(GetProcessHeap(), 0, object);
+
+    return D3DXERR_INVALIDDATA;
 }
 
 HRESULT WINAPI D3DXGetShaderConstantTable(CONST DWORD* byte_code,
diff --git a/dlls/d3dx9_36/tests/shader.c b/dlls/d3dx9_36/tests/shader.c
index c49d089..255e84a 100644
--- a/dlls/d3dx9_36/tests/shader.c
+++ b/dlls/d3dx9_36/tests/shader.c
@@ -43,7 +43,7 @@ static const DWORD simple_ps[] = {
 static const DWORD shader_with_ctab[] = {
     0xfffe0300,                                                             /* vs_3_0                       */
     0x0002fffe, FCC_TEXT,   0x00000000,                                     /* TEXT comment                 */
-    0x0008fffe, FCC_CTAB,   0x0000001c, 0x00000000, 0xfffe0300, 0x00000000, /* CTAB comment                 */
+    0x0008fffe, FCC_CTAB,   0x0000001c, 0x00000010, 0xfffe0300, 0x00000000, /* CTAB comment                 */
                 0x00000000, 0x00000000, 0x00000000,
     0x0004fffe, FCC_TEXT,   0x00000000, 0x00000000, 0x00000000,             /* TEXT comment                 */
     0x0000ffff};                                                            /* END                          */
@@ -120,6 +120,7 @@ static void test_get_shader_constant_table_ex(void)
     HRESULT hr;
     LPVOID data;
     DWORD size;
+    D3DXCONSTANTTABLE_DESC desc;
 
     hr = D3DXGetShaderConstantTableEx(NULL, 0, &constant_table);
     ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
@@ -130,7 +131,7 @@ static void test_get_shader_constant_table_ex(void)
 
     /* With invalid CTAB data */
     hr = D3DXGetShaderConstantTableEx(shader_with_invalid_ctab, 0, &constant_table);
-    todo_wine ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
+    ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
     if (constant_table) ID3DXConstantTable_Release(constant_table);
 
     hr = D3DXGetShaderConstantTableEx(shader_with_ctab, 0, &constant_table);
@@ -144,6 +145,15 @@ static void test_get_shader_constant_table_ex(void)
         data = ID3DXConstantTable_GetBufferPointer(constant_table);
         ok(!memcmp(data, shader_with_ctab + 6, size), "Retreived wrong CTAB data\n");
 
+        hr = ID3DXConstantTable_GetDesc(constant_table, NULL);
+        ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
+
+        hr = ID3DXConstantTable_GetDesc(constant_table, &desc);
+        ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
+        ok(desc.Creator == (LPCSTR)data + 0x10, "Got result %p, expected %p\n", desc.Creator, (LPCSTR)data + 0x10);
+        ok(desc.Version == D3DVS_VERSION(3, 0), "Got result %x, expected %x\n", desc.Version, D3DVS_VERSION(3, 0));
+        ok(desc.Constants == 0, "Got result %x, expected 0\n", desc.Constants);
+
         ID3DXConstantTable_Release(constant_table);
     }
 }


More information about the wine-patches mailing list