d3d1x: add blob and signature extraction APIs
authorLuca Barbieri <luca@luca-barbieri.com>
Tue, 21 Sep 2010 00:39:52 +0000 (02:39 +0200)
committerLuca Barbieri <luca@luca-barbieri.com>
Tue, 21 Sep 2010 13:44:41 +0000 (15:44 +0200)
NOTE: untested, needs a testing tool!

src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h
src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_assemble.cpp [new file with mode: 0644]
src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp
src/gallium/state_trackers/d3d1x/d3d1xstutil/include/d3d1xstutil.h
src/gallium/state_trackers/d3d1x/d3dapi/d3dcommon.idl
src/gallium/state_trackers/d3d1x/gd3d10/Makefile
src/gallium/state_trackers/d3d1x/gd3d11/d3d11.cpp

index 44fce8107959d4468196bb6fce48ee6caa6f8a65..06a078af6ec4b6a3f64f030231fba744b0e402cc 100644 (file)
@@ -75,6 +75,15 @@ struct dxbc_container
        std::map<unsigned, unsigned> chunk_map;
 };
 
+struct dxbc_container_header
+{
+       unsigned fourcc;
+       uint32_t unk[4];
+       uint32_t one;
+       uint32_t total_size;
+       uint32_t chunk_count;
+};
+
 dxbc_container* dxbc_parse(const void* data, int size);
 std::ostream& operator <<(std::ostream& out, const dxbc_container& container);
 
@@ -98,4 +107,6 @@ struct _D3D11_SIGNATURE_PARAMETER_DESC;
 typedef struct _D3D11_SIGNATURE_PARAMETER_DESC D3D11_SIGNATURE_PARAMETER_DESC;
 int dxbc_parse_signature(dxbc_chunk_signature* sig, D3D11_SIGNATURE_PARAMETER_DESC** params);
 
+std::pair<void*, size_t> dxbc_assemble(struct dxbc_chunk_header** chunks, unsigned num_chunks);
+
 #endif /* DXBC_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_assemble.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_assemble.cpp
new file mode 100644 (file)
index 0000000..1021a8a
--- /dev/null
@@ -0,0 +1,59 @@
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include "dxbc.h"
+
+std::pair<void*, size_t> dxbc_assemble(struct dxbc_chunk_header** chunks, unsigned num_chunks)
+{
+       size_t data_size = 0;
+       for(unsigned i = 0; i < num_chunks; ++i)
+               data_size += sizeof(uint32_t) + sizeof(dxbc_chunk_header) + bswap_le32(chunks[i]->size);
+
+       size_t total_size = sizeof(dxbc_container_header) + data_size;
+       dxbc_container_header* header = (dxbc_container_header*)malloc(total_size);
+       if(!header)
+               return std::make_pair((void*)0, 0);
+
+       header->fourcc = bswap_le32(FOURCC_DXBC);
+       memset(header->unk, 0, sizeof(header->unk));
+       header->one = bswap_le32(1);
+       header->total_size = bswap_le32(total_size);
+       header->chunk_count = num_chunks;
+
+       uint32_t* chunk_offsets = (uint32_t*)(header + 1);
+       uint32_t off = sizeof(struct dxbc_container_header) + num_chunks * sizeof(uint32_t);
+       for(unsigned i = 0; i < num_chunks; ++i)
+       {
+               chunk_offsets[i] = bswap_le32(off);
+               unsigned chunk_full_size = sizeof(dxbc_chunk_header) + bswap_le32(chunks[i]->size);
+               memcpy((char*)header + off, chunks[i], chunk_full_size);
+               off += chunk_full_size;
+       }
+
+       return std::make_pair((void*)header, total_size);
+}
index 6b696ae1afec805fe0e1b5a738ff6d0ea7441c6c..4903e2c3b941bff8c96eb9962b3d876cee7392a2 100644 (file)
 #include <d3d11shader.h>
 #include <d3dcommon.h>
 
