gl_device: Implement interface and add uniform offset alignment

This commit is contained in:
ReinUsesLisp 2019-04-10 15:56:12 -03:00
parent 97648f4841
commit 0032821864
5 changed files with 70 additions and 13 deletions

View File

@ -36,6 +36,8 @@ add_library(video_core STATIC
renderer_base.h renderer_base.h
renderer_opengl/gl_buffer_cache.cpp renderer_opengl/gl_buffer_cache.cpp
renderer_opengl/gl_buffer_cache.h renderer_opengl/gl_buffer_cache.h
renderer_opengl/gl_device.cpp
renderer_opengl/gl_device.h
renderer_opengl/gl_global_cache.cpp renderer_opengl/gl_global_cache.cpp
renderer_opengl/gl_global_cache.h renderer_opengl/gl_global_cache.h
renderer_opengl/gl_primitive_assembler.cpp renderer_opengl/gl_primitive_assembler.cpp

View File

@ -0,0 +1,27 @@
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <cstddef>
#include <glad/glad.h>
#include "video_core/renderer_opengl/gl_device.h"
namespace OpenGL {
namespace {
template <typename T>
T GetInteger(GLenum pname) {
GLint temporary;
glGetIntegerv(pname, &temporary);
return static_cast<T>(temporary);
}
} // Anonymous namespace
Device::Device() = default;
void Device::Initialize() {
uniform_buffer_alignment = GetInteger<std::size_t>(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT);
}
} // namespace OpenGL

View File

@ -0,0 +1,25 @@
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <cstddef>
namespace OpenGL {
class Device {
public:
Device();
void Initialize();
std::size_t GetUniformBufferAlignment() const {
return uniform_buffer_alignment;
}
private:
std::size_t uniform_buffer_alignment{};
};
} // namespace OpenGL

View File

@ -107,14 +107,14 @@ RasterizerOpenGL::RasterizerOpenGL(Core::System& system, ScreenInfo& info)
state.texture_units[i].sampler = texture_samplers[i].sampler.handle; state.texture_units[i].sampler = texture_samplers[i].sampler.handle;
} }
device.Initialize();
OpenGLState::ApplyDefaultState(); OpenGLState::ApplyDefaultState();
shader_program_manager = std::make_unique<GLShader::ProgramManager>(); shader_program_manager = std::make_unique<GLShader::ProgramManager>();
state.draw.shader_program = 0; state.draw.shader_program = 0;
state.Apply(); state.Apply();
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &uniform_buffer_alignment);
LOG_DEBUG(Render_OpenGL, "Sync fixed function OpenGL state here"); LOG_DEBUG(Render_OpenGL, "Sync fixed function OpenGL state here");
CheckExtensions(); CheckExtensions();
} }
@ -321,8 +321,8 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) {
GLShader::MaxwellUniformData ubo{}; GLShader::MaxwellUniformData ubo{};
ubo.SetFromRegs(gpu, stage); ubo.SetFromRegs(gpu, stage);
const GLintptr offset = buffer_cache.UploadHostMemory( const GLintptr offset =
&ubo, sizeof(ubo), static_cast<std::size_t>(uniform_buffer_alignment)); buffer_cache.UploadHostMemory(&ubo, sizeof(ubo), device.GetUniformBufferAlignment());
// Bind the emulation info buffer // Bind the emulation info buffer
bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), offset, bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), offset,
@ -706,23 +706,24 @@ void RasterizerOpenGL::DrawArrays() {
// Add space for index buffer (keeping in mind non-core primitives) // Add space for index buffer (keeping in mind non-core primitives)
switch (regs.draw.topology) { switch (regs.draw.topology) {
case Maxwell::PrimitiveTopology::Quads: case Maxwell::PrimitiveTopology::Quads:
buffer_size = Common::AlignUp<std::size_t>(buffer_size, 4) + buffer_size = Common::AlignUp(buffer_size, 4) +
primitive_assembler.CalculateQuadSize(regs.vertex_buffer.count); primitive_assembler.CalculateQuadSize(regs.vertex_buffer.count);
break; break;
default: default:
if (is_indexed) { if (is_indexed) {
buffer_size = Common::AlignUp<std::size_t>(buffer_size, 4) + CalculateIndexBufferSize(); buffer_size = Common::AlignUp(buffer_size, 4) + CalculateIndexBufferSize();
} }
break; break;
} }
// Uniform space for the 5 shader stages // Uniform space for the 5 shader stages
buffer_size = buffer_size = Common::AlignUp<std::size_t>(buffer_size, 4) +
Common::AlignUp<std::size_t>(buffer_size, 4) + (sizeof(GLShader::MaxwellUniformData) + device.GetUniformBufferAlignment()) *
(sizeof(GLShader::MaxwellUniformData) + uniform_buffer_alignment) * Maxwell::MaxShaderStage; Maxwell::MaxShaderStage;
// Add space for at least 18 constant buffers // Add space for at least 18 constant buffers
buffer_size += Maxwell::MaxConstBuffers * (MaxConstbufferSize + uniform_buffer_alignment); buffer_size +=
Maxwell::MaxConstBuffers * (MaxConstbufferSize + device.GetUniformBufferAlignment());
const bool invalidate = buffer_cache.Map(buffer_size); const bool invalidate = buffer_cache.Map(buffer_size);
if (invalidate) { if (invalidate) {
@ -939,8 +940,8 @@ void RasterizerOpenGL::SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::Shader
size = Common::AlignUp(size, sizeof(GLvec4)); size = Common::AlignUp(size, sizeof(GLvec4));
ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big"); ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big");
const GLintptr const_buffer_offset = buffer_cache.UploadMemory( const GLintptr const_buffer_offset =
buffer.address, size, static_cast<std::size_t>(uniform_buffer_alignment)); buffer_cache.UploadMemory(buffer.address, size, device.GetUniformBufferAlignment());
bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), const_buffer_offset, size); bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), const_buffer_offset, size);
} }

