1 /**************************************************************************
3 * Copyright 2010 Luca Barbieri
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
36 #define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24 ))
37 #define FOURCC_DXBC FOURCC('D', 'X', 'B', 'C')
38 #define FOURCC_RDEF FOURCC('R', 'D', 'E', 'F')
39 #define FOURCC_ISGN FOURCC('I', 'S', 'G', 'N')
40 #define FOURCC_OSGN FOURCC('O', 'S', 'G', 'N')
41 #define FOURCC_SHDR FOURCC('S', 'H', 'D', 'R')
42 #define FOURCC_SHEX FOURCC('S', 'H', 'E', 'X')
43 #define FOURCC_STAT FOURCC('S', 'T', 'A', 'T')
45 /* this is always little-endian! */
46 struct dxbc_chunk_header
52 /* this is always little-endian! */
53 struct dxbc_chunk_signature
: public dxbc_chunk_header
60 uint32_t semantic_index
;
61 uint32_t system_value_type
;
62 uint32_t component_type
;
63 uint32_t register_num
;
65 uint8_t read_write_mask
;
66 uint8_t stream
; /* TODO: guess! */
74 std::vector
<dxbc_chunk_header
*> chunks
;
75 std::map
<unsigned, unsigned> chunk_map
;
78 struct dxbc_container_header
87 dxbc_container
* dxbc_parse(const void* data
, int size
);
88 std::ostream
& operator <<(std::ostream
& out
, const dxbc_container
& container
);
90 dxbc_chunk_header
* dxbc_find_chunk(const void* data
, int size
, unsigned fourcc
);
92 static inline dxbc_chunk_header
* dxbc_find_shader_bytecode(const void* data
, int size
)
94 dxbc_chunk_header
* chunk
;
95 chunk
= dxbc_find_chunk(data
, size
, FOURCC_SHDR
);
97 chunk
= dxbc_find_chunk(data
, size
, FOURCC_SHEX
);
101 static inline dxbc_chunk_signature
* dxbc_find_signature(const void* data
, int size
, bool output
)
103 return (dxbc_chunk_signature
*)dxbc_find_chunk(data
, size
, output
? FOURCC_OSGN
: FOURCC_ISGN
);
106 struct _D3D11_SIGNATURE_PARAMETER_DESC
;
107 typedef struct _D3D11_SIGNATURE_PARAMETER_DESC D3D11_SIGNATURE_PARAMETER_DESC
;
108 int dxbc_parse_signature(dxbc_chunk_signature
* sig
, D3D11_SIGNATURE_PARAMETER_DESC
** params
);
110 std::pair
<void*, size_t> dxbc_assemble(struct dxbc_chunk_header
** chunks
, unsigned num_chunks
);