|
|
|
@ -31,6 +31,7 @@
|
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_shader_cache.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_shader_cache.h"
|
|
|
|
|
|
|
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
|
|
|
#include "video_core/shader_cache.h"
|
|
|
|
#include "video_core/shader_cache.h"
|
|
|
|
#include "video_core/shader_environment.h"
|
|
|
|
#include "video_core/shader_environment.h"
|
|
|
|
@ -53,77 +54,6 @@ auto MakeSpan(Container& container) {
|
|
|
|
return std::span(container.data(), container.size());
|
|
|
|
return std::span(container.data(), container.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddShader(GLenum stage, GLuint program, std::span<const u32> code) {
|
|
|
|
|
|
|
|
OGLShader shader;
|
|
|
|
|
|
|
|
shader.handle = glCreateShader(stage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glShaderBinary(1, &shader.handle, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, code.data(),
|
|
|
|
|
|
|
|
static_cast<GLsizei>(code.size_bytes()));
|
|
|
|
|
|
|
|
glSpecializeShader(shader.handle, "main", 0, nullptr, nullptr);
|
|
|
|
|
|
|
|
glAttachShader(program, shader.handle);
|
|
|
|
|
|
|
|
if (!Settings::values.renderer_debug) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GLint shader_status{};
|
|
|
|
|
|
|
|
glGetShaderiv(shader.handle, GL_COMPILE_STATUS, &shader_status);
|
|
|
|
|
|
|
|
if (shader_status == GL_FALSE) {
|
|
|
|
|
|
|
|
LOG_ERROR(Render_OpenGL, "Failed to build shader");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GLint log_length{};
|
|
|
|
|
|
|
|
glGetShaderiv(shader.handle, GL_INFO_LOG_LENGTH, &log_length);
|
|
|
|
|
|
|
|
if (log_length == 0) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string log(log_length, 0);
|
|
|
|
|
|
|
|
glGetShaderInfoLog(shader.handle, log_length, nullptr, log.data());
|
|
|
|
|
|
|
|
if (shader_status == GL_FALSE) {
|
|
|
|
|
|
|
|
LOG_ERROR(Render_OpenGL, "{}", log);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "{}", log);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LinkProgram(GLuint program) {
|
|
|
|
|
|
|
|
glLinkProgram(program);
|
|
|
|
|
|
|
|
if (!Settings::values.renderer_debug) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GLint link_status{};
|
|
|
|
|
|
|
|
glGetProgramiv(program, GL_LINK_STATUS, &link_status);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLint log_length{};
|
|
|
|
|
|
|
|
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length);
|
|
|
|
|
|
|
|
if (log_length == 0) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string log(log_length, 0);
|
|
|
|
|
|
|
|
glGetProgramInfoLog(program, log_length, nullptr, log.data());
|
|
|
|
|
|
|
|
if (link_status == GL_FALSE) {
|
|
|
|
|
|
|
|
LOG_ERROR(Render_OpenGL, "{}", log);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "{}", log);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
const auto err = reinterpret_cast<const char*>(glGetString(GL_PROGRAM_ERROR_STRING_NV));
|
|
|
|
|
|
|
|
if (err && *err) {
|
|
|
|
|
|
|
|
if (std::strstr(err, "error")) {
|
|
|
|
|
|
|
|
LOG_CRITICAL(Render_OpenGL, "\n{}", err);
|
|
|
|
|
|
|
|
LOG_INFO(Render_OpenGL, "\n{}", code);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "\n{}", err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return program;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLenum Stage(size_t stage_index) {
|
|
|
|
GLenum Stage(size_t stage_index) {
|
|
|
|
switch (stage_index) {
|
|
|
|
switch (stage_index) {
|
|
|
|
case 0:
|
|
|
|
case 0:
|
|
|
|
@ -492,9 +422,8 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline(
|
|
|
|
if (!device.UseAssemblyShaders()) {
|
|
|
|
if (!device.UseAssemblyShaders()) {
|
|
|
|
source_program.handle = glCreateProgram();
|
|
|
|
source_program.handle = glCreateProgram();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t first_index = uses_vertex_a && uses_vertex_b ? 1 : 0;
|
|
|
|
for (size_t index = uses_vertex_a && uses_vertex_b ? 1 : 0; index < Maxwell::MaxShaderProgram;
|
|
|
|
for (size_t index = first_index; index < Maxwell::MaxShaderProgram; ++index) {
|
|
|
|
++index) {
|
|
|
|
|
|
|
|
if (key.unique_hashes[index] == 0) {
|
|
|
|
if (key.unique_hashes[index] == 0) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -510,7 +439,7 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline(
|
|
|
|
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, runtime_info, program, binding)};
|
|
|
|
const std::vector<u32> code{EmitSPIRV(profile, runtime_info, program, binding)};
|
|
|
|
AddShader(Stage(stage_index), source_program.handle, code);
|
|
|
|
AttachShader(Stage(stage_index), source_program.handle, code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!device.UseAssemblyShaders()) {
|
|
|
|
if (!device.UseAssemblyShaders()) {
|
|
|
|
@ -565,7 +494,7 @@ std::unique_ptr<ComputePipeline> ShaderCache::CreateComputePipeline(ShaderPools&
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const std::vector<u32> code{EmitSPIRV(profile, program)};
|
|
|
|
const std::vector<u32> code{EmitSPIRV(profile, program)};
|
|
|
|
source_program.handle = glCreateProgram();
|
|
|
|
source_program.handle = glCreateProgram();
|
|
|
|
AddShader(GL_COMPUTE_SHADER, source_program.handle, code);
|
|
|
|
AttachShader(GL_COMPUTE_SHADER, source_program.handle, code);
|
|
|
|
LinkProgram(source_program.handle);
|
|
|
|
LinkProgram(source_program.handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::make_unique<ComputePipeline>(device, texture_cache, buffer_cache, gpu_memory,
|
|
|
|
return std::make_unique<ComputePipeline>(device, texture_cache, buffer_cache, gpu_memory,
|
|
|
|
|