Skip to content

Commit 0feaba5

Browse files
committed
Handle glTexBuffer(buffer = 0) calls, and resizing buffers after create
1 parent 19cc4fa commit 0feaba5

2 files changed

Lines changed: 86 additions & 23 deletions

File tree

renderdoc/driver/gl/gl_manager.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,17 @@ void GLResourceManager::Apply_InitialState(GLResource live, InitialContentData i
17881788
}
17891789
else
17901790
{
1791-
GLuint buffer = GetLiveResource(state->texBuffer).name;
1791+
GLuint buffer = 0;
1792+
1793+
if(HasLiveResource(state->texBuffer))
1794+
buffer = GetLiveResource(state->texBuffer).name;
1795+
1796+
GLenum fmt = details.internalFormat;
1797+
1798+
// update width from here as it's authoratitive - the texture might have been resized in
1799+
// multiple rebinds that we will not have serialised before.
1800+
details.width =
1801+
state->texBufSize / uint32_t(GetByteSize(1, 1, 1, GetBaseFormat(fmt), GetDataType(fmt)));
17921802

17931803
if(gl.glTextureBufferRangeEXT)
17941804
{

renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5422,14 +5422,17 @@ bool WrappedOpenGL::Serialise_glTextureBufferRangeEXT(GLuint texture, GLenum tar
54225422
m_Textures[liveId].internalFormat = fmt;
54235423
}
54245424

5425+
GLuint buf = 0;
5426+
5427+
if(GetResourceManager()->HasLiveResource(bufid))
5428+
buf = GetResourceManager()->GetLiveResource(bufid).name;
5429+
54255430
if(Target != eGL_NONE)
54265431
m_Real.glTextureBufferRangeEXT(GetResourceManager()->GetLiveResource(texid).name, Target, fmt,
5427-
GetResourceManager()->GetLiveResource(bufid).name,
5428-
(GLintptr)offs, (GLsizeiptr)Size);
5432+
buf, (GLintptr)offs, (GLsizeiptr)Size);
54295433
else
5430-
m_Real.glTextureBufferRange(GetResourceManager()->GetLiveResource(texid).name, fmt,
5431-
GetResourceManager()->GetLiveResource(bufid).name, (GLintptr)offs,
5432-
(GLsizei)Size);
5434+
m_Real.glTextureBufferRange(GetResourceManager()->GetLiveResource(texid).name, fmt, buf,
5435+
(GLintptr)offs, (GLsizei)Size);
54335436
}
54345437

