2018-08-23 23:30:27 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-02-26 20:13:47 +01:00
|
|
|
#include <atomic>
|
|
|
|
#include <functional>
|
2019-04-06 22:59:56 +02:00
|
|
|
#include <mutex>
|
2019-09-25 04:34:18 +02:00
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2019-04-06 22:59:56 +02:00
|
|
|
#include <thread>
|
2019-09-25 04:34:18 +02:00
|
|
|
#include <unordered_set>
|
2020-02-26 20:13:47 +01:00
|
|
|
|
2019-11-13 03:39:45 +01:00
|
|
|
#include "common/alignment.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "common/assert.h"
|
2019-11-13 03:39:45 +01:00
|
|
|
#include "common/logging/log.h"
|
2019-04-06 22:59:56 +02:00
|
|
|
#include "common/scope_exit.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "core/core.h"
|
2019-04-06 22:59:56 +02:00
|
|
|
#include "core/frontend/emu_window.h"
|
2021-05-08 21:34:41 +02:00
|
|
|
#include "shader_recompiler/backend/glasm/emit_glasm.h"
|
2021-05-23 09:28:34 +02:00
|
|
|
#include "shader_recompiler/backend/spirv/emit_spirv.h"
|
|
|
|
#include "shader_recompiler/frontend/ir/program.h"
|
|
|
|
#include "shader_recompiler/frontend/maxwell/control_flow.h"
|
|
|
|
#include "shader_recompiler/frontend/maxwell/program.h"
|
|
|
|
#include "shader_recompiler/profile.h"
|
2019-09-23 21:40:58 +02:00
|
|
|
#include "video_core/engines/kepler_compute.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2019-11-18 22:35:21 +01:00
|
|
|
#include "video_core/engines/shader_type.h"
|
2019-04-06 05:59:54 +02:00
|
|
|
#include "video_core/memory_manager.h"
|
2018-11-08 12:08:00 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
2020-08-24 02:23:54 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_cache.h"
|
2019-12-29 06:03:05 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
2020-05-23 01:55:38 +02:00
|
|
|
#include "video_core/shader_cache.h"
|
2021-05-23 09:28:34 +02:00
|
|
|
#include "video_core/shader_environment.h"
|
2020-07-10 05:36:38 +02:00
|
|
|
#include "video_core/shader_notify.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
|
|
|
|
namespace OpenGL {
|
2021-05-23 09:28:34 +02:00
|
|
|
namespace {
|
2021-05-08 21:34:41 +02:00
|
|
|
using Shader::Backend::GLASM::EmitGLASM;
|
2021-05-23 09:28:34 +02:00
|
|
|
using Shader::Backend::SPIRV::EmitSPIRV;
|
|
|
|
using Shader::Maxwell::TranslateProgram;
|
|
|
|
using VideoCommon::ComputeEnvironment;
|
|
|
|
using VideoCommon::GraphicsEnvironment;
|
|
|
|
|
|
|
|
template <typename Container>
|
|
|
|
auto MakeSpan(Container& container) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 21:34:41 +02:00
|
|
|
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());
|
2021-05-22 01:36:30 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2021-05-08 21:34:41 +02:00
|
|
|
}
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
2021-05-23 09:28:34 +02:00
|
|
|
GLenum Stage(size_t stage_index) {
|
|
|
|
switch (stage_index) {
|
|
|
|
case 0:
|
|
|
|
return GL_VERTEX_SHADER;
|
|
|
|
case 1:
|
|
|
|
return GL_TESS_CONTROL_SHADER;
|
|
|
|
case 2:
|
|
|
|
return GL_TESS_EVALUATION_SHADER;
|
|
|
|
case 3:
|
|
|
|
return GL_GEOMETRY_SHADER;
|
|
|
|
case 4:
|
|
|
|
return GL_FRAGMENT_SHADER;
|
|
|
|
}
|
|
|
|
UNREACHABLE_MSG("{}", stage_index);
|
|
|
|
return GL_NONE;
|
|
|
|
}
|
2021-05-15 23:19:08 +02:00
|
|
|
|
|
|
|
GLenum AssemblyStage(size_t stage_index) {
|
|
|
|
switch (stage_index) {
|
|
|
|
case 0:
|
|
|
|
return GL_VERTEX_PROGRAM_NV;
|
|
|
|
case 1:
|
|
|
|
return GL_TESS_CONTROL_PROGRAM_NV;
|
|
|
|
case 2:
|
|
|
|
return GL_TESS_EVALUATION_PROGRAM_NV;
|
|
|
|
case 3:
|
|
|
|
return GL_GEOMETRY_PROGRAM_NV;
|
|
|
|
case 4:
|
|
|
|
return GL_FRAGMENT_PROGRAM_NV;
|
|
|
|
}
|
|
|
|
UNREACHABLE_MSG("{}", stage_index);
|
|
|
|
return GL_NONE;
|
|
|
|
}
|
2021-05-21 07:57:52 +02:00
|
|
|
|
|
|
|
Shader::RuntimeInfo MakeRuntimeInfo(const GraphicsProgramKey& key,
|
|
|
|
const Shader::IR::Program& program) {
|
|
|
|
UNIMPLEMENTED_IF_MSG(key.xfb_enabled != 0, "Transform feedbacks");
|
|
|
|
|
|
|
|
Shader::RuntimeInfo info;
|
|
|
|
switch (program.stage) {
|
|
|
|
case Shader::Stage::TessellationEval:
|
|
|
|
// We have to flip tessellation clockwise for some reason...
|
|
|
|
info.tess_clockwise = key.tessellation_clockwise == 0;
|
|
|
|
info.tess_primitive = [&key] {
|
|
|
|
switch (key.tessellation_primitive) {
|
|
|
|
case Maxwell::TessellationPrimitive::Isolines:
|
|
|
|
return Shader::TessPrimitive::Isolines;
|
|
|
|
case Maxwell::TessellationPrimitive::Triangles:
|
|
|
|
return Shader::TessPrimitive::Triangles;
|
|
|
|
case Maxwell::TessellationPrimitive::Quads:
|
|
|
|
return Shader::TessPrimitive::Quads;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return Shader::TessPrimitive::Triangles;
|
|
|
|
}();
|
|
|
|
info.tess_spacing = [&] {
|
|
|
|
switch (key.tessellation_spacing) {
|
|
|
|
case Maxwell::TessellationSpacing::Equal:
|
|
|
|
return Shader::TessSpacing::Equal;
|
|
|
|
case Maxwell::TessellationSpacing::FractionalOdd:
|
|
|
|
return Shader::TessSpacing::FractionalOdd;
|
|
|
|
case Maxwell::TessellationSpacing::FractionalEven:
|
|
|
|
return Shader::TessSpacing::FractionalEven;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return Shader::TessSpacing::Equal;
|
|
|
|
}();
|
|
|
|
break;
|
2021-05-21 23:27:37 +02:00
|
|
|
case Shader::Stage::Fragment:
|
|
|
|
info.force_early_z = key.early_z != 0;
|
2021-05-21 07:57:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (key.gs_input_topology) {
|
|
|
|
case Maxwell::PrimitiveTopology::Points:
|
|
|
|
info.input_topology = Shader::InputTopology::Points;
|
|
|
|
break;
|
|
|
|
case Maxwell::PrimitiveTopology::Lines:
|
|
|
|
case Maxwell::PrimitiveTopology::LineLoop:
|
|
|
|
case Maxwell::PrimitiveTopology::LineStrip:
|
|
|
|
info.input_topology = Shader::InputTopology::Lines;
|
|
|
|
break;
|
|
|
|
case Maxwell::PrimitiveTopology::Triangles:
|
|
|
|
case Maxwell::PrimitiveTopology::TriangleStrip:
|
|
|
|
case Maxwell::PrimitiveTopology::TriangleFan:
|
|
|
|
case Maxwell::PrimitiveTopology::Quads:
|
|
|
|
case Maxwell::PrimitiveTopology::QuadStrip:
|
|
|
|
case Maxwell::PrimitiveTopology::Polygon:
|
|
|
|
case Maxwell::PrimitiveTopology::Patches:
|
|
|
|
info.input_topology = Shader::InputTopology::Triangles;
|
|
|
|
break;
|
|
|
|
case Maxwell::PrimitiveTopology::LinesAdjacency:
|
|
|
|
case Maxwell::PrimitiveTopology::LineStripAdjacency:
|
|
|
|
info.input_topology = Shader::InputTopology::LinesAdjacency;
|
|
|
|
break;
|
|
|
|
case Maxwell::PrimitiveTopology::TrianglesAdjacency:
|
|
|
|
case Maxwell::PrimitiveTopology::TriangleStripAdjacency:
|
|
|
|
info.input_topology = Shader::InputTopology::TrianglesAdjacency;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
2021-05-21 23:17:53 +02:00
|
|
|
|
|
|
|
void SetXfbState(VideoCommon::TransformFeedbackState& state, const Maxwell& regs) {
|
|
|
|
std::ranges::transform(regs.tfb_layouts, state.layouts.begin(), [](const auto& layout) {
|
|
|
|
return VideoCommon::TransformFeedbackState::Layout{
|
|
|
|
.stream = layout.stream,
|
|
|
|
.varying_count = layout.varying_count,
|
|
|
|
.stride = layout.stride,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
state.varyings = regs.tfb_varying_locs;
|
|
|
|
}
|
2021-05-23 09:28:34 +02:00
|
|
|
} // Anonymous namespace
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2021-04-26 08:53:26 +02:00
|
|
|
ShaderCache::ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindow& emu_window_,
|
2021-05-23 09:28:34 +02:00
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d_,
|
2021-04-26 08:53:26 +02:00
|
|
|
Tegra::Engines::KeplerCompute& kepler_compute_,
|
2021-05-23 09:28:34 +02:00
|
|
|
Tegra::MemoryManager& gpu_memory_, const Device& device_,
|
|
|
|
TextureCache& texture_cache_, BufferCache& buffer_cache_,
|
|
|
|
ProgramManager& program_manager_, StateTracker& state_tracker_)
|
2021-04-26 08:53:26 +02:00
|
|
|
: VideoCommon::ShaderCache{rasterizer_, gpu_memory_, maxwell3d_, kepler_compute_},
|
2021-05-23 09:28:34 +02:00
|
|
|
emu_window{emu_window_}, device{device_}, texture_cache{texture_cache_},
|
|
|
|
buffer_cache{buffer_cache_}, program_manager{program_manager_}, state_tracker{
|
2021-05-22 01:46:40 +02:00
|
|
|
state_tracker_} {
|
|
|
|
profile = Shader::Profile{
|
|
|
|
.supported_spirv = 0x00010000,
|
|
|
|
|
|
|
|
.unified_descriptor_binding = false,
|
|
|
|
.support_descriptor_aliasing = false,
|
|
|
|
.support_int8 = false,
|
|
|
|
.support_int16 = false,
|
|
|
|
.support_vertex_instance_id = true,
|
|
|
|
.support_float_controls = false,
|
|
|
|
.support_separate_denorm_behavior = false,
|
|
|
|
.support_separate_rounding_mode = false,
|
|
|
|
.support_fp16_denorm_preserve = false,
|
|
|
|
.support_fp32_denorm_preserve = false,
|
|
|
|
.support_fp16_denorm_flush = false,
|
|
|
|
.support_fp32_denorm_flush = false,
|
|
|
|
.support_fp16_signed_zero_nan_preserve = false,
|
|
|
|
.support_fp32_signed_zero_nan_preserve = false,
|
|
|
|
.support_fp64_signed_zero_nan_preserve = false,
|
|
|
|
.support_explicit_workgroup_layout = false,
|
|
|
|
.support_vote = true,
|
|
|
|
.support_viewport_index_layer_non_geometry =
|
|
|
|
device.HasNvViewportArray2() || device.HasVertexViewportLayer(),
|
2021-05-22 01:47:48 +02:00
|
|
|
.support_viewport_mask = device.HasNvViewportArray2(),
|
2021-05-22 01:46:40 +02:00
|
|
|
.support_typeless_image_loads = device.HasImageLoadFormatted(),
|
|
|
|
.support_demote_to_helper_invocation = false,
|
|
|
|
.support_int64_atomics = false,
|
|
|
|
|
|
|
|
.warp_size_potentially_larger_than_guest = true,
|
|
|
|
.lower_left_origin_mode = true,
|
|
|
|
|
|
|
|
.has_broken_spirv_clamp = true,
|
|
|
|
.has_broken_unsigned_image_offsets = true,
|
|
|
|
.has_broken_signed_operations = true,
|
|
|
|
.ignore_nan_fp_comparisons = true,
|
|
|
|
};
|
|
|
|
}
|
2021-04-26 08:53:26 +02:00
|
|
|
|
|
|
|
ShaderCache::~ShaderCache() = default;
|
2019-01-14 04:58:15 +01:00
|
|
|
|
2021-05-23 09:28:34 +02:00
|
|
|
GraphicsProgram* ShaderCache::CurrentGraphicsProgram() {
|
|
|
|
if (!RefreshStages(graphics_key.unique_hashes)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto& regs{maxwell3d.regs};
|
|
|
|
graphics_key.raw = 0;
|
|
|
|
graphics_key.early_z.Assign(regs.force_early_fragment_tests != 0 ? 1 : 0);
|
|
|
|
graphics_key.gs_input_topology.Assign(graphics_key.unique_hashes[4] != 0
|
|
|
|
? regs.draw.topology.Value()
|
|
|
|
: Maxwell::PrimitiveTopology{});
|
|
|
|
graphics_key.tessellation_primitive.Assign(regs.tess_mode.prim.Value());
|
|
|
|
graphics_key.tessellation_spacing.Assign(regs.tess_mode.spacing.Value());
|
|
|
|
graphics_key.tessellation_clockwise.Assign(regs.tess_mode.cw.Value());
|
2021-05-21 23:17:53 +02:00
|
|
|
graphics_key.xfb_enabled.Assign(regs.tfb_enabled != 0 ? 1 : 0);
|
|
|
|
if (graphics_key.xfb_enabled) {
|
|
|
|
SetXfbState(graphics_key.xfb_state, regs);
|
|
|
|
}
|
2021-05-23 09:28:34 +02:00
|
|
|
const auto [pair, is_new]{graphics_cache.try_emplace(graphics_key)};
|
|
|
|
auto& program{pair->second};
|
|
|
|
if (is_new) {
|
|
|
|
program = CreateGraphicsProgram();
|
|
|
|
}
|
|
|
|
return program.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
ComputeProgram* ShaderCache::CurrentComputeProgram() {
|
|
|
|
const VideoCommon::ShaderInfo* const shader{ComputeShader()};
|
|
|
|
if (!shader) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto& qmd{kepler_compute.launch_description};
|
|
|
|
const ComputeProgramKey key{
|
|
|
|
.unique_hash = shader->unique_hash,
|
|
|
|
.shared_memory_size = qmd.shared_alloc,
|
|
|
|
.workgroup_size{qmd.block_dim_x, qmd.block_dim_y, qmd.block_dim_z},
|
|
|
|
};
|
|
|
|
const auto [pair, is_new]{compute_cache.try_emplace(key)};
|
|
|
|
auto& pipeline{pair->second};
|
|
|
|
if (!is_new) {
|
|
|
|
return pipeline.get();
|
|
|
|
}
|
|
|
|
pipeline = CreateComputeProgram(key, shader);
|
|
|
|
return pipeline.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<GraphicsProgram> ShaderCache::CreateGraphicsProgram() {
|
|
|
|
GraphicsEnvironments environments;
|
|
|
|
GetGraphicsEnvironments(environments, graphics_key.unique_hashes);
|
|
|
|
|
|
|
|
main_pools.ReleaseContents();
|
|
|
|
return CreateGraphicsProgram(main_pools, graphics_key, environments.Span(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<GraphicsProgram> ShaderCache::CreateGraphicsProgram(
|
|
|
|
ShaderPools& pools, const GraphicsProgramKey& key, std::span<Shader::Environment* const> envs,
|
|
|
|
bool build_in_parallel) {
|
|
|
|
LOG_INFO(Render_OpenGL, "0x{:016x}", key.Hash());
|
|
|
|
size_t env_index{0};
|
|
|
|
std::array<Shader::IR::Program, Maxwell::MaxShaderProgram> programs;
|
|
|
|
for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) {
|
|
|
|
if (key.unique_hashes[index] == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Shader::Environment& env{*envs[env_index]};
|
|
|
|
++env_index;
|
|
|
|
|
|
|
|
const u32 cfg_offset{static_cast<u32>(env.StartAddress() + sizeof(Shader::ProgramHeader))};
|
|
|
|
Shader::Maxwell::Flow::CFG cfg(env, pools.flow_block, cfg_offset);
|
|
|
|
programs[index] = TranslateProgram(pools.inst, pools.block, env, cfg);
|
|
|
|
}
|
|
|
|
std::array<const Shader::Info*, Maxwell::MaxShaderStage> infos{};
|
|
|
|
|
2021-05-15 23:19:08 +02:00
|
|
|
OGLProgram source_program;
|
|
|
|
std::array<OGLAssemblyProgram, 5> assembly_programs;
|
2021-05-04 01:53:00 +02:00
|
|
|
Shader::Backend::Bindings binding;
|
2021-05-15 23:19:08 +02:00
|
|
|
if (!device.UseAssemblyShaders()) {
|
|
|
|
source_program.handle = glCreateProgram();
|
|
|
|
}
|
2021-05-23 09:28:34 +02:00
|
|
|
for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) {
|
|
|
|
if (key.unique_hashes[index] == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
UNIMPLEMENTED_IF(index == 0);
|
|
|
|
|
|
|
|
Shader::IR::Program& program{programs[index]};
|
|
|
|
const size_t stage_index{index - 1};
|
|
|
|
infos[stage_index] = &program.info;
|
2021-05-21 07:57:52 +02:00
|
|
|
|
|
|
|
const Shader::RuntimeInfo runtime_info{MakeRuntimeInfo(key, program)};
|
2021-05-15 23:19:08 +02:00
|
|
|
if (device.UseAssemblyShaders()) {
|
2021-05-21 07:57:52 +02:00
|
|
|
const std::string code{EmitGLASM(profile, runtime_info, program, binding)};
|
2021-05-15 23:19:08 +02:00
|
|
|
assembly_programs[stage_index] = CompileProgram(code, AssemblyStage(stage_index));
|
|
|
|
} else {
|
2021-05-21 07:57:52 +02:00
|
|
|
const std::vector<u32> code{EmitSPIRV(profile, runtime_info, program, binding)};
|
2021-05-15 23:19:08 +02:00
|
|
|
AddShader(Stage(stage_index), source_program.handle, code);
|
|
|
|
}
|
2021-05-23 09:28:34 +02:00
|
|
|
}
|
2021-05-15 23:19:08 +02:00
|
|
|
if (!device.UseAssemblyShaders()) {
|
|
|
|
LinkProgram(source_program.handle);
|
|
|
|
}
|
|
|
|
return std::make_unique<GraphicsProgram>(
|
|
|
|
texture_cache, buffer_cache, gpu_memory, maxwell3d, program_manager, state_tracker,
|
2021-05-21 23:17:53 +02:00
|
|
|
std::move(source_program), std::move(assembly_programs), infos,
|
|
|
|
key.xfb_enabled != 0 ? &key.xfb_state : nullptr);
|
2021-05-23 09:28:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<ComputeProgram> ShaderCache::CreateComputeProgram(
|
|
|
|
const ComputeProgramKey& key, const VideoCommon::ShaderInfo* shader) {
|
|
|
|
const GPUVAddr program_base{kepler_compute.regs.code_loc.Address()};
|
|
|
|
const auto& qmd{kepler_compute.launch_description};
|
|
|
|
ComputeEnvironment env{kepler_compute, gpu_memory, program_base, qmd.program_start};
|
|
|
|
env.SetCachedSize(shader->size_bytes);
|
|
|
|
|
|
|
|
main_pools.ReleaseContents();
|
|
|
|
return CreateComputeProgram(main_pools, key, env, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<ComputeProgram> ShaderCache::CreateComputeProgram(ShaderPools& pools,
|
|
|
|
const ComputeProgramKey& key,
|
|
|
|
Shader::Environment& env,
|
|
|
|
bool build_in_parallel) {
|
|
|
|
LOG_INFO(Render_OpenGL, "0x{:016x}", key.Hash());
|
|
|
|
|
|
|
|
Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()};
|
|
|
|
Shader::IR::Program program{TranslateProgram(pools.inst, pools.block, env, cfg)};
|
2021-05-08 21:34:41 +02:00
|
|
|
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);
|
|
|
|
}
|
2021-05-23 09:28:34 +02:00
|
|
|
return std::make_unique<ComputeProgram>(texture_cache, buffer_cache, gpu_memory, kepler_compute,
|
2021-05-08 21:34:41 +02:00
|
|
|
program_manager, program.info,
|
|
|
|
std::move(source_program), std::move(asm_program));
|
2021-05-23 09:28:34 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 23:19:28 +02:00
|
|
|
} // namespace OpenGL
|