Matteo Bruni : d3dx9: Use the ID3DXInclude object to open the initial file in D3DX[ Assemble|Compile|Preprocess]ShaderFromFile.

Alexandre Julliard julliard at winehq.org
Tue Sep 3 13:38:04 CDT 2013


Module: wine
Branch: master
Commit: 613d27ebebd30d559c6bbb7b8c233b8f59cacb28
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=613d27ebebd30d559c6bbb7b8c233b8f59cacb28

Author: Matteo Bruni <mbruni at codeweavers.com>
Date:   Tue Sep  3 16:29:43 2013 +0200

d3dx9: Use the ID3DXInclude object to open the initial file in D3DX[Assemble|Compile|Preprocess]ShaderFromFile.

---

 dlls/d3dx9_36/shader.c |   64 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c
index 6edbc33..41be22c 100644
--- a/dlls/d3dx9_36/shader.c
+++ b/dlls/d3dx9_36/shader.c
@@ -306,27 +306,38 @@ HRESULT WINAPI D3DXAssembleShaderFromFileA(const char *filename, const D3DXMACRO
 HRESULT WINAPI D3DXAssembleShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
         ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
 {
-    void *buffer;
+    const void *buffer;
     DWORD len;
     HRESULT hr;
     struct D3DXIncludeImpl includefromfile;
+    char *filename_a;
 
     TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
             debugstr_w(filename), defines, include, flags, shader, error_messages);
 
-    if(FAILED(map_view_of_file(filename, &buffer, &len)))
-        return D3DXERR_INVALIDDATA;
-
     if(!include)
     {
         includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
         include = &includefromfile.ID3DXInclude_iface;
     }
 
-    hr = D3DXAssembleShader(buffer, len, defines, include, flags,
-                            shader, error_messages);
+    len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
+    filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
+    if (!filename_a)
+        return E_OUTOFMEMORY;
+    WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
 
-    UnmapViewOfFile(buffer);
+    hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
+    if (FAILED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, filename_a);
+        return D3DXERR_INVALIDDATA;
+    }
+
+    hr = D3DXAssembleShader(buffer, len, defines, include, flags, shader, error_messages);
+
+    ID3DXInclude_Close(include, buffer);
+    HeapFree(GetProcessHeap(), 0, filename_a);
     return hr;
 }
 
@@ -425,7 +436,7 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
         ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
         ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
 {
-    void *buffer;
+    const void *buffer;
     DWORD len, filename_len;
     HRESULT hr;
     struct D3DXIncludeImpl includefromfile;
@@ -436,9 +447,6 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
             debugstr_w(filename), defines, include, debugstr_a(entrypoint), debugstr_a(profile),
             flags, shader, error_messages, constant_table);
 
-    if (FAILED(map_view_of_file(filename, &buffer, &len)))
-        return D3DXERR_INVALIDDATA;
-
     if (!include)
     {
         includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
@@ -448,12 +456,16 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
     filename_len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
     filename_a = HeapAlloc(GetProcessHeap(), 0, filename_len * sizeof(char));
     if (!filename_a)
-    {
-        UnmapViewOfFile(buffer);
         return E_OUTOFMEMORY;
-    }
     WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, filename_len, NULL, NULL);
 
+    hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
+    if (FAILED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, filename_a);
+        return D3DXERR_INVALIDDATA;
+    }
+
     hr = D3DCompile(buffer, len, filename_a, (const D3D_SHADER_MACRO *)defines,
                     (ID3DInclude *)include, entrypoint, profile, flags, 0,
                     (ID3DBlob **)shader, (ID3DBlob **)error_messages);
@@ -462,8 +474,8 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
         hr = D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader),
                                         constant_table);
 
+    ID3DXInclude_Close(include, buffer);
     HeapFree(GetProcessHeap(), 0, filename_a);
-    UnmapViewOfFile(buffer);
     return hr;
 }
 
@@ -546,29 +558,41 @@ HRESULT WINAPI D3DXPreprocessShaderFromFileA(const char *filename, const D3DXMAC
 HRESULT WINAPI D3DXPreprocessShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
         ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
 {
-    void *buffer;
+    const void *buffer;
     DWORD len;
     HRESULT hr;
     struct D3DXIncludeImpl includefromfile;
+    char *filename_a;
 
     TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
             debugstr_w(filename), defines, include, shader, error_messages);
 
-    if (FAILED(map_view_of_file(filename, &buffer, &len)))
-        return D3DXERR_INVALIDDATA;
-
     if (!include)
     {
         includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
         include = &includefromfile.ID3DXInclude_iface;
     }
 
+    len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
+    filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
+    if (!filename_a)
+        return E_OUTOFMEMORY;
+    WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
+
+    hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
+    if (FAILED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, filename_a);
+        return D3DXERR_INVALIDDATA;
+    }
+
     hr = D3DPreprocess(buffer, len, NULL,
                        (const D3D_SHADER_MACRO *)defines,
                        (ID3DInclude *) include,
                        (ID3DBlob **)shader, (ID3DBlob **)error_messages);
 
-    UnmapViewOfFile(buffer);
+    ID3DXInclude_Close(include, buffer);
+    HeapFree(GetProcessHeap(), 0, filename_a);
     return hr;
 }
 




More information about the wine-cvs mailing list