Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: BGFX_TEXTURE_MSAA_SAMPLE and msaa sampling bugs with gl #3351

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ void ir_print_glsl_visitor::visit(ir_texture *ir)
ir->coordinate->accept(this);

// lod
if (ir->op == ir_txl || ir->op == ir_txf || ir->op == ir_txf_ms)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We handle the ir_txf_ms case a few lines below, so this lead to a duplicate last parameter with texelFetch(Sampler2DMS, ...)

if (ir->op == ir_txl || ir->op == ir_txf)
{
buffer.asprintf_append (", ");
ir->lod_info.lod->accept(this);
Expand Down
8 changes: 4 additions & 4 deletions src/bgfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4535,13 +4535,13 @@ namespace bgfx
++depth;

BGFX_ERROR_CHECK(
// if BGFX_TEXTURE_RT_MSAA_X2 or greater than BGFX_TEXTURE_RT_WRITE_ONLY is required
// if BGFX_TEXTURE_RT with no MSSA then WRITE_ONLY is not required.
// if BGFX_TEXTURE_RT_MSAA_X2 or greater than either BGFX_TEXTURE_RT_WRITE_ONLY or BGFX_TEXTURE_MSAA_SAMPLE is required
// if BGFX_TEXTURE_RT with no MSSA then this is not required.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BGFX_TEXTURE_MSAA_SAMPLER doesn't resolve either, so it's valid to use with depth attachments

(1 == ((tr.m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT))
|| (0 != (tr.m_flags & BGFX_TEXTURE_RT_WRITE_ONLY))
|| (0 != (tr.m_flags & (BGFX_TEXTURE_RT_WRITE_ONLY | BGFX_TEXTURE_MSAA_SAMPLE)))
, _err
, BGFX_ERROR_FRAME_BUFFER_VALIDATION
, "Frame buffer depth MSAA texture cannot be resolved. It must be created with `BGFX_TEXTURE_RT_WRITE_ONLY` flag."
, "Frame buffer depth MSAA texture cannot be resolved. It must be created with either `BGFX_TEXTURE_RT_WRITE_ONLY` or `BGFX_TEXTURE_MSAA_SAMPLE` flag."
, "Attachment %d, texture flags 0x%016" PRIx64 "."
, ii
, tr.m_flags
Expand Down
4 changes: 2 additions & 2 deletions src/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ namespace bgfx { namespace gl
, _internalFormat
, _width
, _height
, false
, true
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we have multiple GL_TEXTURE_2D_MULTISAMPLE attachments this is required to be true, so that all sample locations match.
Realistically I don't know how common it is for sample locations to not match anyway, and I don't believe there is any penalty to doing so, so might as well have it on all the time for now.

);
}
else
Expand Down Expand Up @@ -7101,7 +7101,7 @@ namespace bgfx { namespace gl
{
const TextureGL& texture = s_renderGL->m_textures[at.handle.idx];

if (0 != texture.m_id)
if (0 != texture.m_rbo && 0 != texture.m_id)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't try to resolve multisample textures too, ensure it also has an rbo!
(If one attachment required resolve, this would accidentally try and resolve the multisample texture too, causing an unhappy framebuffer)

{

GLenum attachment = GL_INVALID_ENUM;
Expand Down