diff --git a/renderdoc/data/glsl/debuguniforms.h b/renderdoc/data/glsl/debuguniforms.h index f624ffaaf..44e365dbe 100644 --- a/renderdoc/data/glsl/debuguniforms.h +++ b/renderdoc/data/glsl/debuguniforms.h @@ -195,7 +195,8 @@ BINDING(0) uniform TexDisplayUBOData float Slice; int SampleIdx; - vec3 Padding; + float MipShift; + vec2 Padding; } INST_NAME(texdisplay); diff --git a/renderdoc/data/glsl/gl_texsample.h b/renderdoc/data/glsl/gl_texsample.h index 26378d691..5af7e7555 100644 --- a/renderdoc/data/glsl/gl_texsample.h +++ b/renderdoc/data/glsl/gl_texsample.h @@ -68,52 +68,38 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp uvec4 col; if(type == RESTYPE_TEX1D) { - int size = textureSize(texUInt1D, mipLevel); - - col = texelFetch(texUInt1D, int(pos.x), mipLevel); + col = texelFetch(texUInt1D, int(pos.x * texRes.x), mipLevel); } else if(type == RESTYPE_TEX1DARRAY) { - ivec2 size = textureSize(texUInt1DArray, mipLevel); - - col = texelFetch(texUInt1DArray, ivec2(pos.x, slice), mipLevel); + col = texelFetch(texUInt1DArray, ivec2(pos.x * texRes.x, slice), mipLevel); } else if(type == RESTYPE_TEX2D) { - ivec2 size = textureSize(texUInt2D, mipLevel); - - col = texelFetch(texUInt2D, ivec2(pos), mipLevel); + col = texelFetch(texUInt2D, ivec2(pos * texRes.xy), mipLevel); } else if(type == RESTYPE_TEXRECT) { - ivec2 size = textureSize(texUInt2DRect); - - col = texelFetch(texUInt2DRect, ivec2(pos)); + col = texelFetch(texUInt2DRect, ivec2(pos * texRes.xy)); } else if(type == RESTYPE_TEXBUFFER) { - col = texelFetch(texUIntBuffer, int(pos.x)); + col = texelFetch(texUIntBuffer, int(pos.x * texRes.x)); } else if(type == RESTYPE_TEX2DMS) { - ivec2 size = textureSize(texUInt2DMS); - if(sampleIdx < 0) sampleIdx = 0; - col = texelFetch(texUInt2DMS, ivec2(pos), sampleIdx); + col = texelFetch(texUInt2DMS, ivec2(pos * texRes.xy), sampleIdx); } else if(type == RESTYPE_TEX2DARRAY) { - ivec3 size = textureSize(texUInt2DArray, mipLevel); - - col = texelFetch(texUInt2DArray, ivec3(pos, slice), mipLevel); + col = texelFetch(texUInt2DArray, ivec3(pos * texRes.xy, slice), mipLevel); } else // if (type == RESTYPE_TEX3D) { - ivec3 size = textureSize(texUInt3D, mipLevel); - - col = texelFetch(texUInt3D, ivec3(pos, slice), mipLevel); + col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice), mipLevel); } return col; @@ -154,52 +140,38 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp ivec4 col; if(type == RESTYPE_TEX1D) { - int size = textureSize(texSInt1D, mipLevel); - - col = texelFetch(texSInt1D, int(pos.x), mipLevel); + col = texelFetch(texSInt1D, int(pos.x * texRes.x), mipLevel); } else if(type == RESTYPE_TEX1DARRAY) { - ivec2 size = textureSize(texSInt1DArray, mipLevel); - - col = texelFetch(texSInt1DArray, ivec2(pos.x, slice), mipLevel); + col = texelFetch(texSInt1DArray, ivec2(pos.x * texRes.x, slice), mipLevel); } else if(type == RESTYPE_TEX2D) { - ivec2 size = textureSize(texSInt2D, mipLevel); - - col = texelFetch(texSInt2D, ivec2(pos), mipLevel); + col = texelFetch(texSInt2D, ivec2(pos * texRes.xy), mipLevel); } else if(type == RESTYPE_TEXRECT) { - ivec2 size = textureSize(texSInt2DRect); - - col = texelFetch(texSInt2DRect, ivec2(pos)); + col = texelFetch(texSInt2DRect, ivec2(pos * texRes.xy)); } else if(type == RESTYPE_TEXBUFFER) { - col = texelFetch(texSIntBuffer, int(pos.x)); + col = texelFetch(texSIntBuffer, int(pos.x * texRes.x)); } else if(type == RESTYPE_TEX2DMS) { - ivec2 size = textureSize(texSInt2DMS); - if(sampleIdx < 0) sampleIdx = 0; - col = texelFetch(texSInt2DMS, ivec2(pos), sampleIdx); + col = texelFetch(texSInt2DMS, ivec2(pos * texRes.xy), sampleIdx); } else if(type == RESTYPE_TEX2DARRAY) { - ivec3 size = textureSize(texSInt2DArray, mipLevel); - - col = texelFetch(texSInt2DArray, ivec3(pos, slice), mipLevel); + col = texelFetch(texSInt2DArray, ivec3(pos * texRes.xy, slice), mipLevel); } else // if (type == RESTYPE_TEX3D) { - ivec3 size = textureSize(texSInt3D, mipLevel); - - col = texelFetch(texSInt3D, ivec3(pos, slice), mipLevel); + col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice), mipLevel); } return col; @@ -225,36 +197,26 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp vec4 col; if(type == RESTYPE_TEX1D) { - int size = textureSize(tex1D, mipLevel); - - col = textureLod(tex1D, pos.x / size, float(mipLevel)); + col = textureLod(tex1D, pos.x, float(mipLevel)); } else if(type == RESTYPE_TEX1DARRAY) { - ivec2 size = textureSize(tex1DArray, mipLevel); - - col = textureLod(tex1DArray, vec2(pos.x / size.x, slice), float(mipLevel)); + col = textureLod(tex1DArray, vec2(pos.x, slice), float(mipLevel)); } else if(type == RESTYPE_TEX2D) { - ivec2 size = textureSize(tex2D, mipLevel); - - col = textureLod(tex2D, pos / size, float(mipLevel)); + col = textureLod(tex2D, pos, float(mipLevel)); } else if(type == RESTYPE_TEXRECT) { - ivec2 size = textureSize(tex2DRect); - - col = texelFetch(tex2DRect, ivec2(pos)); + col = texelFetch(tex2DRect, ivec2(pos * texRes.xy)); } else if(type == RESTYPE_TEXBUFFER) { - col = texelFetch(texBuffer, int(pos.x)); + col = texelFetch(texBuffer, int(pos.x * texRes.x)); } else if(type == RESTYPE_TEX2DMS) { - ivec2 size = textureSize(tex2DMS); - if(sampleIdx < 0) { int sampleCount = -sampleIdx; @@ -264,77 +226,69 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp // 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); + col += 0.5f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 0); + col += 0.5f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 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); + col += 0.25f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 0); + col += 0.25f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 1); + col += 0.25f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 2); + col += 0.25f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 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); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 0); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 1); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 2); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 3); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 4); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 5); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 6); + col += 0.125f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 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); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 0); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 1); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 2); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 3); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 4); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 5); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 6); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 7); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 8); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 9); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 10); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 11); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 12); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 13); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 14); + col += 0.0625f * texelFetch(tex2DMS, ivec2(pos * texRes.xy), 15); } } else { - col = texelFetch(tex2DMS, ivec2(pos), sampleIdx); + col = texelFetch(tex2DMS, ivec2(pos * texRes.xy), sampleIdx); } } else if(type == RESTYPE_TEX2DARRAY) { - ivec3 size = textureSize(tex2DArray, mipLevel); - - col = textureLod(tex2DArray, vec3(pos / size.xy, slice), float(mipLevel)); + col = textureLod(tex2DArray, vec3(pos, slice), float(mipLevel)); } else if(type == RESTYPE_TEX3D) { - ivec3 size = textureSize(tex3D, mipLevel); - - col = textureLod(tex3D, vec3(pos / size.xy, slice / size.z), float(mipLevel)); + col = textureLod(tex3D, vec3(pos, slice / texRes.z), float(mipLevel)); } else if(type == RESTYPE_TEXCUBE) { - ivec2 size = textureSize(texCube, mipLevel); - - vec3 cubeCoord = CalcCubeCoord(pos / size, int(slice)); + vec3 cubeCoord = CalcCubeCoord(pos, int(slice)); col = textureLod(texCube, cubeCoord, float(mipLevel)); } else // type == RESTYPE_TEXCUBEARRAY { - ivec3 size = textureSize(texCubeArray, mipLevel); - - vec3 cubeCoord = CalcCubeCoord(pos / size.xy, int(slice) % 6); + vec3 cubeCoord = CalcCubeCoord(pos, int(slice) % 6); vec4 arrayCoord = vec4(cubeCoord, int(slice) / 6); col = textureLod(texCubeArray, arrayCoord, float(mipLevel)); diff --git a/renderdoc/data/glsl/histogram.comp b/renderdoc/data/glsl/histogram.comp index 23fda0d7a..8742c9e88 100644 --- a/renderdoc/data/glsl/histogram.comp +++ b/renderdoc/data/glsl/histogram.comp @@ -54,7 +54,7 @@ void main() #if UINT_TEX { - uvec4 data = SampleTextureUInt4(texType, vec2(x, y), + uvec4 data = SampleTextureUInt4(texType, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, histogram_minmax.HistogramSlice, histogram_minmax.HistogramMip, histogram_minmax.HistogramSample, @@ -97,7 +97,7 @@ void main() } #elif SINT_TEX { - ivec4 data = SampleTextureSInt4(texType, vec2(x, y), + ivec4 data = SampleTextureSInt4(texType, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, histogram_minmax.HistogramSlice, histogram_minmax.HistogramMip, histogram_minmax.HistogramSample, @@ -140,7 +140,7 @@ void main() } #else { - vec4 data = SampleTextureFloat4(texType, vec2(x, y), + vec4 data = SampleTextureFloat4(texType, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, histogram_minmax.HistogramSlice, histogram_minmax.HistogramMip, histogram_minmax.HistogramSample, diff --git a/renderdoc/data/glsl/minmaxtile.comp b/renderdoc/data/glsl/minmaxtile.comp index 07bf2f014..fccca120a 100644 --- a/renderdoc/data/glsl/minmaxtile.comp +++ b/renderdoc/data/glsl/minmaxtile.comp @@ -63,7 +63,7 @@ void main() { for(uint x=topleft.x; x < min(texDim.x, topleft.x + HGRAM_PIXELS_PER_TILE); x++) { - uvec4 data = SampleTextureUInt4(texType, vec2(x, y), + uvec4 data = SampleTextureUInt4(texType, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, histogram_minmax.HistogramSlice, histogram_minmax.HistogramMip, histogram_minmax.HistogramSample, @@ -95,7 +95,7 @@ void main() { for(uint x=topleft.x; x < min(texDim.x, topleft.x + HGRAM_PIXELS_PER_TILE); x++) { - ivec4 data = SampleTextureSInt4(texType, vec2(x, y), + ivec4 data = SampleTextureSInt4(texType, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, histogram_minmax.HistogramSlice, histogram_minmax.HistogramMip, histogram_minmax.HistogramSample, @@ -127,7 +127,7 @@ void main() { for(uint x=topleft.x; x < min(texDim.x, topleft.x + HGRAM_PIXELS_PER_TILE); x++) { - vec4 data = SampleTextureFloat4(texType, vec2(x, y), + vec4 data = SampleTextureFloat4(texType, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, histogram_minmax.HistogramSlice, histogram_minmax.HistogramMip, histogram_minmax.HistogramSample, diff --git a/renderdoc/data/glsl/texdisplay.frag b/renderdoc/data/glsl/texdisplay.frag index c046fc1c6..c7d2d474f 100644 --- a/renderdoc/data/glsl/texdisplay.frag +++ b/renderdoc/data/glsl/texdisplay.frag @@ -69,8 +69,13 @@ void main(void) scr -= texdisplay.Position.xy; + scr /= texdisplay.TextureResolutionPS.xy; + scr /= texdisplay.Scale; + scr /= vec2(texdisplay.MipShift, texdisplay.MipShift); + vec2 scr2 = scr; + #ifdef VULKAN if(texType == RESTYPE_TEX1D) #else @@ -78,13 +83,13 @@ void main(void) #endif { // by convention display 1D textures as 100 high - if(scr.x < 0.0f || scr.x > texdisplay.TextureResolutionPS.x || scr.y < 0.0f || scr.y > 100.0f) + if(scr2.x < 0.0f || scr2.x > 1.0f || scr2.y < 0.0f || scr2.y > 100.0f) discard; } else { - if(scr.x < 0.0f || scr.y < 0.0f || - scr.x > texdisplay.TextureResolutionPS.x || scr.y > texdisplay.TextureResolutionPS.y) + if(scr2.x < 0.0f || scr2.y < 0.0f || + scr2.x > 1.0f || scr2.y > 1.0f) { discard; } @@ -97,7 +102,7 @@ void main(void) #endif if (texdisplay.FlipY != defaultFlipY) - scr.y = texdisplay.TextureResolutionPS.y - scr.y; + scr.y = 1.0f - scr.y; if(uintTex) { diff --git a/renderdoc/data/glsl/vk_texsample.h b/renderdoc/data/glsl/vk_texsample.h index 022a8b28e..79d6c4769 100644 --- a/renderdoc/data/glsl/vk_texsample.h +++ b/renderdoc/data/glsl/vk_texsample.h @@ -22,26 +22,6 @@ * THE SOFTWARE. ******************************************************************************/ -vec3 CalcCubeCoord(vec2 uv, int face) -{ - // From table 8.19 in GL4.5 spec - // Map UVs to [-0.5, 0.5] and rotate - uv -= vec2(0.5); - vec3 coord; - if(face == CUBEMAP_FACE_POS_X) - coord = vec3(0.5, -uv.y, -uv.x); - else if(face == CUBEMAP_FACE_NEG_X) - coord = vec3(-0.5, -uv.y, uv.x); - else if(face == CUBEMAP_FACE_POS_Y) - coord = vec3(uv.x, 0.5, uv.y); - else if(face == CUBEMAP_FACE_NEG_Y) - coord = vec3(uv.x, -0.5, -uv.y); - else if(face == CUBEMAP_FACE_POS_Z) - coord = vec3(uv.x, -uv.y, 0.5); - else // face == CUBEMAP_FACE_NEG_Z - coord = vec3(-uv.x, -uv.y, -0.5); - return coord; -} // these bindings are defined based on the RESTYPE_ defines in debuguniforms.h // binding = 5 + RESTYPE_x @@ -56,15 +36,15 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp if(type == RESTYPE_TEX1D) { - col = textureLod(tex1DArray, vec2(pos.x / texRes.x, slice), float(mipLevel)); + col = textureLod(tex1DArray, vec2(pos.x, slice), float(mipLevel)); } else if(type == RESTYPE_TEX2D) { - col = textureLod(tex2DArray, vec3(pos / texRes.xy, slice), float(mipLevel)); + col = textureLod(tex2DArray, vec3(pos, slice), float(mipLevel)); } else if(type == RESTYPE_TEX3D) { - col = textureLod(tex3D, vec3(pos / texRes.xy, slice / texRes.z), float(mipLevel)); + col = textureLod(tex3D, vec3(pos, slice / texRes.z), float(mipLevel)); } else if(type == RESTYPE_TEX2DMS) { @@ -79,13 +59,13 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp // worst resolve you've seen in your life for(int i = 0; i < sampleCount; i++) - col += texelFetch(tex2DMS, ivec2(pos), i); + col += texelFetch(tex2DMS, ivec2(pos * texRes.xy), i); col /= float(sampleCount); } else { - col = texelFetch(tex2DMS, ivec2(pos), sampleIdx); + col = texelFetch(tex2DMS, ivec2(pos * texRes.xy), sampleIdx); } #endif } @@ -108,22 +88,22 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp #ifndef NO_TEXEL_FETCH if(type == RESTYPE_TEX1D) { - col = texelFetch(texUInt1DArray, ivec2(pos.x, slice), mipLevel); + col = texelFetch(texUInt1DArray, ivec2(pos.x * texRes.x, slice), mipLevel); } else if(type == RESTYPE_TEX2D) { - col = texelFetch(texUInt2DArray, ivec3(pos, slice), mipLevel); + col = texelFetch(texUInt2DArray, ivec3(pos * texRes.xy, slice), mipLevel); } else if(type == RESTYPE_TEX3D) { - col = texelFetch(texUInt3D, ivec3(pos, slice), mipLevel); + col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice), mipLevel); } else if(type == RESTYPE_TEX2DMS) { if(sampleIdx < 0) sampleIdx = 0; - col = texelFetch(texUInt2DMS, ivec2(pos), sampleIdx); + col = texelFetch(texUInt2DMS, ivec2(pos * texRes.xy), sampleIdx); } #endif @@ -145,22 +125,22 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp #ifndef NO_TEXEL_FETCH if(type == RESTYPE_TEX1D) { - col = texelFetch(texSInt1DArray, ivec2(pos.x, slice), mipLevel); + col = texelFetch(texSInt1DArray, ivec2(pos.x * texRes.x, slice), mipLevel); } else if(type == RESTYPE_TEX2D) { - col = texelFetch(texSInt2DArray, ivec3(pos, slice), mipLevel); + col = texelFetch(texSInt2DArray, ivec3(pos * texRes.xy, slice), mipLevel); } else if(type == RESTYPE_TEX3D) { - col = texelFetch(texSInt3D, ivec3(pos, slice), mipLevel); + col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice), mipLevel); } else if(type == RESTYPE_TEX2DMS) { if(sampleIdx < 0) sampleIdx = 0; - col = texelFetch(texSInt2DMS, ivec2(pos), sampleIdx); + col = texelFetch(texSInt2DMS, ivec2(pos * texRes.xy), sampleIdx); } #endif diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index efd2a7d60..a726e8621 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -1390,7 +1390,7 @@ void GLReplay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, uint32_t sl texDisplay.offx = -float(x); texDisplay.offy = -float(y); - RenderTextureInternal(texDisplay, false); + RenderTextureInternal(texDisplay, eTexDisplay_MipShift); gl.glReadPixels(0, 0, 1, 1, eGL_RGBA, eGL_FLOAT, (void *)pixel); @@ -1405,7 +1405,7 @@ void GLReplay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, uint32_t sl { texDisplay.Red = texDisplay.Blue = texDisplay.Alpha = false; - RenderTextureInternal(texDisplay, false); + RenderTextureInternal(texDisplay, eTexDisplay_MipShift); uint32_t stencilpixel[4]; gl.glReadPixels(0, 0, 1, 1, eGL_RGBA, eGL_FLOAT, (void *)stencilpixel); @@ -1491,11 +1491,14 @@ void GLReplay::CopyTex2DMSToArray(GLuint destArray, GLuint srcMS, GLint width, G bool GLReplay::RenderTexture(TextureDisplay cfg) { - return RenderTextureInternal(cfg, true); + return RenderTextureInternal(cfg, eTexDisplay_BlendAlpha | eTexDisplay_MipShift); } -bool GLReplay::RenderTextureInternal(TextureDisplay cfg, bool blendAlpha) +bool GLReplay::RenderTextureInternal(TextureDisplay cfg, int flags) { + const bool blendAlpha = (flags & eTexDisplay_BlendAlpha) != 0; + const bool mipShift = (flags & eTexDisplay_MipShift) != 0; + WrappedOpenGL &gl = *m_pDriver; auto &texDetails = m_pDriver->m_Textures[cfg.texid]; @@ -1781,16 +1784,14 @@ bool GLReplay::RenderTextureInternal(TextureDisplay cfg, bool blendAlpha) ubo->RawOutput = cfg.rawoutput ? 1 : 0; - ubo->TextureResolutionPS.x = float(tex_x); - ubo->TextureResolutionPS.y = float(tex_y); - ubo->TextureResolutionPS.z = float(tex_z); + ubo->TextureResolutionPS.x = float(RDCMAX(1, tex_x >> cfg.mip)); + ubo->TextureResolutionPS.y = float(RDCMAX(1, tex_y >> cfg.mip)); + ubo->TextureResolutionPS.z = float(RDCMAX(1, tex_z >> cfg.mip)); - float mipScale = float(1 << cfg.mip); - - ubo->Scale *= mipScale; - ubo->TextureResolutionPS.x /= mipScale; - ubo->TextureResolutionPS.y /= mipScale; - ubo->TextureResolutionPS.z /= mipScale; + if(mipShift) + ubo->MipShift = float(1 << cfg.mip); + else + ubo->MipShift = 1.0f; ubo->OutputRes.x = DebugData.outWidth; ubo->OutputRes.y = DebugData.outHeight; diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index 1911c5d48..f88d9ceaa 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -2305,7 +2305,7 @@ byte *GLReplay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip, gl.glViewport(0, 0, width, height); - RenderTextureInternal(texDisplay, false); + RenderTextureInternal(texDisplay, 0); } DebugData.outWidth = oldW; @@ -2625,7 +2625,7 @@ ResourceId GLReplay::ApplyCustomShader(ResourceId shader, ResourceId texid, uint disp.scale = 1.0f; disp.sliceFace = arrayIdx; - RenderTextureInternal(disp, false); + RenderTextureInternal(disp, eTexDisplay_MipShift); return DebugData.CustomShaderTexID; } diff --git a/renderdoc/driver/gl/gl_replay.h b/renderdoc/driver/gl/gl_replay.h index bdde19039..7f20489df 100644 --- a/renderdoc/driver/gl/gl_replay.h +++ b/renderdoc/driver/gl/gl_replay.h @@ -169,8 +169,14 @@ public: ShaderStageType type, ResourceId *id, string *errors); void FreeCustomShader(ResourceId id); + enum TexDisplayFlags + { + eTexDisplay_BlendAlpha = 0x1, + eTexDisplay_MipShift = 0x2, + }; + bool RenderTexture(TextureDisplay cfg); - bool RenderTextureInternal(TextureDisplay cfg, bool blendAlpha); + bool RenderTextureInternal(TextureDisplay cfg, int flags); void RenderCheckerboard(Vec3f light, Vec3f dark); diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index f9cbf2897..a23038d2c 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -987,7 +987,7 @@ void VulkanReplay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, uint32_ &clearval, }; - RenderTextureInternal(texDisplay, rpbegin, true); + RenderTextureInternal(texDisplay, rpbegin, eTexDisplay_F32Render | eTexDisplay_MipShift); } VkDevice dev = m_pDriver->GetDev(); @@ -1110,12 +1110,15 @@ bool VulkanReplay::RenderTexture(TextureDisplay cfg) &clearval, }; - return RenderTextureInternal(cfg, rpbegin, false); + return RenderTextureInternal(cfg, rpbegin, eTexDisplay_MipShift | eTexDisplay_BlendAlpha); } -bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginInfo rpbegin, - bool f32render) +bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginInfo rpbegin, int flags) { + const bool blendAlpha = (flags & eTexDisplay_BlendAlpha) != 0; + const bool mipShift = (flags & eTexDisplay_MipShift) != 0; + const bool f32render = (flags & eTexDisplay_F32Render) != 0; + VkDevice dev = m_pDriver->GetDev(); VkCommandBuffer cmd = m_pDriver->GetNextCmd(); const VkLayerDispatchTable *vt = ObjDisp(dev); @@ -1227,13 +1230,16 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn else data->Slice = (float)(cfg.sliceFace >> cfg.mip); - float mipScale = float(1 << cfg.mip); + data->TextureResolutionPS.x = float(RDCMAX(1, tex_x >> cfg.mip)); + data->TextureResolutionPS.y = float(RDCMAX(1, tex_y >> cfg.mip)); + data->TextureResolutionPS.z = float(RDCMAX(1, tex_z >> cfg.mip)); - data->TextureResolutionPS.x = float(tex_x) / mipScale; - data->TextureResolutionPS.y = float(tex_y) / mipScale; - data->TextureResolutionPS.z = float(tex_z) / mipScale; + if(mipShift) + data->MipShift = float(1 << cfg.mip); + else + data->MipShift = 1.0f; - data->Scale = cfg.scale * mipScale; + data->Scale = cfg.scale; int sampleIdx = (int)RDCCLAMP(cfg.sampleIdx, 0U, (uint32_t)SampleCount(iminfo.samples)); @@ -1389,7 +1395,7 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn { pipe = GetDebugManager()->m_TexDisplayF32Pipeline; } - else if(!cfg.rawoutput && cfg.CustomShader == ResourceId()) + else if(!cfg.rawoutput && blendAlpha && cfg.CustomShader == ResourceId()) { pipe = GetDebugManager()->m_TexDisplayBlendPipeline; } @@ -4816,7 +4822,7 @@ byte *VulkanReplay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t m &clearval, }; - RenderTextureInternal(texDisplay, rpbegin, false); + RenderTextureInternal(texDisplay, rpbegin, 0); } m_DebugWidth = oldW; @@ -5438,7 +5444,7 @@ ResourceId VulkanReplay::ApplyCustomShader(ResourceId shader, ResourceId texid, &clearval, }; - RenderTextureInternal(disp, rpbegin, false); + RenderTextureInternal(disp, rpbegin, eTexDisplay_MipShift); m_DebugWidth = oldW; m_DebugHeight = oldH; diff --git a/renderdoc/driver/vulkan/vk_replay.h b/renderdoc/driver/vulkan/vk_replay.h index 1ef86cf47..f737ed154 100644 --- a/renderdoc/driver/vulkan/vk_replay.h +++ b/renderdoc/driver/vulkan/vk_replay.h @@ -331,7 +331,14 @@ private: WrappedVulkan *m_pDriver; - bool RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginInfo rpbegin, bool f32render); + enum TexDisplayFlags + { + eTexDisplay_F32Render = 0x1, + eTexDisplay_BlendAlpha = 0x2, + eTexDisplay_MipShift = 0x4, + }; + + bool RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginInfo rpbegin, int flags); void CreateTexImageView(VkImageAspectFlags aspectFlags, VkImage liveIm, VulkanCreationInfo::Image &iminfo);