View File

@ -21,6 +21,7 @@
#include "video_core/rasterizer_cache.h" #include "video_core/rasterizer_cache.h"
#include "video_core/rasterizer_interface.h" #include "video_core/rasterizer_interface.h"
#include "video_core/renderer_opengl/gl_buffer_cache.h" #include "video_core/renderer_opengl/gl_buffer_cache.h"
#include "video_core/renderer_opengl/gl_device.h"
#include "video_core/renderer_opengl/gl_global_cache.h" #include "video_core/renderer_opengl/gl_global_cache.h"
#include "video_core/renderer_opengl/gl_primitive_assembler.h" #include "video_core/renderer_opengl/gl_primitive_assembler.h"
#include "video_core/renderer_opengl/gl_rasterizer_cache.h" #include "video_core/renderer_opengl/gl_rasterizer_cache.h"
@ -213,6 +214,8 @@ private:
ScreenInfo& screen_info; ScreenInfo& screen_info;
Device device;
std::unique_ptr<GLShader::ProgramManager> shader_program_manager; std::unique_ptr<GLShader::ProgramManager> shader_program_manager;
std::map<std::array<Tegra::Engines::Maxwell3D::Regs::VertexAttribute, std::map<std::array<Tegra::Engines::Maxwell3D::Regs::VertexAttribute,
Tegra::Engines::Maxwell3D::Regs::NumVertexAttributes>, Tegra::Engines::Maxwell3D::Regs::NumVertexAttributes>,
@ -228,7 +231,6 @@ private:
static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024; static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024;
OGLBufferCache buffer_cache; OGLBufferCache buffer_cache;
PrimitiveAssembler primitive_assembler{buffer_cache}; PrimitiveAssembler primitive_assembler{buffer_cache};
GLint uniform_buffer_alignment;
BindBuffersRangePushBuffer bind_ubo_pushbuffer{GL_UNIFORM_BUFFER}; BindBuffersRangePushBuffer bind_ubo_pushbuffer{GL_UNIFORM_BUFFER};
BindBuffersRangePushBuffer bind_ssbo_pushbuffer{GL_SHADER_STORAGE_BUFFER}; BindBuffersRangePushBuffer bind_ssbo_pushbuffer{GL_SHADER_STORAGE_BUFFER};