mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-09-16 14:31:59 +00:00
GL: Respect minimum UBO alignment requirement (#794)
Some checks failed
Hydra Core Build / MacOS (push) Has been cancelled
Hydra Core Build / ARM-Libretro (push) Has been cancelled
Linux Build / build (push) Has been cancelled
Windows Build / build (push) Has been cancelled
MacOS Build / MacOS-x86_64 (push) Has been cancelled
Qt Build / Windows (push) Has been cancelled
Qt Build / MacOS-arm64 (push) Has been cancelled
Qt Build / Linux (push) Has been cancelled
iOS Simulator Build / build (push) Has been cancelled
Hardware Test Build / build (push) Has been cancelled
MacOS Build / MacOS-Universal (push) Has been cancelled
Qt Build / MacOS-Universal (push) Has been cancelled
Android Build / x64 (release) (push) Has been cancelled
HTTP Server Build / build (push) Has been cancelled
Hydra Core Build / Windows (push) Has been cancelled
Hydra Core Build / Linux (push) Has been cancelled
Hydra Core Build / Android-x64 (push) Has been cancelled
Linux AppImage Build / build (push) Has been cancelled
MacOS Build / MacOS-arm64 (push) Has been cancelled
Qt Build / MacOS-x86_64 (push) Has been cancelled
Android Build / arm64 (release) (push) Has been cancelled
Some checks failed
Hydra Core Build / MacOS (push) Has been cancelled
Hydra Core Build / ARM-Libretro (push) Has been cancelled
Linux Build / build (push) Has been cancelled
Windows Build / build (push) Has been cancelled
MacOS Build / MacOS-x86_64 (push) Has been cancelled
Qt Build / Windows (push) Has been cancelled
Qt Build / MacOS-arm64 (push) Has been cancelled
Qt Build / Linux (push) Has been cancelled
iOS Simulator Build / build (push) Has been cancelled
Hardware Test Build / build (push) Has been cancelled
MacOS Build / MacOS-Universal (push) Has been cancelled
Qt Build / MacOS-Universal (push) Has been cancelled
Android Build / x64 (release) (push) Has been cancelled
HTTP Server Build / build (push) Has been cancelled
Hydra Core Build / Windows (push) Has been cancelled
Hydra Core Build / Linux (push) Has been cancelled
Hydra Core Build / Android-x64 (push) Has been cancelled
Linux AppImage Build / build (push) Has been cancelled
MacOS Build / MacOS-arm64 (push) Has been cancelled
Qt Build / MacOS-x86_64 (push) Has been cancelled
Android Build / arm64 (release) (push) Has been cancelled
* GL: Respect minimum UBO alignment requirement * Use glBindBufferRange for UBOs * Fix fragment shadergen UBO bindings * Nit
This commit is contained in:
parent
0815707613
commit
8b0b1939cf
3 changed files with 30 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include "opengl.hpp"
|
||||
|
||||
// Information about our OpenGL/OpenGL ES driver that we should keep track of
|
||||
// Stuff like whether specific extensions are supported, and potentially things like OpenGL context information
|
||||
|
@ -8,6 +9,9 @@ namespace OpenGL {
|
|||
bool supportsExtFbFetch = false;
|
||||
bool supportsArmFbFetch = false;
|
||||
|
||||
// Minimum alignment for UBO offsets. Fetched by the OpenGL renderer using glGetIntegerV.
|
||||
GLuint uboAlignment = 16;
|
||||
|
||||
bool supportFbFetch() const { return supportsExtFbFetch || supportsArmFbFetch; }
|
||||
};
|
||||
} // namespace OpenGL
|
|
@ -101,6 +101,9 @@ class RendererGL final : public Renderer {
|
|||
std::unique_ptr<StreamBuffer> hwVertexBuffer;
|
||||
std::unique_ptr<StreamBuffer> hwIndexBuffer;
|
||||
|
||||
// Current offset for our hw shader uniform UBO
|
||||
u32 hwShaderUniformUBOOffset = 0;
|
||||
|
||||
// Cache of fixed attribute values so that we don't do any duplicate updates
|
||||
std::array<std::array<float, 4>, 16> fixedAttrValues;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stb_image_write.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
#include <cmrc/cmrc.hpp>
|
||||
|
||||
|
@ -179,6 +180,10 @@ void RendererGL::initGraphicsContextInternal() {
|
|||
driverInfo.supportsExtFbFetch = (GLAD_GL_EXT_shader_framebuffer_fetch != 0);
|
||||
driverInfo.supportsArmFbFetch = (GLAD_GL_ARM_shader_framebuffer_fetch != 0);
|
||||
|
||||
// UBOs have an alignment requirement we have to respect
|
||||
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<GLint*>(&driverInfo.uboAlignment));
|
||||
driverInfo.uboAlignment = std::max<GLuint>(driverInfo.uboAlignment, 16);
|
||||
|
||||
// Initialize the default vertex shader used with shadergen
|
||||
std::string defaultShadergenVSSource = fragShaderGen.getDefaultVertexShader();
|
||||
defaultShadergenVs.create({defaultShadergenVSSource.c_str(), defaultShadergenVSSource.size()}, OpenGL::Vertex);
|
||||
|
@ -930,11 +935,6 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
|||
glUniformBlockBinding(program.handle(), vertexUBOIndex, vsUBOBlockBinding);
|
||||
}
|
||||
}
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, fsUBOBlockBinding, shadergenFragmentUBO->GetGLBufferId());
|
||||
|
||||
if (usingAcceleratedShader) {
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, vsUBOBlockBinding, hwShaderUniformUBO->GetGLBufferId());
|
||||
}
|
||||
|
||||
// Upload uniform data to our shader's UBO
|
||||
PICA::FragmentUniforms uniforms;
|
||||
|
@ -1020,10 +1020,21 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
|||
|
||||
// Upload fragment uniforms to UBO
|
||||
shadergenFragmentUBO->Bind();
|
||||
auto mapRes = shadergenFragmentUBO->Map(4, sizeof(PICA::FragmentUniforms));
|
||||
std::memcpy(mapRes.pointer, &uniforms, sizeof(PICA::FragmentUniforms));
|
||||
auto uboRes = shadergenFragmentUBO->Map(driverInfo.uboAlignment, sizeof(PICA::FragmentUniforms));
|
||||
std::memcpy(uboRes.pointer, &uniforms, sizeof(PICA::FragmentUniforms));
|
||||
shadergenFragmentUBO->Unmap(sizeof(PICA::FragmentUniforms));
|
||||
|
||||
// Bind our UBOs
|
||||
glBindBufferRange(
|
||||
GL_UNIFORM_BUFFER, fsUBOBlockBinding, shadergenFragmentUBO->GetGLBufferId(), uboRes.buffer_offset, sizeof(PICA::FragmentUniforms)
|
||||
);
|
||||
|
||||
if (usingAcceleratedShader) {
|
||||
glBindBufferRange(
|
||||
GL_UNIFORM_BUFFER, vsUBOBlockBinding, hwShaderUniformUBO->GetGLBufferId(), hwShaderUniformUBOOffset, PICAShader::totalUniformSize()
|
||||
);
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
|
@ -1074,11 +1085,14 @@ bool RendererGL::prepareForDraw(ShaderUnit& shaderUnit, PICA::DrawAcceleration*
|
|||
generatedVertexShader = &(*shader);
|
||||
hwShaderUniformUBO->Bind();
|
||||
|
||||
// Upload shader uniforms to our UBO
|
||||
if (shaderUnit.vs.uniformsDirty) {
|
||||
shaderUnit.vs.uniformsDirty = false;
|
||||
auto mapRes = hwShaderUniformUBO->Map(4, PICAShader::totalUniformSize());
|
||||
std::memcpy(mapRes.pointer, shaderUnit.vs.getUniformPointer(), PICAShader::totalUniformSize());
|
||||
auto uboRes = hwShaderUniformUBO->Map(driverInfo.uboAlignment, PICAShader::totalUniformSize());
|
||||
std::memcpy(uboRes.pointer, shaderUnit.vs.getUniformPointer(), PICAShader::totalUniformSize());
|
||||
hwShaderUniformUBO->Unmap(PICAShader::totalUniformSize());
|
||||
|
||||
hwShaderUniformUBOOffset = uboRes.buffer_offset;
|
||||
}
|
||||
|
||||
performIndexedRender = accel->indexed;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue