mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-09-16 22:41:58 +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
|
#pragma once
|
||||||
|
#include "opengl.hpp"
|
||||||
|
|
||||||
// Information about our OpenGL/OpenGL ES driver that we should keep track of
|
// 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
|
// Stuff like whether specific extensions are supported, and potentially things like OpenGL context information
|
||||||
|
@ -8,6 +9,9 @@ namespace OpenGL {
|
||||||
bool supportsExtFbFetch = false;
|
bool supportsExtFbFetch = false;
|
||||||
bool supportsArmFbFetch = 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; }
|
bool supportFbFetch() const { return supportsExtFbFetch || supportsArmFbFetch; }
|
||||||
};
|
};
|
||||||
} // namespace OpenGL
|
} // namespace OpenGL
|
|
@ -101,6 +101,9 @@ class RendererGL final : public Renderer {
|
||||||
std::unique_ptr<StreamBuffer> hwVertexBuffer;
|
std::unique_ptr<StreamBuffer> hwVertexBuffer;
|
||||||
std::unique_ptr<StreamBuffer> hwIndexBuffer;
|
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
|
// Cache of fixed attribute values so that we don't do any duplicate updates
|
||||||
std::array<std::array<float, 4>, 16> fixedAttrValues;
|
std::array<std::array<float, 4>, 16> fixedAttrValues;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <stb_image_write.h>
|
#include <stb_image_write.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <bit>
|
#include <bit>
|
||||||
#include <cmrc/cmrc.hpp>
|
#include <cmrc/cmrc.hpp>
|
||||||
|
|
||||||
|
@ -179,6 +180,10 @@ void RendererGL::initGraphicsContextInternal() {
|
||||||
driverInfo.supportsExtFbFetch = (GLAD_GL_EXT_shader_framebuffer_fetch != 0);
|
driverInfo.supportsExtFbFetch = (GLAD_GL_EXT_shader_framebuffer_fetch != 0);
|
||||||
driverInfo.supportsArmFbFetch = (GLAD_GL_ARM_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
|
// Initialize the default vertex shader used with shadergen
|
||||||
std::string defaultShadergenVSSource = fragShaderGen.getDefaultVertexShader();
|
std::string defaultShadergenVSSource = fragShaderGen.getDefaultVertexShader();
|
||||||
defaultShadergenVs.create({defaultShadergenVSSource.c_str(), defaultShadergenVSSource.size()}, OpenGL::Vertex);
|
defaultShadergenVs.create({defaultShadergenVSSource.c_str(), defaultShadergenVSSource.size()}, OpenGL::Vertex);
|
||||||
|
@ -930,11 +935,6 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
glUniformBlockBinding(program.handle(), vertexUBOIndex, vsUBOBlockBinding);
|
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
|
// Upload uniform data to our shader's UBO
|
||||||
PICA::FragmentUniforms uniforms;
|
PICA::FragmentUniforms uniforms;
|
||||||
|
@ -1020,10 +1020,21 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
|
|
||||||
// Upload fragment uniforms to UBO
|
// Upload fragment uniforms to UBO
|
||||||
shadergenFragmentUBO->Bind();
|
shadergenFragmentUBO->Bind();
|
||||||
auto mapRes = shadergenFragmentUBO->Map(4, sizeof(PICA::FragmentUniforms));
|
auto uboRes = shadergenFragmentUBO->Map(driverInfo.uboAlignment, sizeof(PICA::FragmentUniforms));
|
||||||
std::memcpy(mapRes.pointer, &uniforms, sizeof(PICA::FragmentUniforms));
|
std::memcpy(uboRes.pointer, &uniforms, sizeof(PICA::FragmentUniforms));
|
||||||
shadergenFragmentUBO->Unmap(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;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,11 +1085,14 @@ bool RendererGL::prepareForDraw(ShaderUnit& shaderUnit, PICA::DrawAcceleration*
|
||||||
generatedVertexShader = &(*shader);
|
generatedVertexShader = &(*shader);
|
||||||
hwShaderUniformUBO->Bind();
|
hwShaderUniformUBO->Bind();
|
||||||
|
|
||||||
|
// Upload shader uniforms to our UBO
|
||||||
if (shaderUnit.vs.uniformsDirty) {
|
if (shaderUnit.vs.uniformsDirty) {
|
||||||
shaderUnit.vs.uniformsDirty = false;
|
shaderUnit.vs.uniformsDirty = false;
|
||||||
auto mapRes = hwShaderUniformUBO->Map(4, PICAShader::totalUniformSize());
|
auto uboRes = hwShaderUniformUBO->Map(driverInfo.uboAlignment, PICAShader::totalUniformSize());
|
||||||
std::memcpy(mapRes.pointer, shaderUnit.vs.getUniformPointer(), PICAShader::totalUniformSize());
|
std::memcpy(uboRes.pointer, shaderUnit.vs.getUniformPointer(), PICAShader::totalUniformSize());
|
||||||
hwShaderUniformUBO->Unmap(PICAShader::totalUniformSize());
|
hwShaderUniformUBO->Unmap(PICAShader::totalUniformSize());
|
||||||
|
|
||||||
|
hwShaderUniformUBOOffset = uboRes.buffer_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
performIndexedRender = accel->indexed;
|
performIndexedRender = accel->indexed;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue