summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index 14c009535..0d7f7bc3b 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -212,22 +212,22 @@ std::string_view OutputPrimitive(OutputTopology topology) {
212} 212}
213 213
214void SetupLegacyOutPerVertex(EmitContext& ctx, std::string& header) { 214void SetupLegacyOutPerVertex(EmitContext& ctx, std::string& header) {
215 if (!ctx.info.stores_legacy_varyings) { 215 if (!ctx.info.stores.Legacy()) {
216 return; 216 return;
217 } 217 }
218 if (ctx.info.stores_fixed_fnc_textures) { 218 if (ctx.info.stores.FixedFunctionTexture()) {
219 header += "vec4 gl_TexCoord[8];"; 219 header += "vec4 gl_TexCoord[8];";
220 } 220 }
221 if (ctx.info.stores_color_front_diffuse) { 221 if (ctx.info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
222 header += "vec4 gl_FrontColor;"; 222 header += "vec4 gl_FrontColor;";
223 } 223 }
224 if (ctx.info.stores_color_front_specular) { 224 if (ctx.info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
225 header += "vec4 gl_FrontSecondaryColor;"; 225 header += "vec4 gl_FrontSecondaryColor;";
226 } 226 }
227 if (ctx.info.stores_color_back_diffuse) { 227 if (ctx.info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
228 header += "vec4 gl_BackColor;"; 228 header += "vec4 gl_BackColor;";
229 } 229 }
230 if (ctx.info.stores_color_back_specular) { 230 if (ctx.info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
231 header += "vec4 gl_BackSecondaryColor;"; 231 header += "vec4 gl_BackSecondaryColor;";
232 } 232 }
233} 233}
@@ -237,32 +237,32 @@ void SetupOutPerVertex(EmitContext& ctx, std::string& header) {
237 return; 237 return;
238 } 238 }
239 header += "out gl_PerVertex{vec4 gl_Position;"; 239 header += "out gl_PerVertex{vec4 gl_Position;";
240 if (ctx.info.stores_point_size) { 240 if (ctx.info.stores[IR::Attribute::PointSize]) {
241 header += "float gl_PointSize;"; 241 header += "float gl_PointSize;";
242 } 242 }
243 if (ctx.info.stores_clip_distance) { 243 if (ctx.info.stores.ClipDistances()) {
244 header += "float gl_ClipDistance[];"; 244 header += "float gl_ClipDistance[];";
245 } 245 }
246 if (ctx.info.stores_viewport_index && ctx.profile.support_viewport_index_layer_non_geometry && 246 if (ctx.info.stores[IR::Attribute::ViewportIndex] &&
247 ctx.stage != Stage::Geometry) { 247 ctx.profile.support_viewport_index_layer_non_geometry && ctx.stage != Stage::Geometry) {
248 header += "int gl_ViewportIndex;"; 248 header += "int gl_ViewportIndex;";
249 } 249 }
250 SetupLegacyOutPerVertex(ctx, header); 250 SetupLegacyOutPerVertex(ctx, header);
251 header += "};"; 251 header += "};";
252 if (ctx.info.stores_viewport_index && ctx.stage == Stage::Geometry) { 252 if (ctx.info.stores[IR::Attribute::ViewportIndex] && ctx.stage == Stage::Geometry) {
253 header += "out int gl_ViewportIndex;"; 253 header += "out int gl_ViewportIndex;";
254 } 254 }
255} 255}
256 256
257void SetupLegacyInPerFragment(EmitContext& ctx, std::string& header) { 257void SetupLegacyInPerFragment(EmitContext& ctx, std::string& header) {
258 if (!ctx.info.loads_legacy_varyings) { 258 if (!ctx.info.loads.Legacy()) {
259 return; 259 return;
260 } 260 }
261 header += "in gl_PerFragment{"; 261 header += "in gl_PerFragment{";
262 if (ctx.info.loads_fixed_fnc_textures) { 262 if (ctx.info.loads.FixedFunctionTexture()) {
263 header += "vec4 gl_TexCoord[8];"; 263 header += "vec4 gl_TexCoord[8];";
264 } 264 }
265 if (ctx.info.loads_color_front_diffuse) { 265 if (ctx.info.loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
266 header += "vec4 gl_Color;"; 266 header += "vec4 gl_Color;";
267 } 267 }
268 header += "};"; 268 header += "};";
@@ -325,14 +325,13 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
325 SetupOutPerVertex(*this, header); 325 SetupOutPerVertex(*this, header);
326 SetupLegacyInPerFragment(*this, header); 326 SetupLegacyInPerFragment(*this, header);
327 327
328 for (size_t index = 0; index < info.input_generics.size(); ++index) { 328 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
329 const auto& generic{info.input_generics[index]}; 329 if (!info.loads.Generic(index) || !runtime_info.previous_stage_stores.Generic(index)) {
330 if (!generic.used || !runtime_info.previous_stage_stores_generic[index]) {
331 continue; 330 continue;
332 } 331 }
333 header += 332 header += fmt::format("layout(location={}){}in vec4 in_attr{}{};", index,
334 fmt::format("layout(location={}){}in vec4 in_attr{}{};", index, 333 InterpDecorator(info.interpolation[index]), index,
335 InterpDecorator(generic.interpolation), index, InputArrayDecorator(stage)); 334 InputArrayDecorator(stage));
336 } 335 }
337 for (size_t index = 0; index < info.uses_patches.size(); ++index) { 336 for (size_t index = 0; index < info.uses_patches.size(); ++index) {
338 if (!info.uses_patches[index]) { 337 if (!info.uses_patches[index]) {
@@ -349,11 +348,10 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
349 header += fmt::format("layout(location={})out vec4 frag_color{};", index, index); 348 header += fmt::format("layout(location={})out vec4 frag_color{};", index, index);
350 } 349 }
351 } 350 }
352 for (size_t index = 0; index < info.stores_generics.size(); ++index) { 351 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
353 if (!info.stores_generics[index]) { 352 if (info.stores.Generic(index)) {
354 continue; 353 DefineGenericOutput(index, program.invocations);
355 } 354 }
356 DefineGenericOutput(index, program.invocations);
357 } 355 }
358 DefineConstantBuffers(bindings); 356 DefineConstantBuffers(bindings);
359 DefineStorageBuffers(bindings); 357 DefineStorageBuffers(bindings);
@@ -398,14 +396,14 @@ void EmitContext::SetupExtensions() {
398 header += "#extension GL_NV_shader_thread_shuffle : enable\n"; 396 header += "#extension GL_NV_shader_thread_shuffle : enable\n";
399 } 397 }
400 } 398 }
401 if ((info.stores_viewport_index || info.stores_layer) && 399 if ((info.stores[IR::Attribute::ViewportIndex] || info.stores[IR::Attribute::Layer]) &&
402 profile.support_viewport_index_layer_non_geometry && stage != Stage::Geometry) { 400 profile.support_viewport_index_layer_non_geometry && stage != Stage::Geometry) {
403 header += "#extension GL_ARB_shader_viewport_layer_array : enable\n"; 401 header += "#extension GL_ARB_shader_viewport_layer_array : enable\n";
404 } 402 }
405 if (info.uses_sparse_residency && profile.support_gl_sparse_textures) { 403 if (info.uses_sparse_residency && profile.support_gl_sparse_textures) {
406 header += "#extension GL_ARB_sparse_texture2 : enable\n"; 404 header += "#extension GL_ARB_sparse_texture2 : enable\n";
407 } 405 }
408 if (info.stores_viewport_mask && profile.support_viewport_mask) { 406 if (info.stores[IR::Attribute::ViewportMask] && profile.support_viewport_mask) {
409 header += "#extension GL_NV_viewport_array2 : enable\n"; 407 header += "#extension GL_NV_viewport_array2 : enable\n";
410 } 408 }
411 if (info.uses_typeless_image_reads) { 409 if (info.uses_typeless_image_reads) {
@@ -535,20 +533,20 @@ void EmitContext::DefineHelperFunctions() {
535 fmt::format("float IndexedAttrLoad(int offset{}){{int base_index=offset>>2;uint " 533 fmt::format("float IndexedAttrLoad(int offset{}){{int base_index=offset>>2;uint "
536 "masked_index=uint(base_index)&3u;switch(base_index>>2){{", 534 "masked_index=uint(base_index)&3u;switch(base_index>>2){{",
537 vertex_arg)}; 535 vertex_arg)};
538 if (info.loads_position) { 536 if (info.loads.AnyComponent(IR::Attribute::PositionX)) {
539 const auto position_idx{is_array ? "gl_in[vertex]." : ""}; 537 const auto position_idx{is_array ? "gl_in[vertex]." : ""};
540 func += fmt::format("case {}:return {}{}[masked_index];", 538 func += fmt::format("case {}:return {}{}[masked_index];",
541 static_cast<u32>(IR::Attribute::PositionX) >> 2, position_idx, 539 static_cast<u32>(IR::Attribute::PositionX) >> 2, position_idx,
542 position_name); 540 position_name);
543 } 541 }
544 const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2; 542 const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
545 for (u32 i = 0; i < info.input_generics.size(); ++i) { 543 for (u32 index = 0; index < IR::NUM_GENERICS; ++index) {
546 if (!info.input_generics[i].used) { 544 if (!info.loads.Generic(index)) {
547 continue; 545 continue;
548 } 546 }
549 const auto vertex_idx{is_array ? "[vertex]" : ""}; 547 const auto vertex_idx{is_array ? "[vertex]" : ""};
550 func += fmt::format("case {}:return in_attr{}{}[masked_index];", 548 func += fmt::format("case {}:return in_attr{}{}[masked_index];",
551 base_attribute_value + i, i, vertex_idx); 549 base_attribute_value + index, index, vertex_idx);
552 } 550 }
553 func += "default: return 0.0;}}"; 551 func += "default: return 0.0;}}";
554 header += func; 552 header += func;