diff --git a/renderdoc/data/glsl/texsample.h b/renderdoc/data/glsl/texsample.h index a592c6742..26378d691 100644 --- a/renderdoc/data/glsl/texsample.h +++ b/renderdoc/data/glsl/texsample.h @@ -58,7 +58,12 @@ layout(binding = 8) uniform usampler2DRect texUInt2DRect; layout(binding = 9) uniform usamplerBuffer texUIntBuffer; layout(binding = 10) uniform usampler2DMS texUInt2DMS; -uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float slice, int sampleIdx) +vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) +{ + return vec4(0.0f, 0.0f, 0.0f, 0.0f); +} + +uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) { uvec4 col; if(type == RESTYPE_TEX1D) @@ -77,18 +82,12 @@ uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec2 size = textureSize(texUInt2D, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texUInt2D, ivec2(pos), mipLevel); } else if(type == RESTYPE_TEXRECT) { ivec2 size = textureSize(texUInt2DRect); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texUInt2DRect, ivec2(pos)); } else if(type == RESTYPE_TEXBUFFER) @@ -99,9 +98,6 @@ uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec2 size = textureSize(texUInt2DMS); - if(flipY) - pos.y = size.y - pos.y; - if(sampleIdx < 0) sampleIdx = 0; @@ -111,24 +107,23 @@ uvec4 SampleTextureUInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec3 size = textureSize(texUInt2DArray, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texUInt2DArray, ivec3(pos, slice), mipLevel); } else // if (type == RESTYPE_TEX3D) { ivec3 size = textureSize(texUInt3D, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texUInt3D, ivec3(pos, slice), mipLevel); } return col; } +ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) +{ + return ivec4(0, 0, 0, 0); +} + #elif SINT_TEX // these bindings are defined based on the RESTYPE_ defines in debuguniforms.h @@ -144,7 +139,17 @@ layout(binding = 8) uniform isampler2DRect texSInt2DRect; layout(binding = 9) uniform isamplerBuffer texSIntBuffer; layout(binding = 10) uniform isampler2DMS texSInt2DMS; -ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float slice, int sampleIdx) +vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) +{ + return vec4(0.0f, 0.0f, 0.0f, 0.0f); +} + +uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) +{ + return uvec4(0u, 0u, 0u, 0u); +} + +ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) { ivec4 col; if(type == RESTYPE_TEX1D) @@ -163,18 +168,12 @@ ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec2 size = textureSize(texSInt2D, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texSInt2D, ivec2(pos), mipLevel); } else if(type == RESTYPE_TEXRECT) { ivec2 size = textureSize(texSInt2DRect); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texSInt2DRect, ivec2(pos)); } else if(type == RESTYPE_TEXBUFFER) @@ -185,9 +184,6 @@ ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec2 size = textureSize(texSInt2DMS); - if(flipY) - pos.y = size.y - pos.y; - if(sampleIdx < 0) sampleIdx = 0; @@ -197,18 +193,12 @@ ivec4 SampleTextureSInt4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec3 size = textureSize(texSInt2DArray, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texSInt2DArray, ivec3(pos, slice), mipLevel); } else // if (type == RESTYPE_TEX3D) { ivec3 size = textureSize(texSInt3D, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(texSInt3D, ivec3(pos, slice), mipLevel); } @@ -230,8 +220,7 @@ layout(binding = 8) uniform sampler2DRect tex2DRect; layout(binding = 9) uniform samplerBuffer texBuffer; layout(binding = 10) uniform sampler2DMS tex2DMS; -vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, int mipLevel, float slice, int sampleIdx, - int sampleCount) +vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) { vec4 col; if(type == RESTYPE_TEX1D) @@ -250,18 +239,12 @@ vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec2 size = textureSize(tex2D, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = textureLod(tex2D, pos / size, float(mipLevel)); } else if(type == RESTYPE_TEXRECT) { ivec2 size = textureSize(tex2DRect); - if(flipY) - pos.y = size.y - pos.y; - col = texelFetch(tex2DRect, ivec2(pos)); } else if(type == RESTYPE_TEXBUFFER) @@ -272,11 +255,10 @@ vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec2 size = textureSize(tex2DMS); - if(flipY) - pos.y = size.y - pos.y; - if(sampleIdx < 0) { + int sampleCount = -sampleIdx; + // 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 @@ -332,27 +314,18 @@ vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec3 size = textureSize(tex2DArray, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = textureLod(tex2DArray, vec3(pos / size.xy, slice), float(mipLevel)); } else if(type == RESTYPE_TEX3D) { ivec3 size = textureSize(tex3D, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - col = textureLod(tex3D, vec3(pos / size.xy, slice / size.z), float(mipLevel)); } else if(type == RESTYPE_TEXCUBE) { ivec2 size = textureSize(texCube, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - vec3 cubeCoord = CalcCubeCoord(pos / size, int(slice)); col = textureLod(texCube, cubeCoord, float(mipLevel)); @@ -361,9 +334,6 @@ vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, int mipLevel, float sli { ivec3 size = textureSize(texCubeArray, mipLevel); - if(flipY) - pos.y = size.y - pos.y; - vec3 cubeCoord = CalcCubeCoord(pos / size.xy, int(slice) % 6); vec4 arrayCoord = vec4(cubeCoord, int(slice) / 6); @@ -373,4 +343,14 @@ vec4 SampleTextureFloat4(vec2 pos, int type, bool flipY, int mipLevel, float sli return col; } +uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) +{ + return uvec4(0u, 0u, 0u, 0u); +} + +ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes) +{ + return ivec4(0, 0, 0, 0); +} + #endif diff --git a/renderdoc/data/spv/debuguniforms.h b/renderdoc/data/spv/debuguniforms.h index 01f423c0f..12fabb0ce 100644 --- a/renderdoc/data/spv/debuguniforms.h +++ b/renderdoc/data/spv/debuguniforms.h @@ -188,8 +188,7 @@ BINDING(0) uniform TexDisplayUBOData float Slice; int SampleIdx; - int NumSamples; - vec2 Padding; + vec3 Padding; } INST_NAME(texdisplay); diff --git a/renderdoc/data/spv/texdisplay.frag b/renderdoc/data/spv/texdisplay.frag index 98a88f377..c046fc1c6 100644 --- a/renderdoc/data/spv/texdisplay.frag +++ b/renderdoc/data/spv/texdisplay.frag @@ -64,7 +64,7 @@ void main(void) vec2 scr = gl_FragCoord.xy; #ifdef OPENGL - scr.y = OutputRes.y - scr.y; + scr.y = texdisplay.OutputRes.y - scr.y; #endif scr -= texdisplay.Position.xy; @@ -90,7 +90,13 @@ void main(void) } } - if (texdisplay.FlipY != 0) +#ifdef VULKAN + const int defaultFlipY = 0; +#else // OPENGL + const int defaultFlipY = 1; +#endif + + if (texdisplay.FlipY != defaultFlipY) scr.y = texdisplay.TextureResolutionPS.y - scr.y; if(uintTex) diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index 0a2d329fd..81c3308ba 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -26,6 +26,7 @@ #include #include #include "data/glsl/debuguniforms.h" +#include "data/glsl_shaders.h" #include "maths/camera.h" #include "maths/formatpacking.h" #include "maths/matrix.h" @@ -80,6 +81,27 @@ GLuint GLReplay::CreateCShaderProgram(const char *csSrc) } GLuint GLReplay::CreateShaderProgram(const char *vsSrc, const char *fsSrc, const char *gsSrc) +{ + vector vs; + if(vsSrc) + vs.push_back(vsSrc); + vector fs; + if(fsSrc) + fs.push_back(fsSrc); + vector gs; + if(gsSrc) + gs.push_back(gsSrc); + return CreateShaderProgram(vs, fs, gs); +} + +GLuint GLReplay::CreateShaderProgram(const vector &vs, const vector &fs) +{ + vector empty; + return CreateShaderProgram(vs, fs, empty); +} + +GLuint GLReplay::CreateShaderProgram(const vector &vsSources, + const vector &fsSources, const vector &gsSources) { if(m_pDriver == NULL) return 0; @@ -95,10 +117,16 @@ GLuint GLReplay::CreateShaderProgram(const char *vsSrc, const char *fsSrc, const char buffer[1024]; GLint status = 0; - if(vsSrc) + if(!vsSources.empty()) { vs = gl.glCreateShader(eGL_VERTEX_SHADER); - gl.glShaderSource(vs, 1, &vsSrc, NULL); + + vector srcs; + srcs.reserve(vsSources.size()); + for(size_t i = 0; i < vsSources.size(); i++) + srcs.push_back(vsSources[i].c_str()); + + gl.glShaderSource(vs, (GLsizei)srcs.size(), &srcs[0], NULL); gl.glCompileShader(vs); @@ -110,10 +138,16 @@ GLuint GLReplay::CreateShaderProgram(const char *vsSrc, const char *fsSrc, const } } - if(fsSrc) + if(!fsSources.empty()) { fs = gl.glCreateShader(eGL_FRAGMENT_SHADER); - gl.glShaderSource(fs, 1, &fsSrc, NULL); + + vector srcs; + srcs.reserve(fsSources.size()); + for(size_t i = 0; i < fsSources.size(); i++) + srcs.push_back(fsSources[i].c_str()); + + gl.glShaderSource(fs, (GLsizei)srcs.size(), &srcs[0], NULL); gl.glCompileShader(fs); @@ -125,10 +159,16 @@ GLuint GLReplay::CreateShaderProgram(const char *vsSrc, const char *fsSrc, const } } - if(gsSrc) + if(!gsSources.empty()) { gs = gl.glCreateShader(eGL_GEOMETRY_SHADER); - gl.glShaderSource(gs, 1, &gsSrc, NULL); + + vector srcs; + srcs.reserve(gsSources.size()); + for(size_t i = 0; i < gsSources.size(); i++) + srcs.push_back(gsSources[i].c_str()); + + gl.glShaderSource(gs, (GLsizei)srcs.size(), &srcs[0], NULL); gl.glCompileShader(gs); @@ -198,27 +238,27 @@ void GLReplay::InitDebugData() DebugData.outWidth = 0.0f; DebugData.outHeight = 0.0f; - string blitvsSource = GetEmbeddedResource(glsl_blit_vert); - string blitfsSource = GetEmbeddedResource(glsl_blit_frag); + vector empty; - DebugData.blitProg = CreateShaderProgram(blitvsSource.c_str(), blitfsSource.c_str()); + vector vs; + vector fs; + vector gs; - string glslheader = "#version 420 core\n\n"; - glslheader += GetEmbeddedResource(glsl_debuguniforms_h); + GenerateGLSLShader(vs, eShaderGLSL, "", GetEmbeddedResource(spv_blit_vert), 420); + GenerateGLSLShader(fs, eShaderGLSL, "", GetEmbeddedResource(glsl_blit_frag), 420); - string texfs = GetEmbeddedResource(glsl_texsample_h); - texfs += GetEmbeddedResource(glsl_texdisplay_frag); + DebugData.blitProg = CreateShaderProgram(vs, fs); - DebugData.texDisplayVSProg = CreateShaderProgram(blitvsSource.c_str(), NULL); + DebugData.texDisplayVSProg = CreateShaderProgram(vs, empty); for(int i = 0; i < 3; i++) { - string glsl = glslheader; - glsl += string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; - glsl += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - glsl += texfs; + string defines = string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; + defines += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - DebugData.texDisplayProg[i] = CreateShaderProgram(NULL, glsl.c_str()); + GenerateGLSLShader(fs, eShaderGLSL, defines, GetEmbeddedResource(spv_texdisplay_frag), 420); + + DebugData.texDisplayProg[i] = CreateShaderProgram(empty, fs); } GLint numsl = 0; @@ -240,6 +280,9 @@ void GLReplay::InitDebugData() break; } + string blitvsSource = + "#version 420 core\n#define VERTEX_ID gl_VertexID" + GetEmbeddedResource(spv_blit_vert); + if(support450) { DebugData.quadoverdraw420 = false; @@ -285,7 +328,7 @@ void GLReplay::InitDebugData() string meshvs = GetEmbeddedResource(glsl_mesh_vert); string meshgs = GetEmbeddedResource(glsl_mesh_geom); string meshfs = GetEmbeddedResource(glsl_mesh_frag); - meshfs = glslheader + meshfs; + meshfs = "#version 420 core\n\n" + GetEmbeddedResource(glsl_debuguniforms_h) + meshfs; DebugData.meshProg = CreateShaderProgram(meshvs.c_str(), meshfs.c_str()); DebugData.meshgsProg = CreateShaderProgram(meshvs.c_str(), meshfs.c_str(), meshgs.c_str()); @@ -366,9 +409,6 @@ void GLReplay::InitDebugData() // histogram/minmax data { - string histogramglsl = GetEmbeddedResource(glsl_texsample_h); - histogramglsl += GetEmbeddedResource(glsl_histogram_comp); - RDCEraseEl(DebugData.minmaxTileProgram); RDCEraseEl(DebugData.histogramProgram); RDCEraseEl(DebugData.minmaxResultProgram); @@ -377,6 +417,12 @@ void GLReplay::InitDebugData() ARRAY_COUNT(DebugData.minmaxTileProgram) >= (TEXDISPLAY_SINT_TEX | TEXDISPLAY_TYPEMASK) + 1, "not enough programs"); + string glslheader = + "#version 420 core\n\n#extension GL_ARB_compute_shader : require\n#extension " + "GL_ARB_shader_storage_buffer_object : require\n"; + glslheader += GetEmbeddedResource(spv_debuguniforms_h); + glslheader += GetEmbeddedResource(glsl_texsample_h); + for(int t = 1; t <= RESTYPE_TEXTYPEMAX; t++) { // float, uint, sint @@ -393,8 +439,7 @@ void GLReplay::InitDebugData() glsl += string("#define SHADER_RESTYPE ") + ToStr::Get(t) + "\n"; glsl += string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; glsl += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - glsl += string("#define RENDERDOC_TileMinMaxCS 1\n"); - glsl += histogramglsl; + glsl += GetEmbeddedResource(spv_minmaxtile_comp); DebugData.minmaxTileProgram[idx] = CreateCShaderProgram(glsl.c_str()); } @@ -404,8 +449,7 @@ void GLReplay::InitDebugData() glsl += string("#define SHADER_RESTYPE ") + ToStr::Get(t) + "\n"; glsl += string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; glsl += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - glsl += string("#define RENDERDOC_HistogramCS 1\n"); - glsl += histogramglsl; + glsl += GetEmbeddedResource(spv_histogram_comp); DebugData.histogramProgram[idx] = CreateCShaderProgram(glsl.c_str()); } @@ -416,8 +460,7 @@ void GLReplay::InitDebugData() glsl += string("#define SHADER_RESTYPE ") + ToStr::Get(t) + "\n"; glsl += string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; glsl += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - glsl += string("#define RENDERDOC_ResultMinMaxCS 1\n"); - glsl += histogramglsl; + glsl += GetEmbeddedResource(spv_minmaxresult_comp); DebugData.minmaxResultProgram[i] = CreateCShaderProgram(glsl.c_str()); } @@ -1613,12 +1656,11 @@ bool GLReplay::RenderTextureInternal(TextureDisplay cfg, bool blendAlpha) 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; + ubo->SampleIdx = -texDetails.samples; gl.glUnmapBuffer(eGL_UNIFORM_BUFFER); diff --git a/renderdoc/driver/gl/gl_replay.h b/renderdoc/driver/gl/gl_replay.h index 9d175a9c8..cb7bcd046 100644 --- a/renderdoc/driver/gl/gl_replay.h +++ b/renderdoc/driver/gl/gl_replay.h @@ -367,6 +367,11 @@ private: void FillTimers(CounterContext &ctx, const DrawcallTreeNode &drawnode); + GLuint CreateShaderProgram(const vector &vs, const vector &fs, + const vector &gs); + GLuint CreateShaderProgram(const vector &vs, const vector &fs); + GLuint CreateCShaderProgram(const vector &cs); + GLuint CreateShaderProgram(const char *vs, const char *fs, const char *gs = NULL); GLuint CreateCShaderProgram(const char *cs); diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index 26d4350fd..260f58a6d 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -1223,7 +1223,6 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn data->Scale = cfg.scale * mipScale; - data->NumSamples = iminfo.samples; data->SampleIdx = cfg.sampleIdx; if(cfg.sampleIdx == ~0U)