1
0
Fork 1
forked from suyu/suyu

glasm: Initial GLASM compute implementation for testing

This commit is contained in:
ReinUsesLisp 2021-05-08 16:34:41 -03:00 committed by ameerj
parent 6fd190d1ae
commit 2c81ad8311
3 changed files with 47 additions and 14 deletions

View file

@ -29,11 +29,11 @@ bool ComputeProgramKey::operator==(const ComputeProgramKey& rhs) const noexcept
ComputeProgram::ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_,
Tegra::MemoryManager& gpu_memory_,
Tegra::Engines::KeplerCompute& kepler_compute_,
ProgramManager& program_manager_, OGLProgram program_,
const Shader::Info& info_)
ProgramManager& program_manager_, const Shader::Info& info_,
OGLProgram source_program_, OGLAssemblyProgram assembly_program_)
: texture_cache{texture_cache_}, buffer_cache{buffer_cache_}, gpu_memory{gpu_memory_},
kepler_compute{kepler_compute_},
program_manager{program_manager_}, program{std::move(program_)}, info{info_} {
kepler_compute{kepler_compute_}, program_manager{program_manager_}, info{info_},
source_program{std::move(source_program_)}, assembly_program{std::move(assembly_program_)} {
for (const auto& desc : info.texture_buffer_descriptors) {
num_texture_buffers += desc.count;
}
@ -124,6 +124,14 @@ void ComputeProgram::Configure() {
const std::span indices_span(image_view_indices.data(), image_view_indices.size());
texture_cache.FillComputeImageViews(indices_span, image_view_ids);
if (assembly_program.handle != 0) {
// FIXME: State track this
glEnable(GL_COMPUTE_PROGRAM_NV);
glBindProgramARB(GL_COMPUTE_PROGRAM_NV, assembly_program.handle);
program_manager.BindProgram(0);
} else {
program_manager.BindProgram(source_program.handle);
}
buffer_cache.UnbindComputeTextureBuffers();
size_t texbuf_index{};
const auto add_buffer{[&](const auto& desc) {
@ -172,7 +180,6 @@ void ComputeProgram::Configure() {
if (image_binding != 0) {
glBindImageTextures(0, image_binding, images.data());
}
program_manager.BindProgram(program.handle);
}
} // namespace OpenGL

View file

@ -52,8 +52,8 @@ public:
explicit ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_,
Tegra::MemoryManager& gpu_memory_,
Tegra::Engines::KeplerCompute& kepler_compute_,
ProgramManager& program_manager_, OGLProgram program_,
const Shader::Info& info_);
ProgramManager& program_manager_, const Shader::Info& info_,
OGLProgram source_program_, OGLAssemblyProgram assembly_program_);
void Configure();
@ -64,8 +64,9 @@ private:
Tegra::Engines::KeplerCompute& kepler_compute;
ProgramManager& program_manager;
OGLProgram program;
Shader::Info info;
OGLProgram source_program;
OGLAssemblyProgram assembly_program;
u32 num_texture_buffers{};
u32 num_image_buffers{};

View file

@ -16,6 +16,7 @@
#include "common/scope_exit.h"
#include "core/core.h"
#include "core/frontend/emu_window.h"
#include "shader_recompiler/backend/glasm/emit_glasm.h"
#include "shader_recompiler/backend/spirv/emit_spirv.h"
#include "shader_recompiler/frontend/ir/program.h"
#include "shader_recompiler/frontend/maxwell/control_flow.h"
@ -89,6 +90,7 @@ const Shader::Profile profile{
.xfb_varyings = {},
};
using Shader::Backend::GLASM::EmitGLASM;
using Shader::Backend::SPIRV::EmitSPIRV;
using Shader::Maxwell::TranslateProgram;
using VideoCommon::ComputeEnvironment;
@ -151,6 +153,22 @@ void LinkProgram(GLuint program) {
}
}
OGLAssemblyProgram CompileProgram(std::string_view code, GLenum target) {
OGLAssemblyProgram program;
glGenProgramsARB(1, &program.handle);
glNamedProgramStringEXT(program.handle, target, GL_PROGRAM_FORMAT_ASCII_ARB,
static_cast<GLsizei>(code.size()), code.data());
if (!Settings::values.renderer_debug) {
return program;
}
const auto err = reinterpret_cast<const char*>(glGetString(GL_PROGRAM_ERROR_STRING_NV));
if (err && *err) {
LOG_CRITICAL(Render_OpenGL, "{}", err);
LOG_INFO(Render_OpenGL, "{}", code);
}
return program;
}
GLenum Stage(size_t stage_index) {
switch (stage_index) {
case 0:
@ -294,13 +312,20 @@ std::unique_ptr<ComputeProgram> ShaderCache::CreateComputeProgram(ShaderPools& p
Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()};
Shader::IR::Program program{TranslateProgram(pools.inst, pools.block, env, cfg)};
const std::vector<u32> code{EmitSPIRV(profile, program)};
OGLProgram gl_program;
gl_program.handle = glCreateProgram();
AddShader(GL_COMPUTE_SHADER, gl_program.handle, code);
LinkProgram(gl_program.handle);
OGLAssemblyProgram asm_program;
OGLProgram source_program;
if (device.UseAssemblyShaders()) {
const std::string code{EmitGLASM(profile, program)};
asm_program = CompileProgram(code, GL_COMPUTE_PROGRAM_NV);
} else {
const std::vector<u32> code{EmitSPIRV(profile, program)};
source_program.handle = glCreateProgram();
AddShader(GL_COMPUTE_SHADER, source_program.handle, code);
LinkProgram(source_program.handle);
}
return std::make_unique<ComputeProgram>(texture_cache, buffer_cache, gpu_memory, kepler_compute,
program_manager, std::move(gl_program), program.info);
program_manager, program.info,
std::move(source_program), std::move(asm_program));
}
} // namespace OpenGL