renderer_opengl: Address buffer overflow
This commit is contained in:
@ -122,10 +122,8 @@ public:
|
|||||||
QSurfaceFormat format;
|
QSurfaceFormat format;
|
||||||
|
|
||||||
if (Settings::values.graphics_api == Settings::GraphicsAPI::OpenGLES) {
|
if (Settings::values.graphics_api == Settings::GraphicsAPI::OpenGLES) {
|
||||||
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
|
|
||||||
format.setVersion(3, 2);
|
format.setVersion(3, 2);
|
||||||
} else {
|
} else {
|
||||||
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
|
|
||||||
format.setVersion(4, 4);
|
format.setVersion(4, 4);
|
||||||
format.setProfile(QSurfaceFormat::CoreProfile);
|
format.setProfile(QSurfaceFormat::CoreProfile);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ static std::string GetVertexInterfaceDeclaration(bool is_output, bool separable_
|
|||||||
|
|
||||||
const auto append_variable = [&](std::string_view var, int location) {
|
const auto append_variable = [&](std::string_view var, int location) {
|
||||||
if (separable_shader) {
|
if (separable_shader) {
|
||||||
out += fmt::format("layout (location={}) ", location);
|
out += fmt::format("layout(location = {}) ", location);
|
||||||
}
|
}
|
||||||
out += fmt::format("{}{};\n", is_output ? "out " : "in ", var);
|
out += fmt::format("{}{};\n", is_output ? "out " : "in ", var);
|
||||||
};
|
};
|
||||||
@ -1240,7 +1240,7 @@ ShaderDecompiler::ProgramResult GenerateFragmentShader(const PicaFSConfig& confi
|
|||||||
in vec4 gl_FragCoord;
|
in vec4 gl_FragCoord;
|
||||||
#endif // CITRA_GLES
|
#endif // CITRA_GLES
|
||||||
|
|
||||||
out vec4 color;
|
layout (location = 0) out vec4 color;
|
||||||
|
|
||||||
uniform sampler2D tex0;
|
uniform sampler2D tex0;
|
||||||
uniform sampler2D tex1;
|
uniform sampler2D tex1;
|
||||||
|
@ -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_VERTEX_SHADER_BIT, impl->current.vs);
|
||||||
glUseProgramStages(impl->pipeline.handle, GL_GEOMETRY_SHADER_BIT, impl->current.gs);
|
glUseProgramStages(impl->pipeline.handle, GL_GEOMETRY_SHADER_BIT, impl->current.gs);
|
||||||
glUseProgramStages(impl->pipeline.handle, GL_FRAGMENT_SHADER_BIT, impl->current.fs);
|
glUseProgramStages(impl->pipeline.handle, GL_FRAGMENT_SHADER_BIT, impl->current.fs);
|
||||||
|
|
||||||
state.draw.shader_program = 0;
|
state.draw.shader_program = 0;
|
||||||
state.draw.program_pipeline = impl->pipeline.handle;
|
state.draw.program_pipeline = impl->pipeline.handle;
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,6 +68,7 @@ const StagingBuffer& TextureRuntime::FindStaging(u32 size, bool upload) {
|
|||||||
// Attempt to find a free buffer that fits the requested data
|
// Attempt to find a free buffer that fits the requested data
|
||||||
for (auto it = search.lower_bound({.size = size}); it != search.end(); it++) {
|
for (auto it = search.lower_bound({.size = size}); it != search.end(); it++) {
|
||||||
if (!upload || it->IsFree()) {
|
if (!upload || it->IsFree()) {
|
||||||
|
it->mapped = std::span{it->mapped.data(), size};
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,6 +133,7 @@ void TextureRuntime::FormatConvert(const Surface& surface, bool upload,
|
|||||||
} else if (format == VideoCore::PixelFormat::RGB8 && driver.IsOpenGLES()) {
|
} else if (format == VideoCore::PixelFormat::RGB8 && driver.IsOpenGLES()) {
|
||||||
Pica::Texture::ConvertBGRToRGB(source, dest);
|
Pica::Texture::ConvertBGRToRGB(source, dest);
|
||||||
} else {
|
} else {
|
||||||
|
ASSERT(dest.size() >= source.size());
|
||||||
std::memcpy(dest.data(), source.data(), 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)
|
Surface::Surface(VideoCore::SurfaceParams& params, TextureRuntime& runtime)
|
||||||
: VideoCore::SurfaceBase<Surface>{params}, runtime{runtime}, driver{runtime.GetDriver()} {
|
: 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() {
|
Surface::~Surface() {
|
||||||
const VideoCore::HostTextureTag tag = {
|
if (pixel_format != VideoCore::PixelFormat::Invalid) {
|
||||||
.format = pixel_format,
|
const VideoCore::HostTextureTag tag = {
|
||||||
.width = GetScaledWidth(),
|
.format = pixel_format,
|
||||||
.height = GetScaledHeight(),
|
.width = GetScaledWidth(),
|
||||||
.layers = texture_type == VideoCore::TextureType::CubeMap ? 6u : 1u
|
.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));
|
MICROPROFILE_DEFINE(OpenGL_Upload, "OpenGLSurface", "Texture Upload", MP_RGB(128, 192, 64));
|
||||||
|
@ -22,7 +22,7 @@ struct FormatTuple {
|
|||||||
struct StagingBuffer {
|
struct StagingBuffer {
|
||||||
OGLBuffer buffer{};
|
OGLBuffer buffer{};
|
||||||
mutable OGLSync buffer_lock{};
|
mutable OGLSync buffer_lock{};
|
||||||
std::span<std::byte> mapped{};
|
mutable std::span<std::byte> mapped{};
|
||||||
u32 size{};
|
u32 size{};
|
||||||
|
|
||||||
bool operator<(const StagingBuffer& other) const {
|
bool operator<(const StagingBuffer& other) const {
|
||||||
|
Reference in New Issue
Block a user