Skip to content

Commit 267eb7f

Browse files
committed
Ensure a sized format is used when creating MSAA textures. Closes baldurk#1623
* If the application used an unsized format like GL_DEPTH_COMPONENT to create the texture with glTexImage2DMultisample then that's legal, but if we promote it to glTextureStorage2DMultisampleEXT for DSA we can't continue to use that unsized format so we need to convert to sized by picking a sensible default.
1 parent 23c3a38 commit 267eb7f

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

renderdoc/driver/gl/gl_driver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,11 +2739,17 @@ void WrappedOpenGL::CreateTextureImage(GLuint tex, GLenum internalFormat, GLenum
27392739

27402740
if(textype == eGL_TEXTURE_2D_MULTISAMPLE)
27412741
{
2742+
// we need a sized format for storage functions
2743+
internalFormat = GetSizedFormat(internalFormat);
2744+
27422745
GL.glTextureStorage2DMultisampleEXT(tex, textype, samples, internalFormat, width, height,
27432746
GL_TRUE);
27442747
}
27452748
else if(textype == eGL_TEXTURE_2D_MULTISAMPLE_ARRAY)
27462749
{
2750+
// we need a sized format for storage functions
2751+
internalFormat = GetSizedFormat(internalFormat);
2752+
27472753
GL.glTextureStorage3DMultisampleEXT(tex, textype, samples, internalFormat, width, height, depth,
27482754
GL_TRUE);
27492755
}

renderdoc/driver/gl/gl_initstate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,8 @@ bool GLResourceManager::Serialise_InitialState(SerialiserType &ser, ResourceId i
15151515
eGL_CLAMP_TO_EDGE);
15161516

15171517
// must use immutable tex storage here, for MSAA<->Array copies
1518-
GL.glTextureStorage3DEXT(tex, eGL_TEXTURE_2D_ARRAY, 1, TextureState.internalformat,
1518+
GL.glTextureStorage3DEXT(tex, eGL_TEXTURE_2D_ARRAY, 1,
1519+
GetSizedFormat(TextureState.internalformat),
15191520
TextureState.width, TextureState.height, copySlices);
15201521

15211522
// read back from the array we prepared

renderdoc/driver/gl/gl_msaa_array_conv.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ void WrappedOpenGL::CopyTex2DMSToArray(GLuint &destArray, GLuint srcMS, GLint wi
110110
{
111111
const ArrayMSPrograms &arrms = GetArrayMS();
112112

113+
intFormat = GetSizedFormat(intFormat);
114+
113115
// create temporary texture array, which we'll initialise to be the width/height in same format,
114116
// with the same number of array slices as multi samples.
115117
GL.glGenTextures(1, &destArray);
@@ -267,11 +269,11 @@ void WrappedOpenGL::CopyDepthTex2DMSToArray(GLuint &destArray, GLuint srcMS, GLi
267269
numStencil = 256;
268270
attach = eGL_DEPTH_STENCIL_ATTACHMENT;
269271
break;
270-
case eGL_DEPTH:
272+
case eGL_DEPTH_COMPONENT:
271273
numStencil = 1;
272274
attach = eGL_DEPTH_ATTACHMENT;
273275
break;
274-
case eGL_STENCIL:
276+
case eGL_STENCIL_INDEX:
275277
numStencil = 256;
276278
attach = eGL_STENCIL_ATTACHMENT;
277279
break;
@@ -341,6 +343,8 @@ void WrappedOpenGL::CopyArrayToTex2DMS(GLuint destMS, GLuint srcArray, GLint wid
341343
{
342344
WrappedOpenGL &drv = *this;
343345

346+
intFormat = GetSizedFormat(intFormat);
347+
344348
const ArrayMSPrograms &arrms = GetArrayMS();
345349

346350
if(!HasExt[ARB_compute_shader])
@@ -499,11 +503,11 @@ void WrappedOpenGL::CopyDepthArrayToTex2DMS(GLuint destMS, GLuint srcArray, GLin
499503
numStencil = 256;
500504
attach = eGL_DEPTH_STENCIL_ATTACHMENT;
501505
break;
502-
case eGL_DEPTH:
506+
case eGL_DEPTH_COMPONENT:
503507
numStencil = 1;
504508
attach = eGL_DEPTH_ATTACHMENT;
505509
break;
506-
case eGL_STENCIL:
510+
case eGL_STENCIL_INDEX:
507511
numStencil = 256;
508512
attach = eGL_STENCIL_ATTACHMENT;
509513
break;

renderdoc/driver/gl/gl_resources.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ GLenum GetBaseFormat(GLenum internalFormat)
455455
case eGL_STENCIL_INDEX4:
456456
case eGL_STENCIL_INDEX8:
457457
case eGL_STENCIL_INDEX16:
458-
case eGL_STENCIL: return eGL_STENCIL;
458+
case eGL_STENCIL: return eGL_STENCIL_INDEX;
459459
default: break;
460460
}
461461

@@ -891,6 +891,28 @@ bool EmulateLuminanceFormat(GLuint tex, GLenum target, GLenum &internalFormat, G
891891
return true;
892892
}
893893

894+
GLenum GetSizedFormat(GLenum internalformat)
895+
{
896+
switch(internalformat)
897+
{
898+
case eGL_DEPTH_COMPONENT: internalformat = eGL_DEPTH_COMPONENT32F; break;
899+
case eGL_DEPTH_STENCIL: internalformat = eGL_DEPTH32F_STENCIL8; break;
900+
case eGL_STENCIL:
901+
case eGL_STENCIL_INDEX: internalformat = eGL_STENCIL_INDEX8; break;
902+
case eGL_RGBA: internalformat = eGL_RGBA8; break;
903+
case eGL_RGBA_INTEGER: internalformat = eGL_RGBA8I; break;
904+
case eGL_RGB: internalformat = eGL_RGB8; break;
905+
case eGL_RGB_INTEGER: internalformat = eGL_RGB8I; break;
906+
case eGL_RG: internalformat = eGL_RG8; break;
907+
case eGL_RG_INTEGER: internalformat = eGL_RG8I; break;
908+
case eGL_RED: internalformat = eGL_R8; break;
909+
case eGL_RED_INTEGER: internalformat = eGL_R8I; break;
910+
default: break;
911+
}
912+
913+
return internalformat;
914+
}
915+
894916
bool IsCompressedFormat(GLenum internalFormat)
895917
{
896918
switch(internalFormat)
@@ -979,7 +1001,7 @@ bool IsDepthStencilFormat(GLenum internalFormat)
9791001

9801002
GLenum fmt = GetBaseFormat(internalFormat);
9811003

982-
return (fmt == eGL_DEPTH_COMPONENT || fmt == eGL_STENCIL || fmt == eGL_DEPTH_STENCIL);
1004+
return (fmt == eGL_DEPTH_COMPONENT || fmt == eGL_STENCIL_INDEX || fmt == eGL_DEPTH_STENCIL);
9831005
}
9841006

9851007
bool IsUIntFormat(GLenum internalFormat)

renderdoc/driver/gl/gl_resources.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void GetTextureSwizzle(GLuint tex, GLenum target, GLenum *swizzleRGBA);
3737
void SetTextureSwizzle(GLuint tex, GLenum target, const GLenum *swizzleRGBA);
3838

3939
bool EmulateLuminanceFormat(GLuint tex, GLenum target, GLenum &internalFormat, GLenum &dataFormat);
40+
GLenum GetSizedFormat(GLenum internalFormat);
4041

4142
inline void EmulateGLClamp(GLenum pname, GLenum param)
4243
{

renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4485,6 +4485,9 @@ bool WrappedOpenGL::Serialise_glTextureStorage2DMultisampleEXT(SerialiserType &s
44854485
GLenum dummy = eGL_NONE;
44864486
bool emulated = EmulateLuminanceFormat(texture.name, target, internalformat, dummy);
44874487

4488+
// if we promoted glTexImage2DMultisample to storage, we need a sized format
4489+
internalformat = GetSizedFormat(internalformat);
4490+
44884491
ResourceId liveId = GetResourceManager()->GetID(texture);
44894492
m_Textures[liveId].width = width;
44904493
m_Textures[liveId].height = height;
@@ -4660,6 +4663,9 @@ bool WrappedOpenGL::Serialise_glTextureStorage3DMultisampleEXT(SerialiserType &s
46604663
GLenum dummy = eGL_NONE;
46614664
bool emulated = EmulateLuminanceFormat(texture.name, target, internalformat, dummy);
46624665

4666+
// if we promoted glTexImage3DMultisample to storage, we need a sized format
4667+
internalformat = GetSizedFormat(internalformat);
4668+
46634669
ResourceId liveId = GetResourceManager()->GetID(texture);
46644670
m_Textures[liveId].width = width;
46654671
m_Textures[liveId].height = height;

0 commit comments

Comments
 (0)