summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/backend/glsl/emit_context.cpp
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-06-08 02:39:30 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:37 +0200
commitc5422041134ed2645e7cd32152e36f9d04c66da3 (patch)
treee417bbe88e598fd74dffc576c79427ce5d268cac /src/shader_recompiler/backend/glsl/emit_context.cpp
parentglsl: Conditionally add GL_ARB_sparse_texture2 (diff)
downloadyuzu-c5422041134ed2645e7cd32152e36f9d04c66da3.tar
yuzu-c5422041134ed2645e7cd32152e36f9d04c66da3.tar.gz
yuzu-c5422041134ed2645e7cd32152e36f9d04c66da3.tar.bz2
yuzu-c5422041134ed2645e7cd32152e36f9d04c66da3.tar.lz
yuzu-c5422041134ed2645e7cd32152e36f9d04c66da3.tar.xz
yuzu-c5422041134ed2645e7cd32152e36f9d04c66da3.tar.zst
yuzu-c5422041134ed2645e7cd32152e36f9d04c66da3.zip
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) {
std::string_view ImageType(TextureType type) {
switch (type) {
+ case TextureType::Color1D:
+ return "uimage1D";
+ case TextureType::ColorArray1D:
+ return "uimage1DArray";
case TextureType::Color2D:
return "uimage2D";
+ case TextureType::ColorArray2D:
+ return "uimage2DArray";
+ case TextureType::Color3D:
+ return "uimage3D";
+ case TextureType::ColorCube:
+ return "uimageCube";
+ case TextureType::ColorArrayCube:
+ return "uimageCubeArray";
+ case TextureType::Buffer:
+ return "uimageBuffer";
default:
throw NotImplementedException("Image type: {}", type);
}
@@ -250,6 +264,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
break;
case Stage::Fragment:
stage_name = "fs";
+ position_name = "gl_FragCoord";
break;
case Stage::Compute:
stage_name = "cs";
@@ -449,6 +464,33 @@ void EmitContext::DefineHelperFunctions() {
if (info.uses_global_memory) {
header += DefineGlobalMemoryFunctions();
}
+ if (info.loads_indexed_attributes) {
+ const bool is_array{stage == Stage::Geometry};
+ const auto vertex_arg{is_array ? ",uint vertex" : ""};
+ std::string func{
+ fmt::format("float IndexedAttrLoad(int offset{}){{int base_index=offset>>2;uint "
+ "masked_index=uint(base_index)&3u;switch(base_index>>2){{",
+ vertex_arg)};
+ if (info.loads_position) {
+ func += fmt::format("case {}:", static_cast<u32>(IR::Attribute::PositionX) >> 2);
+ const auto position_idx{is_array ? "gl_in[vertex]." : ""};
+ func += fmt::format("return {}{}[masked_index];", position_idx, position_name);
+ }
+ const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
+ for (u32 i = 0; i < info.input_generics.size(); ++i) {
+ if (!info.input_generics[i].used) {
+ continue;
+ }
+ const auto vertex_idx{is_array ? "[vertex]" : ""};
+ func += fmt::format("case {}:", base_attribute_value + i);
+ func += fmt::format("return in_attr{}{}[masked_index];", i, vertex_idx);
+ }
+ func += "default: return 0.0;}}";
+ header += func;
+ }
+ if (info.stores_indexed_attributes) {
+ // TODO
+ }
}
std::string EmitContext::DefineGlobalMemoryFunctions() {