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.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index d6b3c7aba..ed0955da0 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -104,8 +104,22 @@ std::string_view SamplerType(TextureType type, bool is_depth) {
104 104
105std::string_view ImageType(TextureType type) { 105std::string_view ImageType(TextureType type) {
106 switch (type) { 106 switch (type) {
107 case TextureType::Color1D:
108 return "uimage1D";
109 case TextureType::ColorArray1D:
110 return "uimage1DArray";
107 case TextureType::Color2D: 111 case TextureType::Color2D:
108 return "uimage2D"; 112 return "uimage2D";
113 case TextureType::ColorArray2D:
114 return "uimage2DArray";
115 case TextureType::Color3D:
116 return "uimage3D";
117 case TextureType::ColorCube:
118 return "uimageCube";
119 case TextureType::ColorArrayCube:
120 return "uimageCubeArray";
121 case TextureType::Buffer:
122 return "uimageBuffer";
109 default: 123 default:
110 throw NotImplementedException("Image type: {}", type); 124 throw NotImplementedException("Image type: {}", type);
111 } 125 }
@@ -250,6 +264,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
250 break; 264 break;
251 case Stage::Fragment: 265 case Stage::Fragment:
252 stage_name = "fs"; 266 stage_name = "fs";
267 position_name = "gl_FragCoord";
253 break; 268 break;
254 case Stage::Compute: 269 case Stage::Compute:
255 stage_name = "cs"; 270 stage_name = "cs";
@@ -449,6 +464,33 @@ void EmitContext::DefineHelperFunctions() {
449 if (info.uses_global_memory) { 464 if (info.uses_global_memory) {
450 header += DefineGlobalMemoryFunctions(); 465 header += DefineGlobalMemoryFunctions();
451 } 466 }
467 if (info.loads_indexed_attributes) {
468 const bool is_array{stage == Stage::Geometry};
469 const auto vertex_arg{is_array ? ",uint vertex" : ""};
470 std::string func{
471 fmt::format("float IndexedAttrLoad(int offset{}){{int base_index=offset>>2;uint "
472 "masked_index=uint(base_index)&3u;switch(base_index>>2){{",
473 vertex_arg)};
474 if (info.loads_position) {
475 func += fmt::format("case {}:", static_cast<u32>(IR::Attribute::PositionX) >> 2);
476 const auto position_idx{is_array ? "gl_in[vertex]." : ""};
477 func += fmt::format("return {}{}[masked_index];", position_idx, position_name);
478 }
479 const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
480 for (u32 i = 0; i < info.input_generics.size(); ++i) {
481 if (!info.input_generics[i].used) {
482 continue;
483 }
484 const auto vertex_idx{is_array ? "[vertex]" : ""};
485 func += fmt::format("case {}:", base_attribute_value + i);
486 func += fmt::format("return in_attr{}{}[masked_index];", i, vertex_idx);
487 }
488 func += "default: return 0.0;}}";
489 header += func;
490 }
491 if (info.stores_indexed_attributes) {
492 // TODO
493 }
452} 494}
453 495
454std::string EmitContext::DefineGlobalMemoryFunctions() { 496std::string EmitContext::DefineGlobalMemoryFunctions() {