summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/program_header.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/program_header.h')
-rw-r--r--src/shader_recompiler/program_header.h219
1 files changed, 219 insertions, 0 deletions
diff --git a/src/shader_recompiler/program_header.h b/src/shader_recompiler/program_header.h
new file mode 100644
index 000000000..bd6c2bfb5
--- /dev/null
+++ b/src/shader_recompiler/program_header.h
@@ -0,0 +1,219 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <optional>
9
10#include "common/bit_field.h"
11#include "common/common_funcs.h"
12#include "common/common_types.h"
13
14namespace Shader {
15
16enum class OutputTopology : u32 {
17 PointList = 1,
18 LineStrip = 6,
19 TriangleStrip = 7,
20};
21
22enum class PixelImap : u8 {
23 Unused = 0,
24 Constant = 1,
25 Perspective = 2,
26 ScreenLinear = 3,
27};
28
29// Documentation in:
30// http://download.nvidia.com/open-gpu-doc/Shader-Program-Header/1/Shader-Program-Header.html
31struct ProgramHeader {
32 union {
33 BitField<0, 5, u32> sph_type;
34 BitField<5, 5, u32> version;
35 BitField<10, 4, u32> shader_type;
36 BitField<14, 1, u32> mrt_enable;
37 BitField<15, 1, u32> kills_pixels;
38 BitField<16, 1, u32> does_global_store;
39 BitField<17, 4, u32> sass_version;
40 BitField<21, 2, u32> reserved1;
41 BitField<24, 1, u32> geometry_passthrough;
42 BitField<25, 1, u32> reserved2;
43 BitField<26, 1, u32> does_load_or_store;
44 BitField<27, 1, u32> does_fp64;
45 BitField<28, 4, u32> stream_out_mask;
46 } common0;
47
48 union {
49 BitField<0, 24, u32> shader_local_memory_low_size;
50 BitField<24, 8, u32> per_patch_attribute_count;
51 } common1;
52
53 union {
54 BitField<0, 24, u32> shader_local_memory_high_size;
55 BitField<24, 8, u32> threads_per_input_primitive;
56 } common2;
57
58 union {
59 BitField<0, 24, u32> shader_local_memory_crs_size;
60 BitField<24, 4, OutputTopology> output_topology;
61 BitField<28, 4, u32> reserved;
62 } common3;
63
64 union {
65 BitField<0, 12, u32> max_output_vertices;
66 BitField<12, 8, u32> store_req_start; // NOTE: not used by geometry shaders.
67 BitField<20, 4, u32> reserved;
68 BitField<24, 8, u32> store_req_end; // NOTE: not used by geometry shaders.
69 } common4;
70
71 union {
72 struct {
73 INSERT_PADDING_BYTES_NOINIT(3); // ImapSystemValuesA
74
75 union {
76 BitField<0, 1, u8> primitive_array_id;
77 BitField<1, 1, u8> rt_array_index;
78 BitField<2, 1, u8> viewport_index;
79 BitField<3, 1, u8> point_size;
80 BitField<4, 1, u8> position_x;
81 BitField<5, 1, u8> position_y;
82 BitField<6, 1, u8> position_z;
83 BitField<7, 1, u8> position_w;
84 u8 raw;
85 } imap_systemb;
86
87 std::array<u8, 16> imap_generic_vector;
88
89 INSERT_PADDING_BYTES_NOINIT(2); // ImapColor
90 union {
91 BitField<0, 8, u16> clip_distances;
92 BitField<8, 1, u16> point_sprite_s;
93 BitField<9, 1, u16> point_sprite_t;
94 BitField<10, 1, u16> fog_coordinate;
95 BitField<12, 1, u16> tessellation_eval_point_u;
96 BitField<13, 1, u16> tessellation_eval_point_v;
97 BitField<14, 1, u16> instance_id;
98 BitField<15, 1, u16> vertex_id;
99 };
100 INSERT_PADDING_BYTES_NOINIT(5); // ImapFixedFncTexture[10]
101 INSERT_PADDING_BYTES_NOINIT(1); // ImapReserved
102 INSERT_PADDING_BYTES_NOINIT(3); // OmapSystemValuesA
103
104 union {
105 BitField<0, 1, u8> primitive_array_id;
106 BitField<1, 1, u8> rt_array_index;
107 BitField<2, 1, u8> viewport_index;
108 BitField<3, 1, u8> point_size;
109 BitField<4, 1, u8> position_x;
110 BitField<5, 1, u8> position_y;
111 BitField<6, 1, u8> position_z;
112 BitField<7, 1, u8> position_w;
113 u8 raw;
114 } omap_systemb;
115
116 std::array<u8, 16> omap_generic_vector;
117
118 INSERT_PADDING_BYTES_NOINIT(2); // OmapColor
119
120 union {
121 BitField<0, 8, u16> clip_distances;
122 BitField<8, 1, u16> point_sprite_s;
123 BitField<9, 1, u16> point_sprite_t;
124 BitField<10, 1, u16> fog_coordinate;
125 BitField<12, 1, u16> tessellation_eval_point_u;
126 BitField<13, 1, u16> tessellation_eval_point_v;
127 BitField<14, 1, u16> instance_id;
128 BitField<15, 1, u16> vertex_id;
129 } omap_systemc;
130
131 INSERT_PADDING_BYTES_NOINIT(5); // OmapFixedFncTexture[10]
132 INSERT_PADDING_BYTES_NOINIT(1); // OmapReserved
133
134 [[nodiscard]] std::array<bool, 4> InputGeneric(size_t index) const noexcept {
135 const int data{imap_generic_vector[index >> 1] >> ((index % 2) * 4)};
136 return {
137 (data & 1) != 0,
138 (data & 2) != 0,
139 (data & 4) != 0,
140 (data & 8) != 0,
141 };
142 }
143
144 [[nodiscard]] std::array<bool, 4> OutputGeneric(size_t index) const noexcept {
145 const int data{omap_generic_vector[index >> 1] >> ((index % 2) * 4)};
146 return {
147 (data & 1) != 0,
148 (data & 2) != 0,
149 (data & 4) != 0,
150 (data & 8) != 0,
151 };
152 }
153 } vtg;
154
155 struct {
156 INSERT_PADDING_BYTES_NOINIT(3); // ImapSystemValuesA
157
158 union {
159 BitField<0, 1, u8> primitive_array_id;
160 BitField<1, 1, u8> rt_array_index;
161 BitField<2, 1, u8> viewport_index;
162 BitField<3, 1, u8> point_size;
163 BitField<4, 1, u8> position_x;
164 BitField<5, 1, u8> position_y;
165 BitField<6, 1, u8> position_z;
166 BitField<7, 1, u8> position_w;
167 BitField<0, 4, u8> first;
168 BitField<4, 4, u8> position;
169 u8 raw;
170 } imap_systemb;
171
172 union {
173 BitField<0, 2, PixelImap> x;
174 BitField<2, 2, PixelImap> y;
175 BitField<4, 2, PixelImap> z;
176 BitField<6, 2, PixelImap> w;
177 u8 raw;
178 } imap_generic_vector[32];
179
180 INSERT_PADDING_BYTES_NOINIT(2); // ImapColor
181 INSERT_PADDING_BYTES_NOINIT(2); // ImapSystemValuesC
182 INSERT_PADDING_BYTES_NOINIT(10); // ImapFixedFncTexture[10]
183 INSERT_PADDING_BYTES_NOINIT(2); // ImapReserved
184
185 struct {
186 u32 target;
187 union {
188 BitField<0, 1, u32> sample_mask;
189 BitField<1, 1, u32> depth;
190 BitField<2, 30, u32> reserved;
191 };
192 } omap;
193
194 [[nodiscard]] std::array<bool, 4> EnabledOutputComponents(u32 rt) const noexcept {
195 const u32 bits{omap.target >> (rt * 4)};
196 return {(bits & 1) != 0, (bits & 2) != 0, (bits & 4) != 0, (bits & 8) != 0};
197 }
198
199 [[nodiscard]] std::array<PixelImap, 4> GenericInputMap(u32 attribute) const {
200 const auto& vector{imap_generic_vector[attribute]};
201 return {vector.x, vector.y, vector.z, vector.w};
202 }
203
204 [[nodiscard]] bool IsGenericVectorActive(size_t index) const {
205 return imap_generic_vector[index].raw != 0;
206 }
207 } ps;
208
209 std::array<u32, 0xf> raw;
210 };
211
212 [[nodiscard]] u64 LocalMemorySize() const noexcept {
213 return static_cast<u64>(common1.shader_local_memory_low_size) |
214 (static_cast<u64>(common2.shader_local_memory_high_size) << 24);
215 }
216};
217static_assert(sizeof(ProgramHeader) == 0x50, "Incorrect structure size");
218
219} // namespace Shader