gl: Commit to bindless framebuffer object management

This commit is contained in:
kd-11 2022-05-27 00:39:56 +03:00 committed by kd-11
parent 7ec481d99b
commit 55e68441cb
4 changed files with 67 additions and 62 deletions

View file

@ -4,6 +4,7 @@
#include "GLCompute.h"
#include "util/logs.hpp"
#include "../Common/simple_array.hpp"
#include <unordered_map>
namespace gl
@ -223,8 +224,7 @@ namespace gl
bool fbo::check() const
{
save_binding_state save(*this);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
GLenum status = DSA_CALL2_RET(CheckNamedFramebufferStatus, m_id, GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
@ -245,29 +245,24 @@ namespace gl
void fbo::draw_buffer(const attachment& buffer) const
{
save_binding_state save(*this);
GLenum buf = buffer.id();
glDrawBuffers(1, &buf);
DSA_CALL3(NamedFramebufferDrawBuffers, FramebufferDrawBuffers, m_id, 1, &buf);
}
void fbo::draw_buffers(const std::initializer_list<attachment>& indexes) const
{
save_binding_state save(*this);
std::vector<GLenum> ids;
rsx::simple_array<GLenum> ids;
ids.reserve(indexes.size());
for (auto &index : indexes)
ids.push_back(index.id());
glDrawBuffers(::narrow<GLsizei>(ids.size()), ids.data());
DSA_CALL3(NamedFramebufferDrawBuffers, FramebufferDrawBuffers, m_id, static_cast<GLsizei>(ids.size()), ids.data());
}
void fbo::read_buffer(const attachment& buffer) const
{
save_binding_state save(*this);
GLenum buf = buffer.id();
glReadBuffer(buf);
DSA_CALL3(NamedFramebufferReadBuffer, FramebufferReadBuffer, m_id, buffer.id());
}
void fbo::draw_arrays(rsx::primitive_type mode, GLsizei count, GLint first) const
@ -565,25 +560,25 @@ namespace gl
{
const bool is_depth_copy = (real_src->aspect() != image_aspect::color);
const filter interp = (linear_interpolation && !is_depth_copy) ? filter::linear : filter::nearest;
GLenum attachment;
gl::fbo::attachment::type attachment;
gl::buffers target;
if (is_depth_copy)
{
if (real_dst->aspect() & gl::image_aspect::stencil)
{
attachment = GL_DEPTH_STENCIL_ATTACHMENT;
attachment = fbo::attachment::type::depth_stencil;
target = gl::buffers::depth_stencil;
}
else
{
attachment = GL_DEPTH_ATTACHMENT;
attachment = fbo::attachment::type::depth;
target = gl::buffers::depth;
}
}
else
{
attachment = GL_COLOR_ATTACHMENT0;
attachment = fbo::attachment::type::color;
target = gl::buffers::color;
}
@ -591,11 +586,11 @@ namespace gl
save_binding_state saved;
glBindFramebuffer(GL_READ_FRAMEBUFFER, blit_src.id());
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, attachment, GL_TEXTURE_2D, real_src->id(), 0);
gl::fbo::attachment src_att{blit_src, static_cast<fbo::attachment::type>(attachment)};
src_att = *real_src;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, blit_dst.id());
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, real_dst->id(), 0);
gl::fbo::attachment dst_att{ blit_dst, static_cast<fbo::attachment::type>(attachment) };
dst_att = *real_dst;
if (xfer_info.flip_horizontal)
{
@ -607,13 +602,11 @@ namespace gl
src_rect.flip_vertical();
}
glBlitFramebuffer(src_rect.x1, src_rect.y1, src_rect.x2, src_rect.y2,
dst_rect.x1, dst_rect.y1, dst_rect.x2, dst_rect.y2,
static_cast<GLbitfield>(target), static_cast<GLenum>(interp));
blit_src.blit(blit_dst, src_rect, dst_rect, target, interp);
// Release the attachments explicitly (not doing so causes glitches, e.g Journey Menu)
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, attachment, GL_TEXTURE_2D, GL_NONE, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, GL_NONE, 0);
src_att = GL_NONE;
dst_att = GL_NONE;
}
if (xfer_info.dst_is_typeless)
@ -628,19 +621,19 @@ namespace gl
save_binding_state saved;
blit_dst.bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dst->id(), 0);
blit_dst.color[0] = *dst;
blit_dst.check();
cmd->clear_color(color);
cmd->color_maski(0, true, true, true, true);
glClear(GL_COLOR_BUFFER_BIT);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, GL_NONE, 0);
blit_dst.color[0] = GL_NONE;
}
void blitter::fast_clear_image(gl::command_context& cmd, const texture* dst, float /*depth*/, u8 /*stencil*/)
{
GLenum attachment;
fbo::attachment::type attachment;
GLbitfield clear_mask;
switch (const auto fmt = dst->get_internal_format())
@ -648,27 +641,28 @@ namespace gl
case texture::internal_format::depth16:
case texture::internal_format::depth32f:
clear_mask = GL_DEPTH_BUFFER_BIT;
attachment = GL_DEPTH_ATTACHMENT;
attachment = fbo::attachment::type::depth;
break;
case texture::internal_format::depth24_stencil8:
case texture::internal_format::depth32f_stencil8:
clear_mask = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
attachment = GL_DEPTH_STENCIL_ATTACHMENT;
attachment = fbo::attachment::type::depth_stencil;
break;
default:
fmt::throw_exception("Invalid texture passed to clear depth function, format=0x%x", static_cast<u32>(fmt));
}
save_binding_state saved;
fbo::attachment attach_point{ blit_dst, attachment };
blit_dst.bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, dst->id(), 0);
attach_point = *dst;
blit_dst.check();
cmd->depth_mask(GL_TRUE);
cmd->stencil_mask(0xFF);
glClear(clear_mask);
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, GL_NONE, 0);
attach_point = GL_NONE;
}
}