-struct dxbc_container_header
-{
-       unsigned fourcc;
-       uint32_t unk[5];
-       uint32_t total_size;
-       uint32_t chunk_count;
-       uint32_t chunk_offsets[];
-};
-
 dxbc_container* dxbc_parse(const void* data, int size)
 {
        std::auto_ptr<dxbc_container> container(new dxbc_container());
        container->data = data;
        dxbc_container_header* header = (dxbc_container_header*)data;
+       uint32_t* chunk_offsets = (uint32_t*)(header + 1);
        if(bswap_le32(header->fourcc) != FOURCC_DXBC)
                return 0;
        unsigned num_chunks = bswap_le32(header->chunk_count);
        for(unsigned i = 0; i < num_chunks; ++i)
        {
-               unsigned offset = bswap_le32(header->chunk_offsets[i]);
+               unsigned offset = bswap_le32(chunk_offsets[i]);
                dxbc_chunk_header* chunk = (dxbc_chunk_header*)((char*)data + offset);
                unsigned fourcc = bswap_le32(chunk->fourcc);
                container->chunk_map[fourcc] = i;
@@ -60,12 +52,13 @@ dxbc_container* dxbc_parse(const void* data, int size)
 dxbc_chunk_header* dxbc_find_chunk(const void* data, int size, unsigned fourcc)
 {
        dxbc_container_header* header = (dxbc_container_header*)data;
+       uint32_t* chunk_offsets = (uint32_t*)(header + 1);
        if(bswap_le32(header->fourcc) != FOURCC_DXBC)
                return 0;
        unsigned num_chunks = bswap_le32(header->chunk_count);
        for(unsigned i = 0; i < num_chunks; ++i)
        {
-               unsigned offset = bswap_le32(header->chunk_offsets[i]);
+               unsigned offset = bswap_le32(chunk_offsets[i]);
                dxbc_chunk_header* chunk = (dxbc_chunk_header*)((char*)data + offset);
                if(bswap_le32(chunk->fourcc) == fourcc)
                        return chunk;
index a9260acdbab10ae929743394dddef0f4f06ec201..47bf842b7b1187826f5f766152c00e0706fbdbb0 100644 (file)
@@ -59,6 +59,7 @@ namespace std
        { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
 
 #include "galliumdxgi.h"
+#include <d3dcommon.h>
 
 extern "C"
 {
@@ -1035,4 +1036,37 @@ struct GalliumDXGIDevice : public GalliumMultiPrivateDataComObject<Base, IDXGIDe
         }
 };
 
+COM_INTERFACE(ID3D10Blob, IUnknown);
+
+/* NOTE: ID3DBlob implementations may come from a Microsoft native DLL
+ * (e.g. d3dcompiler), or perhaps even from the application itself.
+ *
+ * Hence, never try to access the data/size members directly, which is why they are private.
+ * In internal code, use std::pair<void*, size_t> instead of this class.
+ */
+class GalliumD3DBlob : public GalliumComObject<ID3DBlob>
+{
+       void* data;
+       size_t size;
+
+       GalliumD3DBlob(void* data, size_t size)
+       : data(data), size(size)
+       {}
+
+       ~GalliumD3DBlob()
+       {
+               free(data);
+       }
+public:
+       virtual LPVOID STDMETHODCALLTYPE GetBufferPointer()
+       {
+               return data;
+       }
+
+       virtual SIZE_T STDMETHODCALLTYPE GetBufferSize()
+       {
+               return size;
+       }
+};
+
 #endif /* D3D1XSTUTIL_H_ */
index 3594bf58f8c05e5e022ae188f90429f73271d6de..71021b8a6c04d886a71d3f296ceb8ea61a8a044c 100644 (file)
@@ -314,6 +314,10 @@ interface ID3D10Blob : IUnknown
        SIZE_T GetBufferSize();
 };
 
+typedef ID3D10Blob* LPD3D10BLOB;
+typedef ID3D10Blob ID3DBlob;
+typedef ID3DBlob* LPD3DBLOB;
+
 typedef enum _D3D_INCLUDE_TYPE
 {
        D3D_INCLUDE_LOCAL = 0,
index c6cfea25ea2de3e5e72661eda712fb34beccf27c..300149d384ebc30b20f05eb14380f8278e8a0033 100644 (file)
@@ -6,7 +6,7 @@ GEN_D3D10=perl d3d10.pl
 
 include ../Makefile.inc
 
-d3d10.generated.o: d3d10_objects.generated.h d3d10_screen.generated.h d3d10_context.generated.h
+d3d10.generated.o: d3d10_objects.generated.h d3d10_screen.generated.h d3d10_context.generated.h d3d10_misc.generated.h
  
 d3d10.generated.cpp: ../gd3d11/d3d11.cpp d3d10.pl
        $(GEN_D3D10) $< > $@
@@ -16,4 +16,5 @@ d3d10_screen.generated.h: ../gd3d11/d3d11_screen.h d3d10.pl
        $(GEN_D3D10) $< > $@
 d3d10_context.generated.h: ../gd3d11/d3d11_context.h d3d10.pl
        $(GEN_D3D10) $< > $@
-
+d3d10_misc.generated.h: ../gd3d11/d3d11_misc.h d3d10.pl
+       $(GEN_D3D10) $< > $@
index 22cbf150fe110763ed5b4c070de15a1056f435a8..69dfd403f3d9f648f986006870183a330789caea 100644 (file)
@@ -214,6 +214,7 @@ struct GalliumD3D11Screen
 #include "d3d11_objects.h"
 #include "d3d11_screen.h"
 #include "d3d11_context.h"
+#include "d3d11_misc.h"
 
 #if API >= 11
 HRESULT STDMETHODCALLTYPE GalliumD3D11DeviceCreate(struct pipe_screen* screen, struct pipe_context* context, BOOL owns_context, unsigned creation_flags, IDXGIAdapter* adapter, ID3D11Device** ppDevice)