glasm: Support textures used in more than one stage

This commit is contained in:
ReinUsesLisp 2021-05-18 21:04:09 -03:00 committed by ameerj
parent 3d3ed53511
commit 8b7d5912d6
4 changed files with 25 additions and 5 deletions

View File

@ -4,6 +4,7 @@
#include <string_view> #include <string_view>
#include "shader_recompiler/backend/bindings.h"
#include "shader_recompiler/backend/glasm/emit_context.h" #include "shader_recompiler/backend/glasm/emit_context.h"
#include "shader_recompiler/frontend/ir/program.h" #include "shader_recompiler/frontend/ir/program.h"
@ -22,7 +23,7 @@ std::string_view InterpDecorator(Interpolation interp) {
} }
} // Anonymous namespace } // Anonymous namespace
EmitContext::EmitContext(IR::Program& program) { EmitContext::EmitContext(IR::Program& program, Bindings& bindings) : info{program.info} {
// FIXME: Temporary partial implementation // FIXME: Temporary partial implementation
u32 cbuf_index{}; u32 cbuf_index{};
for (const auto& desc : program.info.constant_buffer_descriptors) { for (const auto& desc : program.info.constant_buffer_descriptors) {
@ -79,6 +80,13 @@ EmitContext::EmitContext(IR::Program& program) {
Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index); Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
} }
} }
const size_t num_textures{program.info.texture_descriptors.size()};
texture_bindings.resize(num_textures);
for (size_t index = 0; index < num_textures; ++index) {
const auto& desc{program.info.texture_descriptors[index]};
texture_bindings[index] = bindings.texture;
bindings.texture += desc.count;
}
} }
} // namespace Shader::Backend::GLASM } // namespace Shader::Backend::GLASM

View File

@ -6,11 +6,20 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector>
#include <fmt/format.h> #include <fmt/format.h>
#include "shader_recompiler/backend/glasm/reg_alloc.h" #include "shader_recompiler/backend/glasm/reg_alloc.h"
namespace Shader {
struct Info;
}
namespace Shader::Backend {
struct Bindings;
}
namespace Shader::IR { namespace Shader::IR {
class Inst; class Inst;
struct Program; struct Program;
@ -20,7 +29,7 @@ namespace Shader::Backend::GLASM {
class EmitContext { class EmitContext {
public: public:
explicit EmitContext(IR::Program& program); explicit EmitContext(IR::Program& program, Bindings& bindings);
template <typename... Args> template <typename... Args>
void Add(const char* format_str, IR::Inst& inst, Args&&... args) { void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
@ -45,6 +54,9 @@ public:
std::string code; std::string code;
RegAlloc reg_alloc{*this}; RegAlloc reg_alloc{*this};
const Info& info;
std::vector<u32> texture_bindings;
std::string_view stage_name = "invalid"; std::string_view stage_name = "invalid";
}; };

View File

@ -312,8 +312,8 @@ std::string_view StageHeader(Stage stage) {
} }
} // Anonymous namespace } // Anonymous namespace
std::string EmitGLASM(const Profile&, IR::Program& program, Bindings&) { std::string EmitGLASM(const Profile&, IR::Program& program, Bindings& bindings) {
EmitContext ctx{program}; EmitContext ctx{program, bindings};
Precolor(ctx, program); Precolor(ctx, program);
EmitCode(ctx, program); EmitCode(ctx, program);
std::string header{StageHeader(program.stage)}; std::string header{StageHeader(program.stage)};

View File

@ -302,7 +302,7 @@ std::unique_ptr<GraphicsProgram> ShaderCache::CreateGraphicsProgram(
const size_t stage_index{index - 1}; const size_t stage_index{index - 1};
infos[stage_index] = &program.info; infos[stage_index] = &program.info;
if (device.UseAssemblyShaders()) { if (device.UseAssemblyShaders()) {
const std::string code{EmitGLASM(profile, program)}; const std::string code{EmitGLASM(profile, program, binding)};
assembly_programs[stage_index] = CompileProgram(code, AssemblyStage(stage_index)); assembly_programs[stage_index] = CompileProgram(code, AssemblyStage(stage_index));
} else { } else {
const std::vector<u32> code{EmitSPIRV(profile, program, binding)}; const std::vector<u32> code{EmitSPIRV(profile, program, binding)};