summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-06-16 09:59:30 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:38 +0200
commit374eeda1a35f6a1dc81cf22122c701be68e89c0f (patch)
tree1155e56fffab693fe2c66ca38e6a435562c21b6d /src/shader_recompiler
parentglsl: Only declare fragment outputs on fragment shaders (diff)
downloadyuzu-374eeda1a35f6a1dc81cf22122c701be68e89c0f.tar
yuzu-374eeda1a35f6a1dc81cf22122c701be68e89c0f.tar.gz
yuzu-374eeda1a35f6a1dc81cf22122c701be68e89c0f.tar.bz2
yuzu-374eeda1a35f6a1dc81cf22122c701be68e89c0f.tar.lz
yuzu-374eeda1a35f6a1dc81cf22122c701be68e89c0f.tar.xz
yuzu-374eeda1a35f6a1dc81cf22122c701be68e89c0f.tar.zst
yuzu-374eeda1a35f6a1dc81cf22122c701be68e89c0f.zip
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp26
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.h2
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp5
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_special.cpp18
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp3
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp2
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.cpp4
-rw-r--r--src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp6
-rw-r--r--src/shader_recompiler/runtime_info.h8
-rw-r--r--src/shader_recompiler/shader_info.h2
10 files changed, 40 insertions, 36 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index bd40356a1..14c009535 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -327,11 +327,12 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
for (size_t index = 0; index < info.input_generics.size(); ++index) {
const auto& generic{info.input_generics[index]};
- if (generic.used) {
- header += fmt::format("layout(location={}){}in vec4 in_attr{}{};", index,
- InterpDecorator(generic.interpolation), index,
- InputArrayDecorator(stage));
+ if (!generic.used || !runtime_info.previous_stage_stores_generic[index]) {
+ continue;
}
+ header +=
+ fmt::format("layout(location={}){}in vec4 in_attr{}{};", index,
+ InterpDecorator(generic.interpolation), index, InputArrayDecorator(stage));
}
for (size_t index = 0; index < info.uses_patches.size(); ++index) {
if (!info.uses_patches[index]) {
@@ -349,10 +350,10 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
}
}
for (size_t index = 0; index < info.stores_generics.size(); ++index) {
- // TODO: Properly resolve attribute issues
- if (info.stores_generics[index] || StageInitializesVaryings()) {
- DefineGenericOutput(index, program.invocations);
+ if (!info.stores_generics[index]) {
+ continue;
}
+ DefineGenericOutput(index, program.invocations);
}
DefineConstantBuffers(bindings);
DefineStorageBuffers(bindings);
@@ -362,17 +363,6 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
DefineConstants();
}
-bool EmitContext::StageInitializesVaryings() const noexcept {
- switch (stage) {
- case Stage::VertexA:
- case Stage::VertexB:
- case Stage::Geometry:
- return true;
- default:
- return false;
- }
-}
-
void EmitContext::SetupExtensions() {
if (info.uses_shadow_lod && profile.support_gl_texture_shadow_lod) {
header += "#extension GL_EXT_texture_shadow_lod : enable\n";
diff --git a/src/shader_recompiler/backend/glsl/emit_context.h b/src/shader_recompiler/backend/glsl/emit_context.h
index 4a50556e1..8fa87c02c 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.h
+++ b/src/shader_recompiler/backend/glsl/emit_context.h
@@ -136,8 +136,6 @@ public:
code += '\n';
}
- [[nodiscard]] bool StageInitializesVaryings() const noexcept;
-
std::string header;
std::string code;
VarAlloc var_alloc;
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
index a241d18fe..663ff3753 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
@@ -8,6 +8,7 @@
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
#include "shader_recompiler/frontend/ir/value.h"
#include "shader_recompiler/profile.h"
+#include "shader_recompiler/runtime_info.h"
namespace Shader::Backend::GLSL {
namespace {
@@ -179,6 +180,10 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
const char swizzle{"xyzw"[element]};
if (IR::IsGeneric(attr)) {
const u32 index{IR::GenericAttributeIndex(attr)};
+ if (!ctx.runtime_info.previous_stage_stores_generic[index]) {
+ ctx.AddF32("{}=0.f;", inst, attr);
+ return;
+ }
ctx.AddF32("{}=in_attr{}{}.{};", inst, index, InputVertexIndex(ctx, vertex), swizzle);
return;
}
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
index f8e8aaa67..1a2d3dcea 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
@@ -12,11 +12,12 @@
namespace Shader::Backend::GLSL {
namespace {
-void InitializeVaryings(EmitContext& ctx) {
- ctx.Add("gl_Position=vec4(0,0,0,1);");
- // TODO: Properly resolve attribute issues
- for (size_t index = 0; index < ctx.info.stores_generics.size() / 2; ++index) {
- if (!ctx.info.stores_generics[index]) {
+void InitializeOutputVaryings(EmitContext& ctx) {
+ if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
+ ctx.Add("gl_Position=vec4(0,0,0,1);");
+ }
+ for (size_t index = 0; index < 16; ++index) {
+ if (ctx.info.stores_generics[index]) {
ctx.Add("out_attr{}=vec4(0,0,0,1);", index);
}
}
@@ -56,9 +57,8 @@ void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value&
}
void EmitPrologue(EmitContext& ctx) {
- if (ctx.StageInitializesVaryings()) {
- InitializeVaryings(ctx);
- }
+ InitializeOutputVaryings(ctx);
+
if (ctx.stage == Stage::Fragment && ctx.profile.need_declared_frag_colors) {
for (size_t index = 0; index < ctx.info.stores_frag_color.size(); ++index) {
if (ctx.info.stores_frag_color[index]) {
@@ -73,7 +73,7 @@ void EmitEpilogue(EmitContext&) {}
void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream) {
ctx.Add("EmitStreamVertex(int({}));", ctx.var_alloc.Consume(stream));
- InitializeVaryings(ctx);
+ InitializeOutputVaryings(ctx);
}
void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream) {
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index 007b79650..612d087ad 100644
--- a/src/shader_recompiler/backend/spirv/emit_context.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_context.cpp
@@ -1209,6 +1209,9 @@ void EmitContext::DefineInputs(const Info& info) {
tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord);
}
for (size_t index = 0; index < info.input_generics.size(); ++index) {
+ if (!runtime_info.previous_stage_stores_generic[index]) {
+ continue;
+ }
const InputVarying generic{info.input_generics[index]};
if (!generic.used) {
continue;
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
index 42fff74e3..4ac1fbae5 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
@@ -286,7 +286,7 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
if (IR::IsGeneric(attr)) {
const u32 index{IR::GenericAttributeIndex(attr)};
const std::optional<AttrInfo> type{AttrTypes(ctx, index)};
- if (!type) {
+ if (!type || !ctx.runtime_info.previous_stage_stores_generic[index]) {
// Attribute is disabled
return ctx.Const(0.0f);
}
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index 5250509c1..ed8729fca 100644
--- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
@@ -192,7 +192,9 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b
result.local_memory_size = std::max(vertex_a.local_memory_size, vertex_b.local_memory_size);
for (size_t index = 0; index < 32; ++index) {
result.info.input_generics[index].used |= vertex_b.info.input_generics[index].used;
- result.info.stores_generics[index] |= vertex_b.info.stores_generics[index];
+ if (vertex_b.info.stores_generics[index]) {
+ result.info.stores_generics[index] = true;
+ }
}
Optimization::JoinTextureInfo(result.info, vertex_b.info);
Optimization::JoinStorageInfo(result.info, vertex_b.info);
diff --git a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp
index 47933df97..bab32b58b 100644
--- a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp
+++ b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp
@@ -79,7 +79,7 @@ void GetAttribute(Info& info, IR::Attribute attr) {
void SetAttribute(Info& info, IR::Attribute attr) {
if (IR::IsGeneric(attr)) {
- info.stores_generics.at(IR::GenericAttributeIndex(attr)) = true;
+ info.stores_generics[IR::GenericAttributeIndex(attr)] = true;
return;
}
if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) {
@@ -956,7 +956,9 @@ void GatherInfoFromHeader(Environment& env, Info& info) {
}
if (info.stores_indexed_attributes) {
for (size_t i = 0; i < info.stores_generics.size(); i++) {
- info.stores_generics[i] |= header.vtg.IsOutputGenericVectorActive(i);
+ if (header.vtg.IsOutputGenericVectorActive(i)) {
+ info.stores_generics[i] = true;
+ }
}
info.stores_clip_distance |= header.vtg.omap_systemc.clip_distances != 0;
info.stores_position |= header.vtg.omap_systemb.position != 0;
diff --git a/src/shader_recompiler/runtime_info.h b/src/shader_recompiler/runtime_info.h
index d4b047b4d..63fe2afaf 100644
--- a/src/shader_recompiler/runtime_info.h
+++ b/src/shader_recompiler/runtime_info.h
@@ -5,6 +5,7 @@
#pragma once
#include <array>
+#include <bitset>
#include <optional>
#include <vector>
@@ -59,6 +60,8 @@ struct TransformFeedbackVarying {
struct RuntimeInfo {
std::array<AttributeType, 32> generic_input_types{};
+ std::bitset<32> previous_stage_stores_generic{};
+
bool convert_depth_mode{};
bool force_early_z{};
@@ -72,11 +75,12 @@ struct RuntimeInfo {
std::optional<CompareFunction> alpha_test_func;
float alpha_test_reference{};
- // Static y negate value
+ /// Static Y negate value
bool y_negate{};
- // Use storage buffers instead of global pointers on GLASM
+ /// Use storage buffers instead of global pointers on GLASM
bool glasm_use_storage_buffers{};
+ /// Transform feedback state for each varying
std::vector<TransformFeedbackVarying> xfb_varyings;
};
diff --git a/src/shader_recompiler/shader_info.h b/src/shader_recompiler/shader_info.h
index e9ebc16a4..a20e15d2e 100644
--- a/src/shader_recompiler/shader_info.h
+++ b/src/shader_recompiler/shader_info.h
@@ -140,7 +140,7 @@ struct Info {
bool stores_sample_mask{};
bool stores_frag_depth{};
- std::array<bool, 32> stores_generics{};
+ std::bitset<32> stores_generics{};
bool stores_layer{};
bool stores_viewport_index{};
bool stores_point_size{};