summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/d3d1x/d3d1xshader
diff options
context:
space:
mode:
authorLuca Barbieri <[email protected]>2010-09-21 02:39:52 +0200
committerLuca Barbieri <[email protected]>2010-09-21 15:44:41 +0200
commit70fed0b0ec8a3ec4f6b9b47f1fe98cc54c6037f0 (patch)
tree915bd721659a1a3eaf7bb2705c371cbef4bd9917 /src/gallium/state_trackers/d3d1x/d3d1xshader
parent2ec86793bd43fe15d8f79d04e32d6c524e8ad844 (diff)
d3d1x: add blob and signature extraction APIs
NOTE: untested, needs a testing tool!
Diffstat (limited to 'src/gallium/state_trackers/d3d1x/d3d1xshader')
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h11
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_assemble.cpp59
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp15
3 files changed, 74 insertions, 11 deletions
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h
index 44fce810795..06a078af6ec 100644
--- a/src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h
@@ -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
index 00000000000..1021a8a1bd5
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_assemble.cpp
@@ -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);
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp
index 6b696ae1afe..4903e2c3b94 100644
--- a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp
@@ -29,26 +29,18 @@
#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;