From e52981ad47571e9d70bd3c09ead888e4501928ff Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 2 Dec 2014 23:28:12 +0000 Subject: [PATCH] Display of MSAA textures in GL --- renderdoc/data/glsl/debuguniforms.h | 9 ++- renderdoc/data/glsl/histogram.comp | 18 ++--- renderdoc/data/glsl/texdisplay.frag | 7 +- renderdoc/data/glsl/texsample.h | 93 +++++++++++++++++++++++++- renderdoc/driver/d3d11/d3d11_debug.cpp | 2 - renderdoc/driver/gl/gl_debug.cpp | 17 +++++ 6 files changed, 123 insertions(+), 23 deletions(-) diff --git a/renderdoc/data/glsl/debuguniforms.h b/renderdoc/data/glsl/debuguniforms.h index 2a1a9ce18..c3dca1cf0 100644 --- a/renderdoc/data/glsl/debuguniforms.h +++ b/renderdoc/data/glsl/debuguniforms.h @@ -61,6 +61,10 @@ BINDING(0) uniform texdisplay vec2 OutputRes; int RawOutput; float Slice; + + int SampleIdx; + int NumSamples; + vec2 Padding; }; BINDING(0) uniform FontUniforms @@ -83,7 +87,7 @@ BINDING(0) uniform HistogramCBufferData float HistogramSlice; int HistogramMip; int HistogramSample; - uint Padding2; + int HistogramNumSamples; vec3 HistogramTextureResolution; float Padding3; @@ -105,7 +109,8 @@ BINDING(0) uniform HistogramCBufferData #define RESTYPE_TEX2DARRAY 0x6 #define RESTYPE_TEXCUBEARRAY 0x7 #define RESTYPE_TEXRECT 0x8 -#define RESTYPE_TEXTYPEMAX 0x8 +#define RESTYPE_TEX2DMS 0x9 +#define RESTYPE_TEXTYPEMAX 0x9 #define TEXDISPLAY_TYPEMASK 0xF #define TEXDISPLAY_UINT_TEX 0x10 diff --git a/renderdoc/data/glsl/histogram.comp b/renderdoc/data/glsl/histogram.comp index 98d0c6126..371f7786b 100644 --- a/renderdoc/data/glsl/histogram.comp +++ b/renderdoc/data/glsl/histogram.comp @@ -71,8 +71,7 @@ void main() for(uint x=topleft.x; x < min(texDim.x, topleft.x + HGRAM_PIXELS_PER_TILE); x++) { uvec4 data = SampleTextureUInt4(vec2(x, y), texType, false, - HistogramMip, HistogramSlice); - // HistogramSample, texDim + HistogramMip, HistogramSlice, HistogramSample); if(i == 0) { @@ -101,8 +100,7 @@ void main() for(uint x=topleft.x; x < min(texDim.x, topleft.x + HGRAM_PIXELS_PER_TILE); x++) { ivec4 data = SampleTextureSInt4(vec2(x, y), texType, false, - HistogramMip, HistogramSlice); - // HistogramSample, texDim + HistogramMip, HistogramSlice, HistogramSample); if(i == 0) { @@ -131,8 +129,7 @@ void main() for(uint x=topleft.x; x < min(texDim.x, topleft.x + HGRAM_PIXELS_PER_TILE); x++) { vec4 data = SampleTextureFloat4(vec2(x, y), RESTYPE_TEX2D, false, true, - HistogramMip, HistogramSlice); - // HistogramSample, texDim + HistogramMip, HistogramSlice, HistogramSample, HistogramNumSamples); if(i == 0) { @@ -275,8 +272,7 @@ void main() #if UINT_TEX { uvec4 data = SampleTextureUInt4(vec2(x, y), texType, false, - HistogramMip, HistogramSlice); - // HistogramSample, texDim + HistogramMip, HistogramSlice, HistogramSample); float divisor = 0.0f; uint sum = 0; @@ -316,8 +312,7 @@ void main() #elif SINT_TEX { ivec4 data = SampleTextureSInt4(vec2(x, y), texType, false, - HistogramMip, HistogramSlice); - // HistogramSample, texDim + HistogramMip, HistogramSlice, HistogramSample); float divisor = 0.0f; int sum = 0; @@ -357,8 +352,7 @@ void main() #else { vec4 data = SampleTextureFloat4(vec2(x, y), texType, false, false, - HistogramMip, HistogramSlice); - // HistogramSample, texDim + HistogramMip, HistogramSlice, HistogramSample, HistogramNumSamples); float divisor = 0.0f; float sum = 0.0f; diff --git a/renderdoc/data/glsl/texdisplay.frag b/renderdoc/data/glsl/texdisplay.frag index c1bfbdebd..3b584ee8f 100644 --- a/renderdoc/data/glsl/texdisplay.frag +++ b/renderdoc/data/glsl/texdisplay.frag @@ -56,16 +56,15 @@ void main(void) // sample the texture. if (uintTex) { - ucol = SampleTextureUInt4(scr, texType, FlipY == 0, int(MipLevel), Slice); + ucol = SampleTextureUInt4(scr, texType, FlipY == 0, int(MipLevel), Slice, SampleIdx); } else if (sintTex) { - scol = SampleTextureSInt4(scr, texType, FlipY == 0, int(MipLevel), Slice); + scol = SampleTextureSInt4(scr, texType, FlipY == 0, int(MipLevel), Slice, SampleIdx); } else { - col = SampleTextureFloat4(scr / Scale, OutputDisplayFormat & TEXDISPLAY_TYPEMASK, FlipY == 0, (Scale < 1.0 && MipLevel == 0.0 && !depthTex), int(MipLevel), Slice); - col = SampleTextureFloat4(scr, texType, FlipY == 0, (Scale < 1.0 && MipLevel == 0.0 && !depthTex), int(MipLevel), Slice); + col = SampleTextureFloat4(scr, texType, FlipY == 0, (Scale < 1.0 && MipLevel == 0.0 && !depthTex), int(MipLevel), Slice, SampleIdx, NumSamples); } if(RawOutput != 0) diff --git a/renderdoc/data/glsl/texsample.h b/renderdoc/data/glsl/texsample.h index d7bf95d42..d43c5f1ad 100644 --- a/renderdoc/data/glsl/texsample.h +++ b/renderdoc/data/glsl/texsample.h @@ -30,6 +30,7 @@ layout (binding = 5) uniform sampler1DArray tex1DArray; layout (binding = 6) uniform sampler2DArray tex2DArray; layout (binding = 7) uniform samplerCubeArray texCubeArray; layout (binding = 8) uniform sampler2DRect tex2DRect; +layout (binding = 9) uniform sampler2DMS tex2DMS; layout (binding = 17) uniform usampler1D texUInt1D; layout (binding = 18) uniform usampler2D texUInt2D; @@ -37,6 +38,7 @@ layout (binding = 19) uniform usampler3D texUInt3D; layout (binding = 20) uniform usampler1DArray texUInt1DArray; layout (binding = 21) uniform usampler2DArray texUInt2DArray; layout (binding = 22) uniform usampler2DRect texUInt2DRect; +layout (binding = 23) uniform usampler2DMS texUInt2DMS; layout (binding = 33) uniform isampler1D texSInt1D; layout (binding = 34) uniform isampler2D texSInt2D; @@ -44,6 +46,7 @@ layout (binding = 35) uniform isampler3D texSInt3D; layout (binding = 36) uniform isampler1DArray texSInt1DArray; layout (binding = 37) uniform isampler2DArray texSInt2DArray; layout (binding = 38) uniform isampler2DRect texSInt2DRect; +layout (binding = 39) uniform isampler2DMS texSInt2DMS; vec3 CalcCubeCoord(vec2 uv, int face) { @@ -65,7 +68,7 @@ vec3 CalcCubeCoord(vec2 uv, int face) return coord; } -uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float slice) +uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float slice, int sampleIdx) { uvec4 col; if (type == RESTYPE_TEX1D) @@ -98,6 +101,18 @@ uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli col = texelFetch(texUInt2DRect, ivec2(pos)); } + else if (type == RESTYPE_TEX2DMS) + { + ivec2 size = textureSize(texUInt2DMS); + + if (flipY) + pos.y = size.y - pos.y; + + if(sampleIdx < 0) + sampleIdx = 0; + + col = texelFetch(texUInt2DMS, ivec2(pos), sampleIdx); + } else if (type == RESTYPE_TEX2DARRAY) { ivec3 size = textureSize(texUInt2DArray, mipLevel); @@ -120,7 +135,7 @@ uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli return col; } -ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float slice) +ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float slice, int sampleIdx) { ivec4 col; if (type == RESTYPE_TEX1D) @@ -153,6 +168,18 @@ ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli col = texelFetch(texSInt2DRect, ivec2(pos)); } + else if (type == RESTYPE_TEX2DMS) + { + ivec2 size = textureSize(texSInt2DMS); + + if (flipY) + pos.y = size.y - pos.y; + + if(sampleIdx < 0) + sampleIdx = 0; + + col = texelFetch(texSInt2DMS, ivec2(pos), sampleIdx); + } else if (type == RESTYPE_TEX2DARRAY) { ivec3 size = textureSize(texSInt2DArray, mipLevel); @@ -176,7 +203,7 @@ ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli } -vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, bool linearSample, int mipLevel, float slice) +vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, bool linearSample, int mipLevel, float slice, int sampleIdx, int sampleCount) { vec4 col; if (type == RESTYPE_TEX1D) @@ -218,6 +245,66 @@ vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, bool linearSample, int col = texelFetch(tex2DRect, ivec2(pos)); } + else if (type == RESTYPE_TEX2DMS) + { + ivec2 size = textureSize(tex2DMS); + + if (flipY) + pos.y = size.y - pos.y; + + if(sampleIdx < 0) + { + // worst resolve you've seen in your life + // it's manually unrolled because doing it as a dynamic loop on + // sampleCount seems to produce crazy artifacts on nvidia - probably a compiler bug + if(sampleCount == 2) + { + col += 0.5f*texelFetch(tex2DMS, ivec2(pos), 0); + col += 0.5f*texelFetch(tex2DMS, ivec2(pos), 1); + } + else if(sampleCount == 4) + { + col += 0.25f*texelFetch(tex2DMS, ivec2(pos), 0); + col += 0.25f*texelFetch(tex2DMS, ivec2(pos), 1); + col += 0.25f*texelFetch(tex2DMS, ivec2(pos), 2); + col += 0.25f*texelFetch(tex2DMS, ivec2(pos), 3); + } + else if(sampleCount == 8) + { + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 0); + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 1); + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 2); + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 3); + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 4); + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 5); + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 6); + col += 0.125f*texelFetch(tex2DMS, ivec2(pos), 7); + } + else if(sampleCount == 16) + { + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 0); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 1); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 2); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 3); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 4); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 5); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 6); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 7); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 8); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 9); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 10); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 11); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 12); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 13); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 14); + col += 0.0625f*texelFetch(tex2DMS, ivec2(pos), 15); + } + } + else + { + col = texelFetch(tex2DMS, ivec2(pos), sampleIdx); + } + } else if (type == RESTYPE_TEX2DARRAY) { ivec3 size = textureSize(tex2DArray, mipLevel); diff --git a/renderdoc/driver/d3d11/d3d11_debug.cpp b/renderdoc/driver/d3d11/d3d11_debug.cpp index 87c0a1da5..a568a5f46 100644 --- a/renderdoc/driver/d3d11/d3d11_debug.cpp +++ b/renderdoc/driver/d3d11/d3d11_debug.cpp @@ -3319,8 +3319,6 @@ bool D3D11DebugManager::RenderTexture(TextureDisplay cfg, bool blendAlpha) TextureShaderDetails details = GetShaderDetails(cfg.texid, cfg.rawoutput ? true : false); - static int sampIdx = 0; - pixelData.SampleIdx = (int)RDCCLAMP(cfg.sampleIdx, 0U, details.sampleCount-1); // hacky resolve diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index bc2913ff7..0b3cacfa1 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -334,6 +334,9 @@ bool GLReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uin case eGL_TEXTURE_2D: texSlot = RESTYPE_TEX2D; break; + case eGL_TEXTURE_2D_MULTISAMPLE: + texSlot = RESTYPE_TEX2DMS; + break; case eGL_TEXTURE_RECTANGLE: texSlot = RESTYPE_TEXRECT; break; @@ -394,6 +397,7 @@ bool GLReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uin cdata->HistogramTextureResolution.z = (float)RDCMAX(details.depth>>mip, 1U); cdata->HistogramSlice = (float)sliceFace; cdata->HistogramMip = (int)mip; + cdata->HistogramNumSamples = texDetails.samples; cdata->HistogramSample = (int)RDCCLAMP(sample, 0U, details.msSamp-1); if(sample == ~0U) cdata->HistogramSample = -int(details.msSamp); cdata->HistogramMin = 0.0f; @@ -487,6 +491,9 @@ bool GLReplay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mip, case eGL_TEXTURE_2D: texSlot = RESTYPE_TEX2D; break; + case eGL_TEXTURE_2D_MULTISAMPLE: + texSlot = RESTYPE_TEX2DMS; + break; case eGL_TEXTURE_RECTANGLE: texSlot = RESTYPE_TEXRECT; break; @@ -547,6 +554,7 @@ bool GLReplay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mip, cdata->HistogramTextureResolution.z = (float)RDCMAX(details.depth>>mip, 1U); cdata->HistogramSlice = (float)sliceFace; cdata->HistogramMip = mip; + cdata->HistogramNumSamples = texDetails.samples; cdata->HistogramSample = (int)RDCCLAMP(sample, 0U, details.msSamp-1); if(sample == ~0U) cdata->HistogramSample = -int(details.msSamp); cdata->HistogramMin = minval; @@ -663,6 +671,9 @@ bool GLReplay::RenderTexture(TextureDisplay cfg) case eGL_TEXTURE_2D: resType = RESTYPE_TEX2D; break; + case eGL_TEXTURE_2D_MULTISAMPLE: + resType = RESTYPE_TEX2DMS; + break; case eGL_TEXTURE_RECTANGLE: resType = RESTYPE_TEXRECT; break; @@ -876,6 +887,12 @@ bool GLReplay::RenderTexture(TextureDisplay cfg) ubo->OutputRes.x = DebugData.outWidth; ubo->OutputRes.y = DebugData.outHeight; + ubo->NumSamples = texDetails.samples; + ubo->SampleIdx = (int)RDCCLAMP(cfg.sampleIdx, 0U, (uint32_t)texDetails.samples-1); + + // hacky resolve + if(cfg.sampleIdx == ~0U) ubo->SampleIdx = -1; + gl.glUnmapBuffer(eGL_UNIFORM_BUFFER); if(cfg.rawoutput)