renderer_opengl: Address buffer overflow

This commit is contained in:
GPUCode
2022-10-04 07:32:19 +03:00
parent d4a3f60575
commit 7e7b3dc18c
5 changed files with 18 additions and 13 deletions

View File

@ -122,10 +122,8 @@ public:
QSurfaceFormat format;
if (Settings::values.graphics_api == Settings::GraphicsAPI::OpenGLES) {
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
format.setVersion(3, 2);
} else {
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
format.setVersion(4, 4);
format.setProfile(QSurfaceFormat::CoreProfile);
}

View File

@ -76,7 +76,7 @@ static std::string GetVertexInterfaceDeclaration(bool is_output, bool separable_
const auto append_variable = [&](std::string_view var, int location) {
if (separable_shader) {
out += fmt::format("layout (location={}) ", location);
out += fmt::format("layout(location = {}) ", location);
}
out += fmt::format("{}{};\n", is_output ? "out " : "in ", var);
};
@ -1240,7 +1240,7 @@ ShaderDecompiler::ProgramResult GenerateFragmentShader(const PicaFSConfig& confi
in vec4 gl_FragCoord;
#endif // CITRA_GLES
out vec4 color;
layout (location = 0) out vec4 color;
uniform sampler2D tex0;
uniform sampler2D tex1;

View File

@ -453,6 +453,7 @@ void ShaderProgramManager::ApplyTo(OpenGLState& state) {
glUseProgramStages(impl->pipeline.handle, GL_VERTEX_SHADER_BIT, impl->current.vs);
glUseProgramStages(impl->pipeline.handle, GL_GEOMETRY_SHADER_BIT, impl->current.gs);
glUseProgramStages(impl->pipeline.handle, GL_FRAGMENT_SHADER_BIT, impl->current.fs);
state.draw.shader_program = 0;
state.draw.program_pipeline = impl->pipeline.handle;
} else {

View File

@ -68,6 +68,7 @@ const StagingBuffer& TextureRuntime::FindStaging(u32 size, bool upload) {
// Attempt to find a free buffer that fits the requested data
for (auto it = search.lower_bound({.size = size}); it != search.end(); it++) {
if (!upload || it->IsFree()) {
it->mapped = std::span{it->mapped.data(), size};
return *it;
}
}
@ -132,6 +133,7 @@ void TextureRuntime::FormatConvert(const Surface& surface, bool upload,
} else if (format == VideoCore::PixelFormat::RGB8 && driver.IsOpenGLES()) {
Pica::Texture::ConvertBGRToRGB(source, dest);
} else {
ASSERT(dest.size() >= source.size());
std::memcpy(dest.data(), source.data(), source.size());
}
}
@ -311,18 +313,22 @@ void TextureRuntime::BindFramebuffer(GLenum target, GLint level, GLenum textarge
Surface::Surface(VideoCore::SurfaceParams& params, TextureRuntime& runtime)
: VideoCore::SurfaceBase<Surface>{params}, runtime{runtime}, driver{runtime.GetDriver()} {
texture = runtime.Allocate(GetScaledWidth(), GetScaledHeight(), params.pixel_format, texture_type);
if (pixel_format != VideoCore::PixelFormat::Invalid) {
texture = runtime.Allocate(GetScaledWidth(), GetScaledHeight(), params.pixel_format, texture_type);
}
}
Surface::~Surface() {
const VideoCore::HostTextureTag tag = {
.format = pixel_format,
.width = GetScaledWidth(),
.height = GetScaledHeight(),
.layers = texture_type == VideoCore::TextureType::CubeMap ? 6u : 1u
};
if (pixel_format != VideoCore::PixelFormat::Invalid) {
const VideoCore::HostTextureTag tag = {
.format = pixel_format,
.width = GetScaledWidth(),
.height = GetScaledHeight(),
.layers = texture_type == VideoCore::TextureType::CubeMap ? 6u : 1u
};
runtime.texture_recycler.emplace(tag, std::move(texture));
runtime.texture_recycler.emplace(tag, std::move(texture));
}
}
MICROPROFILE_DEFINE(OpenGL_Upload, "OpenGLSurface", "Texture Upload", MP_RGB(128, 192, 64));

View File

@ -22,7 +22,7 @@ struct FormatTuple {
struct StagingBuffer {
OGLBuffer buffer{};
mutable OGLSync buffer_lock{};
std::span<std::byte> mapped{};
mutable std::span<std::byte> mapped{};
u32 size{};
bool operator<(const StagingBuffer& other) const {