54355438
return true;
@@ -5449,11 +5452,26 @@ void WrappedOpenGL::Common_glTextureBufferRangeEXT(ResourceId texId, GLenum targ
54495452
GLResourceRecord *record = GetResourceManager()->GetResourceRecord(texId);
54505453
RDCASSERT(record);
54515454

5455+
ResourceId bufid = GetResourceManager()->GetID(BufferRes(GetCtx(), buffer));
5456+
54525457
if(record->datatype == eGL_TEXTURE_BINDING_BUFFER &&
54535458
m_Textures[texId].internalFormat == internalformat && m_State == WRITING_IDLE)
54545459
{
54555460
GetResourceManager()->MarkDirtyResource(texId);
5456-
GetResourceManager()->MarkDirtyResource(BufferRes(GetCtx(), buffer));
5461+
5462+
if(bufid != ResourceId())
5463+
{
5464+
GetResourceManager()->MarkDirtyResource(bufid);
5465+
5466+
// this will lead to an accumulation of parents if the texture is continually rebound, but
5467+
// this is unavoidable as we don't want to add tons of infrastructure just to track this
5468+
// edge case.
5469+
GLResourceRecord *bufRecord = GetResourceManager()->GetResourceRecord(bufid);
5470+
5471+
if(bufRecord)
5472+
record->AddParent(bufRecord);
5473+
}
5474+
54575475
return;
54585476
}
54595477

@@ -5463,18 +5481,24 @@ void WrappedOpenGL::Common_glTextureBufferRangeEXT(ResourceId texId, GLenum targ
54635481

54645482
if(m_State == WRITING_CAPFRAME)
54655483
{
5466-
ResourceId bufid = GetResourceManager()->GetID(BufferRes(GetCtx(), buffer));
5467-
54685484
m_ContextRecord->AddChunk(scope.Get());
54695485
m_MissingTracks.insert(record->GetResourceID());
5470-
m_MissingTracks.insert(bufid);
54715486
GetResourceManager()->MarkResourceFrameReferenced(record->GetResourceID(), eFrameRef_Read);
5472-
GetResourceManager()->MarkResourceFrameReferenced(bufid, eFrameRef_Read);
5487+
5488+
if(bufid != ResourceId())
5489+
{
5490+
m_MissingTracks.insert(bufid);
5491+
GetResourceManager()->MarkResourceFrameReferenced(bufid, eFrameRef_Read);
5492+
}
54735493
}
54745494
else
54755495
{
54765496
record->AddChunk(scope.Get());
5477-
record->AddParent(GetResourceManager()->GetResourceRecord(BufferRes(GetCtx(), buffer)));
5497+
5498+
GLResourceRecord *bufRecord = GetResourceManager()->GetResourceRecord(bufid);
5499+
5500+
if(bufRecord)
5501+
record->AddParent(bufRecord);
54785502
}
54795503
}
54805504

@@ -5588,11 +5612,26 @@ void WrappedOpenGL::Common_glTextureBufferEXT(ResourceId texId, GLenum target,
55885612
GLResourceRecord *record = GetResourceManager()->GetResourceRecord(texId);
55895613
RDCASSERT(record);
55905614

5615+
ResourceId bufid = GetResourceManager()->GetID(BufferRes(GetCtx(), buffer));
5616+
55915617
if(record->datatype == eGL_TEXTURE_BINDING_BUFFER &&
55925618
m_Textures[texId].internalFormat == internalformat && m_State == WRITING_IDLE)
55935619
{
55945620
GetResourceManager()->MarkDirtyResource(texId);
5595-
GetResourceManager()->MarkDirtyResource(BufferRes(GetCtx(), buffer));
5621+
5622+
if(bufid != ResourceId())
5623+
{
5624+
GetResourceManager()->MarkDirtyResource(bufid);
5625+
5626+
// this will lead to an accumulation of parents if the texture is continually rebound, but
5627+
// this is unavoidable as we don't want to add tons of infrastructure just to track this
5628+
// edge case.
5629+
GLResourceRecord *bufRecord = GetResourceManager()->GetResourceRecord(bufid);
5630+
5631+
if(bufRecord)
5632+
record->AddParent(bufRecord);
5633+
}
5634+
55965635
return;
55975636
}
55985637

@@ -5603,27 +5642,41 @@ void WrappedOpenGL::Common_glTextureBufferEXT(ResourceId texId, GLenum target,
56035642

56045643
if(m_State == WRITING_CAPFRAME)
56055644
{
5606-
ResourceId bufid = GetResourceManager()->GetID(BufferRes(GetCtx(), buffer));
5607-
56085645
m_ContextRecord->AddChunk(chunk);
56095646
m_MissingTracks.insert(record->GetResourceID());
5610-
m_MissingTracks.insert(bufid);
56115647
GetResourceManager()->MarkResourceFrameReferenced(record->GetResourceID(), eFrameRef_Read);
5612-
GetResourceManager()->MarkResourceFrameReferenced(bufid, eFrameRef_Read);
5648+
5649+
if(bufid != ResourceId())
5650+
{
5651+
m_MissingTracks.insert(bufid);
5652+
GetResourceManager()->MarkResourceFrameReferenced(bufid, eFrameRef_Read);
5653+
}
56135654
}
56145655
else
56155656
{
56165657
record->AddChunk(chunk);
5617-
record->AddParent(GetResourceManager()->GetResourceRecord(BufferRes(GetCtx(), buffer)));
5658+
5659+
GLResourceRecord *bufRecord = GetResourceManager()->GetResourceRecord(bufid);
5660+
5661+
if(bufRecord)
5662+
record->AddParent(bufRecord);
56185663
}
56195664
}
56205665

56215666
{
5622-
uint32_t size = 1;
5623-
m_Real.glGetNamedBufferParameterivEXT(buffer, eGL_BUFFER_SIZE, (GLint *)&size);
5624-
m_Textures[texId].width =
5625-
uint32_t(size) /
5626-
uint32_t(GetByteSize(1, 1, 1, GetBaseFormat(internalformat), GetDataType(internalformat)));
5667+
if(buffer != 0)
5668+
{
5669+
uint32_t size = 1;
5670+
m_Real.glGetNamedBufferParameterivEXT(buffer, eGL_BUFFER_SIZE, (GLint *)&size);
5671+
m_Textures[texId].width =
5672+
uint32_t(size) /
5673+
uint32_t(GetByteSize(1, 1, 1, GetBaseFormat(internalformat), GetDataType(internalformat)));
5674+
}
5675+
else
5676+
{
5677+
m_Textures[texId].width = 1;
5678+
}
5679+
56275680
m_Textures[texId].height = 1;
56285681
m_Textures[texId].depth = 1;
56295682
if(target != eGL_NONE)

0 commit comments

Comments
 (0)