shader: Properly manage attributes not written from previous stages
This commit is contained in:
parent
892b8aa2ad
commit
374eeda1a3
12 changed files with 62 additions and 41 deletions
|
@ -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";
|
||||
|
|
|
@ -136,8 +136,6 @@ public:
|
|||
code += '\n';
|
||||
}
|
||||
|
||||
[[nodiscard]] bool StageInitializesVaryings() const noexcept;
|
||||
|
||||
std::string header;
|
||||
std::string code;
|
||||
VarAlloc var_alloc;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue