From 15d60ef6b958812dc7a5da7cdf1f4abcbd8409ba Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 22 Jul 2016 02:26:37 +0200 Subject: [PATCH] Convert rest of GL shaders to use spv_ variants --- renderdoc/CMakeLists.txt | 2 + renderdoc/data/embedded_files.h | 2 + renderdoc/data/glsl_shaders.cpp | 2 +- renderdoc/data/renderdoc.rc | 2 + renderdoc/data/resource.h | 2 + renderdoc/data/spv/array2ms.comp | 47 ++++ renderdoc/data/spv/fixedcol.frag | 6 +- renderdoc/data/spv/mesh.comp | 2 + renderdoc/data/spv/ms2array.comp | 47 ++++ renderdoc/driver/gl/gl_debug.cpp | 283 +++++++++++------------- renderdoc/driver/gl/gl_replay.cpp | 16 +- renderdoc/driver/gl/gl_replay.h | 19 +- renderdoc/driver/gl/gl_replay_linux.cpp | 5 + renderdoc/driver/gl/gl_replay_win32.cpp | 5 + renderdoc/renderdoc.vcxproj | 2 + renderdoc/renderdoc.vcxproj.filters | 6 + 16 files changed, 277 insertions(+), 171 deletions(-) create mode 100644 renderdoc/data/spv/array2ms.comp create mode 100644 renderdoc/data/spv/ms2array.comp diff --git a/renderdoc/CMakeLists.txt b/renderdoc/CMakeLists.txt index 509b1b8da..f17b73073 100644 --- a/renderdoc/CMakeLists.txt +++ b/renderdoc/CMakeLists.txt @@ -231,6 +231,8 @@ set(data data/spv/texsample.h data/spv/text.frag data/spv/text.vert + data/spv/array2ms.comp + data/spv/ms2array.comp data/sourcecodepro.ttf) set(data_objects) diff --git a/renderdoc/data/embedded_files.h b/renderdoc/data/embedded_files.h index 8678149ba..00a42d709 100644 --- a/renderdoc/data/embedded_files.h +++ b/renderdoc/data/embedded_files.h @@ -66,5 +66,7 @@ DECLARE_EMBED(spv_texsample_h); DECLARE_EMBED(spv_quadresolve_frag); DECLARE_EMBED(spv_quadwrite_frag); DECLARE_EMBED(spv_mesh_comp); +DECLARE_EMBED(spv_array2ms_comp); +DECLARE_EMBED(spv_ms2array_comp); #undef DECLARE_EMBED diff --git a/renderdoc/data/glsl_shaders.cpp b/renderdoc/data/glsl_shaders.cpp index f9e2ffa54..f0644bf51 100644 --- a/renderdoc/data/glsl_shaders.cpp +++ b/renderdoc/data/glsl_shaders.cpp @@ -47,7 +47,7 @@ void GenerateGLSLShader(std::vector &sources, ShaderType type, sources[0] += shader.substr(begin, extsearch - begin + 1); } while(extsearch != string::npos); - sources[0] += "\n" + defines; + sources[0] += "\n" + defines + "\n"; if(uniforms) sources[1] = GetEmbeddedResource(spv_debuguniforms_h); diff --git a/renderdoc/data/renderdoc.rc b/renderdoc/data/renderdoc.rc index 22569a661..54cea2aba 100644 --- a/renderdoc/data/renderdoc.rc +++ b/renderdoc/data/renderdoc.rc @@ -149,6 +149,8 @@ RESOURCE_spv_texsample_h TYPE_EMBED "spv/texsample.h" RESOURCE_spv_quadresolve_frag TYPE_EMBED "spv/quadresolve.frag" RESOURCE_spv_quadwrite_frag TYPE_EMBED "spv/quadwrite.frag" RESOURCE_spv_mesh_comp TYPE_EMBED "spv/mesh.comp" +RESOURCE_spv_array2ms_comp TYPE_EMBED "spv/array2ms.comp" +RESOURCE_spv_ms2array_comp TYPE_EMBED "spv/ms2array.comp" #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// diff --git a/renderdoc/data/resource.h b/renderdoc/data/resource.h index f2014a458..f0918d051 100644 --- a/renderdoc/data/resource.h +++ b/renderdoc/data/resource.h @@ -51,6 +51,8 @@ #define RESOURCE_spv_quadresolve_frag 418 #define RESOURCE_spv_quadwrite_frag 419 #define RESOURCE_spv_mesh_comp 420 +#define RESOURCE_spv_array2ms_comp 421 +#define RESOURCE_spv_ms2array_comp 422 #if !defined(STRINGIZE) #define STRINGIZE2(a) #a diff --git a/renderdoc/data/spv/array2ms.comp b/renderdoc/data/spv/array2ms.comp new file mode 100644 index 000000000..922e70a56 --- /dev/null +++ b/renderdoc/data/spv/array2ms.comp @@ -0,0 +1,47 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015-2016 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +//#extension GL_ARB_compute_shader : require + +layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +layout(binding = 0) uniform usampler2DArray srcArray; +layout(binding = 1) writeonly uniform uimage2DMSArray dstMS; + +layout (binding = 2, std140) uniform multisampleUBO +{ + int numMultiSamples; +} mscopy; + +void main() +{ + uvec3 id = gl_GlobalInvocationID; + + int slice = int(id.z / mscopy.numMultiSamples); + int sampleIdx = int(id.z % mscopy.numMultiSamples); + + uvec4 data = texelFetch(srcArray, ivec3(int(id.x), int(id.y), int(id.z)), 0); + + imageStore(dstMS, ivec3(int(id.x), int(id.y), slice), sampleIdx, data); +} \ No newline at end of file diff --git a/renderdoc/data/spv/fixedcol.frag b/renderdoc/data/spv/fixedcol.frag index 63c6e6153..9b6c26639 100644 --- a/renderdoc/data/spv/fixedcol.frag +++ b/renderdoc/data/spv/fixedcol.frag @@ -25,8 +25,8 @@ layout (location = 0) out vec4 color_out; -#ifndef VULKAN // OpenGL can't use SPIR-V patching -uniform vec4 RENDERDOC_GenericFS_Color; +#ifdef OPENGL // OpenGL can't use SPIR-V patching +uniform vec4 RENDERDOC_Fixed_Color; #endif void main(void) @@ -38,6 +38,6 @@ void main(void) // on the fly to replace these constants color_out = vec4(1.1f, 2.2f, 3.3f, 4.4f); #else - color_out = RENDERDOC_GenericFS_Color; + color_out = RENDERDOC_Fixed_Color; #endif } diff --git a/renderdoc/data/spv/mesh.comp b/renderdoc/data/spv/mesh.comp index d06ddfbab..81ae3e9a9 100644 --- a/renderdoc/data/spv/mesh.comp +++ b/renderdoc/data/spv/mesh.comp @@ -60,6 +60,8 @@ void main() #ifdef VULKAN if(meshpick.unproject == 0u) wpos.xy *= vec2(1.0f, -1.0f); +#else // OPENGL + wpos.xy *= vec2(1.0f, -1.0f); #endif vec2 scr = (wpos.xy + 1.0f) * 0.5f * meshpick.viewport; diff --git a/renderdoc/data/spv/ms2array.comp b/renderdoc/data/spv/ms2array.comp new file mode 100644 index 000000000..e8c5fd7d6 --- /dev/null +++ b/renderdoc/data/spv/ms2array.comp @@ -0,0 +1,47 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015-2016 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +//#extension GL_ARB_compute_shader : require + +layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +layout(binding = 0) uniform usampler2DMSArray srcMS; +layout(binding = 1) writeonly uniform uimage2DArray dstArray; + +layout (binding = 2, std140) uniform multisampleUBO +{ + int numMultiSamples; +} mscopy; + +void main() +{ + uvec3 id = gl_GlobalInvocationID; + + int slice = int(id.z / mscopy.numMultiSamples); + int sampleIdx = int(id.z % mscopy.numMultiSamples); + + uvec4 data = texelFetch(srcMS, ivec3(int(id.x), int(id.y), slice), sampleIdx); + + imageStore(dstArray, ivec3(int(id.x), int(id.y), int(id.z)), data); +} diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index c0acd3536..1ef54de75 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -38,7 +38,7 @@ #define OPENGL 1 #include "data/spv/debuguniforms.h" -GLuint GLReplay::CreateCShaderProgram(const char *csSrc) +GLuint GLReplay::CreateCShaderProgram(const vector &csSources) { if(m_pDriver == NULL) return 0; @@ -49,7 +49,12 @@ GLuint GLReplay::CreateCShaderProgram(const char *csSrc) GLuint cs = gl.glCreateShader(eGL_COMPUTE_SHADER); - gl.glShaderSource(cs, 1, &csSrc, NULL); + vector srcs; + srcs.reserve(csSources.size()); + for(size_t i = 0; i < csSources.size(); i++) + srcs.push_back(csSources[i].c_str()); + + gl.glShaderSource(cs, (GLsizei)srcs.size(), &srcs[0], NULL); gl.glCompileShader(cs); @@ -83,20 +88,6 @@ GLuint GLReplay::CreateCShaderProgram(const char *csSrc) return ret; } -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; @@ -246,11 +237,9 @@ void GLReplay::InitDebugData() vector vs; vector fs; vector gs; + vector cs; GenerateGLSLShader(vs, eShaderGLSL, "", GetEmbeddedResource(spv_blit_vert), 420); - GenerateGLSLShader(fs, eShaderGLSL, "", GetEmbeddedResource(glsl_blit_frag), 420); - - DebugData.blitProg = CreateShaderProgram(vs, fs); DebugData.texDisplayVSProg = CreateShaderProgram(vs, empty); @@ -311,11 +300,9 @@ void GLReplay::InitDebugData() GenerateGLSLShader(fs, eShaderGLSL, "", GetEmbeddedResource(spv_checkerboard_frag), 420); DebugData.checkerProg = CreateShaderProgram(vs, fs); - string genericvsSource = GetEmbeddedResource(glsl_generic_vert); - string genericfsSource = GetEmbeddedResource(glsl_generic_frag); + GenerateGLSLShader(fs, eShaderGLSL, "", GetEmbeddedResource(spv_fixedcol_frag), 420); - DebugData.genericProg = CreateShaderProgram(genericvsSource.c_str(), genericfsSource.c_str()); - DebugData.genericFSProg = CreateShaderProgram(NULL, genericfsSource.c_str()); + DebugData.fixedcolFSProg = CreateShaderProgram(empty, fs); GenerateGLSLShader(vs, eShaderGLSL, "", GetEmbeddedResource(spv_mesh_vert), 420); GenerateGLSLShader(fs, eShaderGLSL, "", GetEmbeddedResource(spv_mesh_frag), 420); @@ -328,23 +315,6 @@ void GLReplay::InitDebugData() RenderDoc::Inst().SetProgress(DebugManagerInit, 0.4f); - { - float data[] = { - 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.1f, 0.0f, 1.0f, - }; - - gl.glGenBuffers(1, &DebugData.outlineStripVB); - gl.glBindBuffer(eGL_ARRAY_BUFFER, DebugData.outlineStripVB); - gl.glNamedBufferDataEXT(DebugData.outlineStripVB, sizeof(data), data, eGL_STATIC_DRAW); - - gl.glGenVertexArrays(1, &DebugData.outlineStripVAO); - gl.glBindVertexArray(DebugData.outlineStripVAO); - - gl.glVertexAttribPointer(0, 4, eGL_FLOAT, false, 0, (const void *)0); - gl.glEnableVertexAttribArray(0); - } - gl.glGenSamplers(1, &DebugData.linearSampler); gl.glSamplerParameteri(DebugData.linearSampler, eGL_TEXTURE_MIN_FILTER, eGL_LINEAR); gl.glSamplerParameteri(DebugData.linearSampler, eGL_TEXTURE_MAG_FILTER, eGL_LINEAR); @@ -408,11 +378,9 @@ 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); + string extensions = + "#extension GL_ARB_compute_shader : require\n" + "#extension GL_ARB_shader_storage_buffer_object : require\n"; for(int t = 1; t <= RESTYPE_TEXTYPEMAX; t++) { @@ -426,34 +394,38 @@ void GLReplay::InitDebugData() idx |= TEXDISPLAY_SINT_TEX; { - string glsl = glslheader; - 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 += GetEmbeddedResource(spv_minmaxtile_comp); + string defines = extensions; + defines += string("#define SHADER_RESTYPE ") + ToStr::Get(t) + "\n"; + defines += string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; + defines += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - DebugData.minmaxTileProgram[idx] = CreateCShaderProgram(glsl.c_str()); + GenerateGLSLShader(cs, eShaderGLSL, defines, GetEmbeddedResource(spv_minmaxtile_comp), 420); + + DebugData.minmaxTileProgram[idx] = CreateCShaderProgram(cs); } { - string glsl = glslheader; - 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 += GetEmbeddedResource(spv_histogram_comp); + string defines = extensions; + defines += string("#define SHADER_RESTYPE ") + ToStr::Get(t) + "\n"; + defines += string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; + defines += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - DebugData.histogramProgram[idx] = CreateCShaderProgram(glsl.c_str()); + GenerateGLSLShader(cs, eShaderGLSL, defines, GetEmbeddedResource(spv_histogram_comp), 420); + + DebugData.histogramProgram[idx] = CreateCShaderProgram(cs); } if(t == 1) { - string glsl = glslheader; - 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 += GetEmbeddedResource(spv_minmaxresult_comp); + string defines = extensions; + defines += string("#define SHADER_RESTYPE ") + ToStr::Get(t) + "\n"; + defines += string("#define UINT_TEX ") + (i == 1 ? "1" : "0") + "\n"; + defines += string("#define SINT_TEX ") + (i == 2 ? "1" : "0") + "\n"; - DebugData.minmaxResultProgram[i] = CreateCShaderProgram(glsl.c_str()); + GenerateGLSLShader(cs, eShaderGLSL, defines, GetEmbeddedResource(spv_minmaxresult_comp), + 420); + + DebugData.minmaxResultProgram[i] = CreateCShaderProgram(cs); } } } @@ -476,21 +448,19 @@ void GLReplay::InitDebugData() } { - string glsl = "#version 420 core\n\n#define MS2Array main\n\n"; - glsl += GetEmbeddedResource(glsl_arraymscopy_comp); + GenerateGLSLShader(cs, eShaderGLSL, "", GetEmbeddedResource(spv_ms2array_comp), 420); + DebugData.MS2Array = CreateCShaderProgram(cs); - DebugData.MS2Array = CreateCShaderProgram(glsl.c_str()); - - glsl = "#version 420 core\n\n#define Array2MS main\n\n"; - glsl += GetEmbeddedResource(glsl_arraymscopy_comp); - - DebugData.Array2MS = CreateCShaderProgram(glsl.c_str()); + GenerateGLSLShader(cs, eShaderGLSL, "", GetEmbeddedResource(spv_array2ms_comp), 420); + DebugData.Array2MS = CreateCShaderProgram(cs); } { - string glsl = GetEmbeddedResource(glsl_mesh_comp); - - DebugData.meshPickProgram = CreateCShaderProgram(glsl.c_str()); + string defines = + "#extension GL_ARB_compute_shader : require\n" + "#extension GL_ARB_shader_storage_buffer_object : require"; + GenerateGLSLShader(cs, eShaderGLSL, defines, GetEmbeddedResource(spv_mesh_comp), 420); + DebugData.meshPickProgram = CreateCShaderProgram(cs); } RenderDoc::Inst().SetProgress(DebugManagerInit, 0.8f); @@ -499,12 +469,8 @@ void GLReplay::InitDebugData() gl.glGenBuffers(1, &DebugData.pickResultBuf); gl.glBindBuffer(eGL_SHADER_STORAGE_BUFFER, DebugData.pickResultBuf); gl.glNamedBufferStorageEXT(DebugData.pickResultBuf, - sizeof(Vec4f) * DebugRenderData::maxMeshPicks, NULL, GL_MAP_READ_BIT); - - gl.glGenBuffers(1, &DebugData.pickResultCounterBuf); - gl.glBindBuffer(eGL_ATOMIC_COUNTER_BUFFER, DebugData.pickResultCounterBuf); - gl.glNamedBufferStorageEXT(DebugData.pickResultCounterBuf, sizeof(uint32_t), NULL, - GL_DYNAMIC_STORAGE_BIT); + sizeof(Vec4f) * DebugRenderData::maxMeshPicks + sizeof(uint32_t) * 4, + NULL, GL_DYNAMIC_STORAGE_BIT | GL_MAP_READ_BIT); // sized/created on demand DebugData.pickVBBuf = DebugData.pickIBBuf = 0; @@ -619,8 +585,6 @@ void GLReplay::DeleteDebugData() gl.glDeleteTextures(1, &DebugData.overlayTex); } - gl.glDeleteProgram(DebugData.blitProg); - if(DebugData.quadoverdrawFSProg) { gl.glDeleteProgram(DebugData.quadoverdrawFSProg); @@ -634,14 +598,10 @@ void GLReplay::DeleteDebugData() gl.glDeleteProgramPipelines(1, &DebugData.texDisplayPipe); gl.glDeleteProgram(DebugData.checkerProg); - gl.glDeleteProgram(DebugData.genericProg); - gl.glDeleteProgram(DebugData.genericFSProg); + gl.glDeleteProgram(DebugData.fixedcolFSProg); gl.glDeleteProgram(DebugData.meshProg); gl.glDeleteProgram(DebugData.meshgsProg); - gl.glDeleteBuffers(1, &DebugData.outlineStripVB); - gl.glDeleteVertexArrays(1, &DebugData.outlineStripVAO); - gl.glDeleteSamplers(1, &DebugData.linearSampler); gl.glDeleteSamplers(1, &DebugData.pointSampler); gl.glDeleteSamplers(1, &DebugData.pointNoMipSampler); @@ -760,7 +720,7 @@ bool GLReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uin MakeCurrentReplayContext(m_DebugCtx); - gl.glBindBufferBase(eGL_UNIFORM_BUFFER, 0, DebugData.UBOs[0]); + gl.glBindBufferBase(eGL_UNIFORM_BUFFER, 2, DebugData.UBOs[0]); HistogramUBOData *cdata = (HistogramUBOData *)gl.glMapBufferRange(eGL_UNIFORM_BUFFER, 0, sizeof(HistogramUBOData), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); @@ -931,7 +891,7 @@ bool GLReplay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mip, MakeCurrentReplayContext(m_DebugCtx); - gl.glBindBufferBase(eGL_UNIFORM_BUFFER, 0, DebugData.UBOs[0]); + gl.glBindBufferBase(eGL_UNIFORM_BUFFER, 2, DebugData.UBOs[0]); HistogramUBOData *cdata = (HistogramUBOData *)gl.glMapBufferRange(eGL_UNIFORM_BUFFER, 0, sizeof(HistogramUBOData), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); @@ -1041,15 +1001,6 @@ uint32_t GLReplay::PickVertex(uint32_t eventID, const MeshDisplay &cfg, uint32_t gl.glUseProgram(DebugData.meshPickProgram); - GLint loc = gl.glGetUniformLocation(DebugData.meshPickProgram, "PickCoords"); - gl.glUniform2f(loc, (float)x, (float)y); - loc = gl.glGetUniformLocation(DebugData.meshPickProgram, "PickViewport"); - gl.glUniform2f(loc, DebugData.outWidth, DebugData.outHeight); - loc = gl.glGetUniformLocation(DebugData.meshPickProgram, "PickIdx"); - gl.glUniform1ui(loc, cfg.position.idxByteWidth ? 1U : 0U); - loc = gl.glGetUniformLocation(DebugData.meshPickProgram, "PickNumVerts"); - gl.glUniform1ui(loc, cfg.position.numVerts); - Matrix4f projMat = Matrix4f::Perspective(90.0f, 0.1f, 100000.0f, DebugData.outWidth / DebugData.outHeight); @@ -1080,8 +1031,19 @@ uint32_t GLReplay::PickVertex(uint32_t eventID, const MeshDisplay &cfg, uint32_t PickMVP = projMat.Mul(camMat.Mul(guessProj.Inverse())); } - loc = gl.glGetUniformLocation(DebugData.meshPickProgram, "PickMVP"); - gl.glUniformMatrix4fv(loc, 1, GL_FALSE, PickMVP.Data()); + gl.glBindBufferBase(eGL_UNIFORM_BUFFER, 0, DebugData.UBOs[0]); + MeshPickUBOData *cdata = + (MeshPickUBOData *)gl.glMapBufferRange(eGL_UNIFORM_BUFFER, 0, sizeof(MeshPickUBOData), + GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); + + cdata->coords = Vec2f((float)x, (float)y); + cdata->viewport = Vec2f(DebugData.outWidth, DebugData.outHeight); + cdata->use_indices = cfg.position.idxByteWidth ? 1U : 0U; + cdata->numVerts = cfg.position.numVerts; + cdata->unproject = cfg.position.unproject; + cdata->mvp = PickMVP; + + gl.glUnmapBuffer(eGL_UNIFORM_BUFFER); GLuint ib = 0; @@ -1179,22 +1141,22 @@ uint32_t GLReplay::PickVertex(uint32_t eventID, const MeshDisplay &cfg, uint32_t delete[] vbData; } - uint32_t reset = 0; - gl.glBindBufferBase(eGL_ATOMIC_COUNTER_BUFFER, 0, DebugData.pickResultCounterBuf); - gl.glBufferSubData(eGL_ATOMIC_COUNTER_BUFFER, 0, sizeof(uint32_t), &reset); - + uint32_t reset[4] = {}; gl.glBindBufferBase(eGL_SHADER_STORAGE_BUFFER, 0, DebugData.pickResultBuf); + gl.glBufferSubData(eGL_SHADER_STORAGE_BUFFER, 0, sizeof(uint32_t) * 4, &reset); + gl.glBindBufferBase(eGL_SHADER_STORAGE_BUFFER, 1, DebugData.pickVBBuf); gl.glBindBufferRange( eGL_SHADER_STORAGE_BUFFER, 2, DebugData.pickIBBuf, (GLintptr)cfg.position.idxoffs, (GLsizeiptr)(cfg.position.idxoffs + cfg.position.idxByteWidth * cfg.position.numVerts)); + gl.glBindBufferBase(eGL_SHADER_STORAGE_BUFFER, 3, DebugData.pickResultBuf); - gl.glDispatchCompute(GLuint(cfg.position.numVerts / 1024 + 1), 1, 1); + gl.glDispatchCompute(GLuint(cfg.position.numVerts / 128 + 1), 1, 1); gl.glMemoryBarrier(GL_ATOMIC_COUNTER_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT); uint32_t numResults = 0; - gl.glBindBuffer(eGL_COPY_READ_BUFFER, DebugData.pickResultCounterBuf); + gl.glBindBuffer(eGL_COPY_READ_BUFFER, DebugData.pickResultBuf); gl.glGetBufferSubData(eGL_COPY_READ_BUFFER, 0, sizeof(uint32_t), &numResults); if(numResults > 0) @@ -1207,8 +1169,11 @@ uint32_t GLReplay::PickVertex(uint32_t eventID, const MeshDisplay &cfg, uint32_t float depth; }; - PickResult *pickResults = - (PickResult *)gl.glMapNamedBufferEXT(DebugData.pickResultBuf, eGL_READ_ONLY); + byte *mapped = (byte *)gl.glMapNamedBufferEXT(DebugData.pickResultBuf, eGL_READ_ONLY); + + mapped += sizeof(uint32_t) * 4; + + PickResult *pickResults = (PickResult *)mapped; PickResult *closest = pickResults; @@ -1344,7 +1309,7 @@ void GLReplay::CopyTex2DMSToArray(GLuint destArray, GLuint srcMS, GLint width, G gl.glTextureView(texs[0], eGL_TEXTURE_2D_ARRAY, destArray, fmt, 0, 1, 0, arraySize * samples); gl.glTextureView(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, srcMS, fmt, 0, 1, 0, arraySize); - gl.glBindImageTexture(0, texs[0], 0, GL_TRUE, 0, eGL_WRITE_ONLY, fmt); + gl.glBindImageTexture(1, texs[0], 0, GL_TRUE, 0, eGL_WRITE_ONLY, fmt); gl.glActiveTexture(eGL_TEXTURE0); gl.glBindTexture(eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, texs[1]); gl.glBindSampler(0, DebugData.pointNoMipSampler); @@ -1357,8 +1322,13 @@ void GLReplay::CopyTex2DMSToArray(GLuint destArray, GLuint srcMS, GLint width, G gl.glUseProgram(DebugData.MS2Array); - GLint loc = gl.glGetUniformLocation(DebugData.MS2Array, "numMultiSamples"); - gl.glUniform1i(loc, samples); + gl.glBindBufferBase(eGL_UNIFORM_BUFFER, 2, DebugData.UBOs[0]); + GLint *ubo = (GLint *)gl.glMapBufferRange(eGL_UNIFORM_BUFFER, 0, sizeof(uint32_t), + GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); + + *ubo = samples; + + gl.glUnmapBuffer(eGL_UNIFORM_BUFFER); gl.glDispatchCompute((GLuint)width, (GLuint)height, GLuint(arraySize * samples)); gl.glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); @@ -1712,43 +1682,58 @@ void GLReplay::RenderHighlightBox(float w, float h, float scale) { MakeCurrentReplayContext(m_DebugCtx); - const float xpixdim = 2.0f / w; - const float ypixdim = 2.0f / h; - - const float xdim = scale * xpixdim; - const float ydim = scale * ypixdim; - WrappedOpenGL &gl = *m_pDriver; - gl.glUseProgram(DebugData.genericProg); + GLint sz = GLint(scale); - GLint offsetLoc = gl.glGetUniformLocation(DebugData.genericProg, "RENDERDOC_GenericVS_Offset"); - GLint scaleLoc = gl.glGetUniformLocation(DebugData.genericProg, "RENDERDOC_GenericVS_Scale"); - GLint colLoc = gl.glGetUniformLocation(DebugData.genericProg, "RENDERDOC_GenericFS_Color"); + struct rect + { + GLint x, y; + GLint w, h; + }; - Vec4f offsetVal(0.0f, 0.0f, 0.0f, 0.0f); - Vec4f scaleVal(xdim, ydim, 1.0f, 1.0f); - Vec4f colVal(1.0f, 1.0f, 1.0f, 1.0f); + rect tl = {GLint(w / 2.0f + 0.5f), GLint(h / 2.0f + 0.5f), 1, 1}; - gl.glUniform4fv(offsetLoc, 1, &offsetVal.x); - gl.glUniform4fv(scaleLoc, 1, &scaleVal.x); - gl.glUniform4fv(colLoc, 1, &colVal.x); + rect scissors[4] = { + {tl.x, tl.y, 1, sz}, + {tl.x + (GLint)sz, tl.y, 1, sz + 1}, + {tl.x, tl.y, sz, 1}, + {tl.x, tl.y + (GLint)sz, sz, 1}, + }; - gl.glDisable(eGL_DEPTH_TEST); + // inner + gl.glEnable(eGL_SCISSOR_TEST); + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + for(size_t i = 0; i < ARRAY_COUNT(scissors); i++) + { + gl.glScissor(scissors[i].x, scissors[i].y, scissors[i].w, scissors[i].h); + gl.glClear(eGL_COLOR_BUFFER_BIT); + } - gl.glBindVertexArray(DebugData.outlineStripVAO); - gl.glDrawArrays(eGL_LINE_STRIP, 0, 5); + scissors[0].x--; + scissors[1].x++; + scissors[2].x--; + scissors[3].x--; - offsetVal = Vec4f(-xpixdim, ypixdim, 0.0f, 0.0f); - scaleVal = Vec4f(xdim + xpixdim * 2, ydim + ypixdim * 2, 1.0f, 1.0f); - colVal = Vec4f(0.0f, 0.0f, 0.0f, 1.0f); + scissors[0].y--; + scissors[1].y--; + scissors[2].y--; + scissors[3].y++; - gl.glUniform4fv(offsetLoc, 1, &offsetVal.x); - gl.glUniform4fv(scaleLoc, 1, &scaleVal.x); - gl.glUniform4fv(colLoc, 1, &colVal.x); + scissors[0].h += 2; + scissors[1].h += 2; + scissors[2].w += 2; + scissors[3].w += 2; - gl.glBindVertexArray(DebugData.outlineStripVAO); - gl.glDrawArrays(eGL_LINE_STRIP, 0, 5); + // outer + gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + for(size_t i = 0; i < ARRAY_COUNT(scissors); i++) + { + gl.glScissor(scissors[i].x, scissors[i].y, scissors[i].w, scissors[i].h); + gl.glClear(eGL_COLOR_BUFFER_BIT); + } + + gl.glDisable(eGL_SCISSOR_TEST); } void GLReplay::SetupOverlayPipeline(GLuint Program, GLuint Pipeline, GLuint fragProgram) @@ -1834,7 +1819,7 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FormatComponentType typeHin // we bind the separable program created for each shader, and copy // uniforms and attrib bindings from the 'real' programs, wherever // they are. - SetupOverlayPipeline(rs.Program, rs.Pipeline, DebugData.genericFSProg); + SetupOverlayPipeline(rs.Program, rs.Pipeline, DebugData.fixedcolFSProg); auto &texDetails = m_pDriver->m_Textures[texid]; @@ -1896,9 +1881,9 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FormatComponentType typeHin float black[] = {0.0f, 0.0f, 0.0f, 0.5f}; gl.glClearBufferfv(eGL_COLOR, 0, black); - GLint colLoc = gl.glGetUniformLocation(DebugData.genericFSProg, "RENDERDOC_GenericFS_Color"); + GLint colLoc = gl.glGetUniformLocation(DebugData.fixedcolFSProg, "RENDERDOC_Fixed_Color"); float colVal[] = {0.8f, 0.1f, 0.8f, 1.0f}; - gl.glProgramUniform4fv(DebugData.genericFSProg, colLoc, 1, colVal); + gl.glProgramUniform4fv(DebugData.fixedcolFSProg, colLoc, 1, colVal); ReplayLog(eventID, eReplay_OnlyDraw); } @@ -1907,9 +1892,9 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FormatComponentType typeHin float wireCol[] = {200.0f / 255.0f, 255.0f / 255.0f, 0.0f / 255.0f, 0.0f}; gl.glClearBufferfv(eGL_COLOR, 0, wireCol); - GLint colLoc = gl.glGetUniformLocation(DebugData.genericFSProg, "RENDERDOC_GenericFS_Color"); + GLint colLoc = gl.glGetUniformLocation(DebugData.fixedcolFSProg, "RENDERDOC_Fixed_Color"); wireCol[3] = 1.0f; - gl.glProgramUniform4fv(DebugData.genericFSProg, colLoc, 1, wireCol); + gl.glProgramUniform4fv(DebugData.fixedcolFSProg, colLoc, 1, wireCol); gl.glPolygonMode(eGL_FRONT_AND_BACK, eGL_LINE); @@ -1969,9 +1954,9 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FormatComponentType typeHin float black[] = {0.0f, 0.0f, 0.0f, 0.0f}; gl.glClearBufferfv(eGL_COLOR, 0, black); - GLint colLoc = gl.glGetUniformLocation(DebugData.genericFSProg, "RENDERDOC_GenericFS_Color"); + GLint colLoc = gl.glGetUniformLocation(DebugData.fixedcolFSProg, "RENDERDOC_Fixed_Color"); float red[] = {1.0f, 0.0f, 0.0f, 1.0f}; - gl.glProgramUniform4fv(DebugData.genericFSProg, colLoc, 1, red); + gl.glProgramUniform4fv(DebugData.fixedcolFSProg, colLoc, 1, red); ReplayLog(eventID, eReplay_OnlyDraw); @@ -2047,7 +2032,7 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FormatComponentType typeHin gl.glBindFramebuffer(eGL_READ_FRAMEBUFFER, rs.DrawFBO); float green[] = {0.0f, 1.0f, 0.0f, 1.0f}; - gl.glProgramUniform4fv(DebugData.genericFSProg, colLoc, 1, green); + gl.glProgramUniform4fv(DebugData.fixedcolFSProg, colLoc, 1, green); if(overlay == eTexOverlay_Depth) { @@ -2099,8 +2084,8 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FormatComponentType typeHin col[0] = 1.0f; col[3] = 1.0f; - GLint colLoc = gl.glGetUniformLocation(DebugData.genericFSProg, "RENDERDOC_GenericFS_Color"); - gl.glProgramUniform4fv(DebugData.genericFSProg, colLoc, 1, col); + GLint colLoc = gl.glGetUniformLocation(DebugData.fixedcolFSProg, "RENDERDOC_Fixed_Color"); + gl.glProgramUniform4fv(DebugData.fixedcolFSProg, colLoc, 1, col); ReplayLog(eventID, eReplay_OnlyDraw); @@ -2112,7 +2097,7 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FormatComponentType typeHin col[0] = 0.0f; col[1] = 1.0f; - gl.glProgramUniform4fv(DebugData.genericFSProg, colLoc, 1, col); + gl.glProgramUniform4fv(DebugData.fixedcolFSProg, colLoc, 1, col); ReplayLog(eventID, eReplay_OnlyDraw); } diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index b265c1283..d59f6d0a5 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -240,6 +240,10 @@ void GLReplay::InitOutputWindow(OutputWindow &outwin) gl.glGenVertexArrays(1, &outwin.BlitData.emptyVAO); gl.glBindVertexArray(outwin.BlitData.emptyVAO); + + gl.glGenFramebuffers(1, &outwin.BlitData.readFBO); + gl.glBindFramebuffer(eGL_READ_FRAMEBUFFER, outwin.BlitData.readFBO); + gl.glReadBuffer(eGL_COLOR_ATTACHMENT0); } bool GLReplay::CheckResizeOutputWindow(uint64_t id) @@ -337,14 +341,16 @@ void GLReplay::FlipOutputWindow(uint64_t id) gl.m_Real.glBindFramebuffer(eGL_FRAMEBUFFER, 0); gl.glViewport(0, 0, outw.width, outw.height); - gl.glUseProgram(DebugData.blitProg); + gl.glBindFramebuffer(eGL_READ_FRAMEBUFFER, outw.BlitData.readFBO); + + gl.glFramebufferTexture2D(eGL_READ_FRAMEBUFFER, eGL_COLOR_ATTACHMENT0, eGL_TEXTURE_2D, + outw.BlitData.backbuffer, 0); + gl.glReadBuffer(eGL_COLOR_ATTACHMENT0); - gl.glActiveTexture(eGL_TEXTURE0); - gl.glBindTexture(eGL_TEXTURE_2D, outw.BlitData.backbuffer); gl.glEnable(eGL_FRAMEBUFFER_SRGB); - gl.glBindVertexArray(outw.BlitData.emptyVAO); - gl.glDrawArrays(eGL_TRIANGLE_STRIP, 0, 4); + gl.glBlitFramebuffer(0, 0, outw.width, outw.height, 0, 0, outw.width, outw.height, + GL_COLOR_BUFFER_BIT, eGL_NEAREST); SwapBuffers(&outw); } diff --git a/renderdoc/driver/gl/gl_replay.h b/renderdoc/driver/gl/gl_replay.h index 510b67a97..d882bf845 100644 --- a/renderdoc/driver/gl/gl_replay.h +++ b/renderdoc/driver/gl/gl_replay.h @@ -245,6 +245,9 @@ private: // for any cases where we need to use the replay context (like // re-rendering a draw). GLuint replayFBO; + + // read FBO for blit to window + GLuint readFBO; } BlitData; int width, height; @@ -268,10 +271,6 @@ private: GLuint outlineQuadProg; - // program that does a blit of texture from input to output, - // no transformation or scaling - GLuint blitProg; - GLuint texDisplayPipe; GLuint texDisplayVSProg; GLuint texDisplayProg[3]; // float/uint/sint @@ -286,7 +285,6 @@ private: GLuint pickIBBuf, pickVBBuf; uint32_t pickIBSize, pickVBSize; GLuint pickResultBuf; - GLuint pickResultCounterBuf; GLuint MS2Array, Array2MS; @@ -298,8 +296,7 @@ private: GLuint checkerProg; - GLuint genericProg; - GLuint genericFSProg; + GLuint fixedcolFSProg; GLuint meshProg; GLuint meshgsProg; @@ -312,9 +309,6 @@ private: GLuint axisFrustumBuffer; GLuint triHighlightBuffer; - GLuint outlineStripVB; - GLuint outlineStripVAO; - GLuint feedbackObj; GLuint feedbackQuery; GLuint feedbackBuffer; @@ -333,6 +327,8 @@ private: GLuint UBOs[2]; + GLuint readFBO; + GLuint emptyVAO; } DebugData; @@ -373,9 +369,6 @@ private: 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); - void InitOutputWindow(OutputWindow &outwin); void CreateOutputWindowBackbuffer(OutputWindow &outwin, bool depth); diff --git a/renderdoc/driver/gl/gl_replay_linux.cpp b/renderdoc/driver/gl/gl_replay_linux.cpp index 1c3954307..3d01e2342 100644 --- a/renderdoc/driver/gl/gl_replay_linux.cpp +++ b/renderdoc/driver/gl/gl_replay_linux.cpp @@ -178,6 +178,11 @@ void GLReplay::DestroyOutputWindow(uint64_t id) OutputWindow &outw = it->second; + MakeCurrentReplayContext(&outw); + + WrappedOpenGL &gl = *m_pDriver; + gl.glDeleteFramebuffers(outw.BlitData.readFBO); + glXMakeContextCurrentProc(outw.dpy, None, None, NULL); glXDestroyCtxProc(outw.dpy, outw.ctx); diff --git a/renderdoc/driver/gl/gl_replay_win32.cpp b/renderdoc/driver/gl/gl_replay_win32.cpp index c8711c94b..363800e1a 100644 --- a/renderdoc/driver/gl/gl_replay_win32.cpp +++ b/renderdoc/driver/gl/gl_replay_win32.cpp @@ -209,6 +209,11 @@ void GLReplay::DestroyOutputWindow(uint64_t id) OutputWindow &outw = it->second; + MakeCurrentReplayContext(&outw); + + WrappedOpenGL &gl = *m_pDriver; + gl.glDeleteFramebuffers(1, &outw.BlitData.readFBO); + wglMakeCurrentProc(NULL, NULL); wglDeleteRC(outw.ctx); ReleaseDC(outw.wnd, outw.DC); diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index d6867893f..9d9f3fad3 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -401,6 +401,7 @@ + @@ -411,6 +412,7 @@ + diff --git a/renderdoc/renderdoc.vcxproj.filters b/renderdoc/renderdoc.vcxproj.filters index fc26f3d00..c337d32b9 100644 --- a/renderdoc/renderdoc.vcxproj.filters +++ b/renderdoc/renderdoc.vcxproj.filters @@ -541,6 +541,12 @@ Resources\spv + + Resources\spv + + + Resources\spv +