44fce8107959d4468196bb6fce48ee6caa6f8a65
[mesa.git] / src / gallium / state_trackers / d3d1x / d3d1xshader / include / dxbc.h
1 /**************************************************************************
2 *
3 * Copyright 2010 Luca Barbieri
4 *
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:
12 *
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.
16 *
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.
24 *
25 **************************************************************************/
26
27 #ifndef DXBC_H_
28 #define DXBC_H_
29
30 #include <stdint.h>
31 #include <vector>
32 #include <map>
33 #include <iostream>
34 #include "le32.h"
35
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')
44
45 /* this is always little-endian! */
46 struct dxbc_chunk_header
47 {
48 unsigned fourcc;
49 unsigned size;
50 };
51
52 /* this is always little-endian! */
53 struct dxbc_chunk_signature : public dxbc_chunk_header
54 {
55 uint32_t count;
56 uint32_t unk;
57 struct
58 {
59 uint32_t name_offset;
60 uint32_t semantic_index;
61 uint32_t system_value_type;
62 uint32_t component_type;
63 uint32_t register_num;
64 uint8_t mask;
65 uint8_t read_write_mask;
66 uint8_t stream; /* TODO: guess! */
67 uint8_t unused;
68 } elements[];
69 };
70
71 struct dxbc_container
72 {
73 const void* data;
74 std::vector<dxbc_chunk_header*> chunks;
75 std::map<unsigned, unsigned> chunk_map;
76 };
77
78 dxbc_container* dxbc_parse(const void* data, int size);
79 std::ostream& operator <<(std::ostream& out, const dxbc_container& container);
80
81 dxbc_chunk_header* dxbc_find_chunk(const void* data, int size, unsigned fourcc);
82
83 static inline dxbc_chunk_header* dxbc_find_shader_bytecode(const void* data, int size)
84 {
85 dxbc_chunk_header* chunk;
86 chunk = dxbc_find_chunk(data, size, FOURCC_SHDR);
87 if(!chunk)
88 chunk = dxbc_find_chunk(data, size, FOURCC_SHEX);
89 return chunk;
90 }
91
92 static inline dxbc_chunk_signature* dxbc_find_signature(const void* data, int size, bool output)
93 {
94 return (dxbc_chunk_signature*)dxbc_find_chunk(data, size, output ? FOURCC_OSGN : FOURCC_ISGN);
95 }
96
97 struct _D3D11_SIGNATURE_PARAMETER_DESC;
98 typedef struct _D3D11_SIGNATURE_PARAMETER_DESC D3D11_SIGNATURE_PARAMETER_DESC;
99 int dxbc_parse_signature(dxbc_chunk_signature* sig, D3D11_SIGNATURE_PARAMETER_DESC** params);
100
101 #endif /* DXBC_H_ */