diff --git a/renderdoc/Makefile b/renderdoc/Makefile index 188cc0283..4adf4343e 100644 --- a/renderdoc/Makefile +++ b/renderdoc/Makefile @@ -76,6 +76,7 @@ data/spv/histogramcs.spvo \ data/spv/minmaxtilecs.spvo \ data/spv/minmaxresultcs.spvo \ data/spv/outline.spvo \ +data/spv/debuguniforms.ho \ data/sourcecodepro.ttfo .PHONY: all diff --git a/renderdoc/data/embedded_files.h b/renderdoc/data/embedded_files.h index ef6057ee6..4315d3d91 100644 --- a/renderdoc/data/embedded_files.h +++ b/renderdoc/data/embedded_files.h @@ -60,5 +60,6 @@ DECLARE_EMBED(spirv_minmaxtile_comp); DECLARE_EMBED(spirv_minmaxresult_comp); DECLARE_EMBED(spirv_histogram_comp); DECLARE_EMBED(spirv_outline_frag); +DECLARE_EMBED(spirv_debuguniforms_h); #undef DECLARE_EMBED diff --git a/renderdoc/data/renderdoc.rc b/renderdoc/data/renderdoc.rc index 7c69f01ed..77b7d22c9 100644 --- a/renderdoc/data/renderdoc.rc +++ b/renderdoc/data/renderdoc.rc @@ -144,6 +144,7 @@ RESOURCE_spirv_minmaxtile_comp TYPE_EMBED "spv/minmaxtile.comp" RESOURCE_spirv_minmaxresult_comp TYPE_EMBED "spv/minmaxresult.comp" RESOURCE_spirv_histogram_comp TYPE_EMBED "spv/histogram.comp" RESOURCE_spirv_outline_frag TYPE_EMBED "spv/outline.frag" +RESOURCE_spirv_debuguniforms_h TYPE_EMBED "spv/debuguniforms.h" #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// diff --git a/renderdoc/data/resource.h b/renderdoc/data/resource.h index 4d38ba115..4893d30ab 100644 --- a/renderdoc/data/resource.h +++ b/renderdoc/data/resource.h @@ -46,6 +46,7 @@ #define RESOURCE_spirv_minmaxresult_comp 413 #define RESOURCE_spirv_histogram_comp 414 #define RESOURCE_spirv_outline_frag 415 +#define RESOURCE_spirv_debuguniforms_h 416 #if !defined(STRINGIZE) #define STRINGIZE2(a) #a diff --git a/renderdoc/data/spv/blit.vert b/renderdoc/data/spv/blit.vert index d218292cf..ae1257c0b 100644 --- a/renderdoc/data/spv/blit.vert +++ b/renderdoc/data/spv/blit.vert @@ -22,8 +22,6 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - out gl_PerVertex { vec4 gl_Position; diff --git a/renderdoc/data/spv/checkerboard.frag b/renderdoc/data/spv/checkerboard.frag index 190680ffe..226055727 100644 --- a/renderdoc/data/spv/checkerboard.frag +++ b/renderdoc/data/spv/checkerboard.frag @@ -22,8 +22,6 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - layout (location = 0) out vec4 color_out; layout (binding = 0, std140) uniform checkeruniforms diff --git a/renderdoc/data/spv/debuguniforms.h b/renderdoc/data/spv/debuguniforms.h new file mode 100644 index 000000000..87b1bd7ac --- /dev/null +++ b/renderdoc/data/spv/debuguniforms.h @@ -0,0 +1,194 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015 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. + ******************************************************************************/ + +// use some preprocessor hacks to compile the same header in both GLSL and C++ so we can define +// classes that represent a whole cbuffer +#if defined(__cplusplus) + +#define uniform struct +#define vec2 Vec2f +#define vec3 Vec3f +#define vec4 Vec4f +#define mat4 Matrix4f +#define uint uint32_t + +#define BINDING(s, b) +#define INST_NAME(name) + +struct Vec4u +{ + uint32_t x, y, z, w; +}; + +#define uvec4 Vec4u + +#else + +// this has to happen above even any pre-processor definitions, +// so it's added in code +//#version 430 core + +#define BINDING(s, b) layout (set = s, binding = b, std140) +#define INST_NAME(name) name + +#endif + +BINDING (0, 2) uniform HistogramUBOData +{ + uint HistogramChannels; + float HistogramMin; + float HistogramMax; + uint HistogramFlags; + + float HistogramSlice; + int HistogramMip; + int HistogramSample; + int HistogramNumSamples; + + vec3 HistogramTextureResolution; + float Padding3; +} INST_NAME(histogram_minmax); + +BINDING (0, 0) uniform MeshUBOData +{ + mat4 mvp; + mat4 invProj; + vec4 color; + uint displayFormat; + uint homogenousInput; + vec2 pointSpriteSize; +} INST_NAME(Mesh); + +BINDING (0, 0) uniform OutlineUBOData +{ + vec4 Inner_Color; + vec4 Border_Color; + vec4 ViewRect; + uint Scissor; + vec3 padding; +} INST_NAME(outline); + +BINDING (0, 0) uniform FontUBOData +{ + vec2 TextPosition; + float txtpadding; + float TextSize; + + vec2 CharacterSize; + vec2 FontScreenAspect; +} INST_NAME(general); + +struct FontGlyphData +{ + vec4 posdata; + vec4 uvdata; +}; + +#define FONT_FIRST_CHAR 32 +#define FONT_LAST_CHAR 126 + +BINDING (0, 1) uniform GlyphUBOData +{ + FontGlyphData data[FONT_LAST_CHAR-FONT_FIRST_CHAR+1]; +} INST_NAME(glyphs); + +#define MAX_SINGLE_LINE_LENGTH 256 + +BINDING (0, 2) uniform StringUBOData +{ + uvec4 chars[MAX_SINGLE_LINE_LENGTH]; +} INST_NAME(str); + +BINDING (0, 0) uniform TexDisplayUBOData +{ + vec2 Position; + float Scale; + float HDRMul; + + vec4 Channels; + + float RangeMinimum; + float InverseRangeSize; + float MipLevel; + int FlipY; + + vec3 TextureResolutionPS; + int OutputDisplayFormat; + + vec2 OutputRes; + int RawOutput; + float Slice; + + int SampleIdx; + int NumSamples; + vec2 Padding; +} INST_NAME(texdisplay); + +// some constants available to both C++ and GLSL for configuring display +#define CUBEMAP_FACE_POS_X 0 +#define CUBEMAP_FACE_NEG_X 1 +#define CUBEMAP_FACE_POS_Y 2 +#define CUBEMAP_FACE_NEG_Y 3 +#define CUBEMAP_FACE_POS_Z 4 +#define CUBEMAP_FACE_NEG_Z 5 + +// we always upload an array (but it might have only one layer), +// so 2D and 2D arrays are the same. +// Cube and cube array textures are treated as 2D arrays. +#define RESTYPE_TEX1D 0x1 +#define RESTYPE_TEX2D 0x2 +#define RESTYPE_TEX3D 0x3 +#define RESTYPE_TEXBUFFER 0x4 +#define RESTYPE_TEX2DMS 0x5 +#define RESTYPE_TEXTYPEMAX 0x6 + +#define MESHDISPLAY_SOLID 0x1 +#define MESHDISPLAY_FACELIT 0x2 +#define MESHDISPLAY_SECONDARY 0x3 +#define MESHDISPLAY_SECONDARY_ALPHA 0x4 + +#define TEXDISPLAY_TYPEMASK 0xF +#define TEXDISPLAY_UINT_TEX 0x10 +#define TEXDISPLAY_SINT_TEX 0x20 +#define TEXDISPLAY_NANS 0x80 +#define TEXDISPLAY_CLIPPING 0x100 +#define TEXDISPLAY_GAMMA_CURVE 0x200 + +#ifndef FLT_EPSILON +#define FLT_EPSILON 1.192092896e-07f +#endif + +// histogram/minmax is calculated in blocks of NxN each with MxM tiles. +// e.g. a tile is 32x32 pixels, then this is arranged in blocks of 32x32 tiles. +// 1 compute thread = 1 tile, 1 compute group = 1 block +// +// NOTE because of this a block can cover more than the texture (think of a 1280x720 +// texture covered by 2x1 blocks) +// +// these values are in each dimension +#define HGRAM_PIXELS_PER_TILE 64u +#define HGRAM_TILES_PER_BLOCK 32u + +#define HGRAM_NUM_BUCKETS 256u + diff --git a/renderdoc/data/spv/histogram.comp b/renderdoc/data/spv/histogram.comp index da6af0b3e..55b3c5cfe 100644 --- a/renderdoc/data/spv/histogram.comp +++ b/renderdoc/data/spv/histogram.comp @@ -22,38 +22,11 @@ * THE SOFTWARE. ******************************************************************************/ -// compute shaders that figure out the min/max values or histogram in a texture heirarchically -// note that we have to conditionally compile this shader for float/uint/sint as doing that -// dynamically produces a shader with too many temp registers unfortunately. - -#version 430 core - -#define HGRAM_PIXELS_PER_TILE 64u -#define HGRAM_TILES_PER_BLOCK 32u - -#define HGRAM_NUM_BUCKETS 256u - layout(binding=0, std140) writeonly buffer minmaxresultdest { uint result[HGRAM_NUM_BUCKETS]; } dest; -layout(binding=2, std140) uniform HistogramCBufferData -{ - uint HistogramChannels; - float HistogramMin; - float HistogramMax; - uint HistogramFlags; - - float HistogramSlice; - int HistogramMip; - int HistogramSample; - int HistogramNumSamples; - - vec3 HistogramTextureResolution; - float Padding3; -} histogram; - layout (binding = 3) uniform sampler2D tex; layout (local_size_x = HGRAM_TILES_PER_BLOCK, local_size_y = HGRAM_TILES_PER_BLOCK) in; @@ -63,7 +36,7 @@ void main() uvec3 tid = gl_LocalInvocationID; uvec3 gid = gl_WorkGroupID; - uvec3 texDim = uvec3(histogram.HistogramTextureResolution); + uvec3 texDim = uvec3(histogram_minmax.HistogramTextureResolution); uint blocksX = uint(ceil(float(texDim.x)/float(HGRAM_PIXELS_PER_TILE*HGRAM_TILES_PER_BLOCK))); @@ -78,26 +51,26 @@ void main() uint bucketIdx = HGRAM_NUM_BUCKETS+1; { - vec4 data = textureLod(tex, vec2(x, y) / histogram.HistogramTextureResolution.xy, float(histogram.HistogramMip)); + vec4 data = textureLod(tex, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, float(histogram_minmax.HistogramMip)); float divisor = 0.0f; float sum = 0.0f; - if((histogram.HistogramChannels & 0x1u) > 0) + if((histogram_minmax.HistogramChannels & 0x1u) > 0) { sum += data.x; divisor += 1.0f; } - if((histogram.HistogramChannels & 0x2u) > 0) + if((histogram_minmax.HistogramChannels & 0x2u) > 0) { sum += data.y; divisor += 1.0f; } - if((histogram.HistogramChannels & 0x4u) > 0) + if((histogram_minmax.HistogramChannels & 0x4u) > 0) { sum += data.z; divisor += 1.0f; } - if((histogram.HistogramChannels & 0x8u) > 0) + if((histogram_minmax.HistogramChannels & 0x8u) > 0) { sum += data.w; divisor += 1.0f; @@ -107,7 +80,7 @@ void main() { float val = sum/divisor; - float normalisedVal = (val - histogram.HistogramMin)/(histogram.HistogramMax - histogram.HistogramMin); + float normalisedVal = (val - histogram_minmax.HistogramMin)/(histogram_minmax.HistogramMax - histogram_minmax.HistogramMin); if(normalisedVal < 0.0f) normalisedVal = 2.0f; diff --git a/renderdoc/data/spv/mesh.frag b/renderdoc/data/spv/mesh.frag index 06865055b..720a17a0c 100644 --- a/renderdoc/data/spv/mesh.frag +++ b/renderdoc/data/spv/mesh.frag @@ -22,24 +22,12 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - in v2f { vec4 secondary; vec4 norm; } IN; -layout (binding = 0, std140) uniform meshuniforms -{ - mat4 mvp; - mat4 invProj; - vec4 color; - uint displayFormat; - uint homogenousInput; - vec2 pointSpriteSize; -} Mesh; - layout (location = 0) out vec4 color_out; #define MESHDISPLAY_SOLID 0x1 diff --git a/renderdoc/data/spv/mesh.geom b/renderdoc/data/spv/mesh.geom index 3f6c6ff8a..913285e14 100644 --- a/renderdoc/data/spv/mesh.geom +++ b/renderdoc/data/spv/mesh.geom @@ -21,8 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ - -#version 420 core layout(triangles, invocations = 1) in; layout(triangle_strip, max_vertices = 3) out; @@ -39,16 +37,6 @@ out v2f vec4 norm; } OUT; -layout (binding = 0, std140) uniform meshuniforms -{ - mat4 mvp; - mat4 invProj; - vec4 color; - uint displayFormat; - uint homogenousInput; - vec2 pointSpriteSize; -} Mesh; - out gl_PerVertex { vec4 gl_Position; diff --git a/renderdoc/data/spv/mesh.vert b/renderdoc/data/spv/mesh.vert index 6e26a01b3..892a8df83 100644 --- a/renderdoc/data/spv/mesh.vert +++ b/renderdoc/data/spv/mesh.vert @@ -22,21 +22,9 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - layout (location = 0) in vec4 position; layout (location = 1) in vec4 secondary; -layout (binding = 0, std140) uniform meshuniforms -{ - mat4 mvp; - mat4 invProj; - vec4 color; - uint displayFormat; - uint homogenousInput; - vec2 pointSpriteSize; -} Mesh; - out gl_PerVertex { vec4 gl_Position; diff --git a/renderdoc/data/spv/minmaxresult.comp b/renderdoc/data/spv/minmaxresult.comp index fab12ddbf..22f2d533b 100644 --- a/renderdoc/data/spv/minmaxresult.comp +++ b/renderdoc/data/spv/minmaxresult.comp @@ -22,17 +22,6 @@ * THE SOFTWARE. ******************************************************************************/ -// compute shaders that figure out the min/max values or histogram in a texture heirarchically -// note that we have to conditionally compile this shader for float/uint/sint as doing that -// dynamically produces a shader with too many temp registers unfortunately. - -#version 430 core - -#define HGRAM_PIXELS_PER_TILE 64u -#define HGRAM_TILES_PER_BLOCK 32u - -#define HGRAM_NUM_BUCKETS 256u - layout(binding=0, std140) writeonly buffer minmaxresultdest { vec4 result[2]; @@ -43,27 +32,11 @@ layout(binding=1, std140) readonly buffer minmaxtilesrc vec4 tiles[]; } src; -layout(binding=2, std140) uniform HistogramCBufferData -{ - uint HistogramChannels; - float HistogramMin; - float HistogramMax; - uint HistogramFlags; - - float HistogramSlice; - int HistogramMip; - int HistogramSample; - int HistogramNumSamples; - - vec3 HistogramTextureResolution; - float Padding3; -} minmax; - layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; void main() { - uvec3 texDim = uvec3(minmax.HistogramTextureResolution); + uvec3 texDim = uvec3(histogram_minmax.HistogramTextureResolution); uint blocksX = uint(ceil(float(texDim.x)/float(HGRAM_PIXELS_PER_TILE*HGRAM_TILES_PER_BLOCK))); uint blocksY = uint(ceil(float(texDim.y)/float(HGRAM_PIXELS_PER_TILE*HGRAM_TILES_PER_BLOCK))); diff --git a/renderdoc/data/spv/minmaxtile.comp b/renderdoc/data/spv/minmaxtile.comp index 372909fba..62af6ace2 100644 --- a/renderdoc/data/spv/minmaxtile.comp +++ b/renderdoc/data/spv/minmaxtile.comp @@ -22,38 +22,11 @@ * THE SOFTWARE. ******************************************************************************/ -// compute shaders that figure out the min/max values or histogram in a texture heirarchically -// note that we have to conditionally compile this shader for float/uint/sint as doing that -// dynamically produces a shader with too many temp registers unfortunately. - -#version 430 core - -#define HGRAM_PIXELS_PER_TILE 64u -#define HGRAM_TILES_PER_BLOCK 32u - -#define HGRAM_NUM_BUCKETS 256u - layout(binding=0, std140) writeonly buffer minmaxtiledest { vec4 tiles[]; } dest; -layout(binding=2, std140) uniform HistogramCBufferData -{ - uint HistogramChannels; - float HistogramMin; - float HistogramMax; - uint HistogramFlags; - - float HistogramSlice; - int HistogramMip; - int HistogramSample; - int HistogramNumSamples; - - vec3 HistogramTextureResolution; - float Padding3; -} minmax; - layout (binding = 3) uniform sampler2D tex; layout (local_size_x = HGRAM_TILES_PER_BLOCK, local_size_y = HGRAM_TILES_PER_BLOCK) in; @@ -63,7 +36,7 @@ void main() uvec3 tid = gl_LocalInvocationID; uvec3 gid = gl_WorkGroupID; - uvec3 texDim = uvec3(minmax.HistogramTextureResolution); + uvec3 texDim = uvec3(histogram_minmax.HistogramTextureResolution); uint blocksX = uint(ceil(float(texDim.x)/float(HGRAM_PIXELS_PER_TILE*HGRAM_TILES_PER_BLOCK))); @@ -81,7 +54,7 @@ void main() { for(uint x=topleft.x; x < min(texDim.x, topleft.x + HGRAM_PIXELS_PER_TILE); x++) { - vec4 data = textureLod(tex, vec2(x, y) / minmax.HistogramTextureResolution.xy, float(minmax.HistogramMip)); + vec4 data = textureLod(tex, vec2(x, y) / histogram_minmax.HistogramTextureResolution.xy, float(histogram_minmax.HistogramMip)); if(i == 0) { diff --git a/renderdoc/data/spv/outline.frag b/renderdoc/data/spv/outline.frag index e79c146b3..3f39c1905 100644 --- a/renderdoc/data/spv/outline.frag +++ b/renderdoc/data/spv/outline.frag @@ -22,19 +22,8 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - layout (location = 0) out vec4 color_out; -layout (binding = 0, std140) uniform outlineuniforms -{ - vec4 Inner_Color; - vec4 Border_Color; - vec4 ViewRect; - uint Scissor; - uvec3 padding; -} outline; - void main(void) { vec4 ret = outline.Inner_Color; diff --git a/renderdoc/data/spv/texdisplay.frag b/renderdoc/data/spv/texdisplay.frag index 525ca9c8f..6264ad60a 100644 --- a/renderdoc/data/spv/texdisplay.frag +++ b/renderdoc/data/spv/texdisplay.frag @@ -22,46 +22,8 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - layout (location = 0) out vec4 color_out; -layout (binding = 0, std140) uniform displayuniforms -{ - vec2 Position; - float Scale; - float HDRMul; - - vec4 Channels; - - float RangeMinimum; - float InverseRangeSize; - float MipLevel; - int FlipY; - - vec3 TextureResolutionPS; - int OutputDisplayFormat; - - vec2 OutputRes; - int RawOutput; - float Slice; - - int SampleIdx; - int NumSamples; - vec2 Padding; -} texdisplay; - -#define TEXDISPLAY_TYPEMASK 0xF -#define TEXDISPLAY_UINT_TEX 0x10 -#define TEXDISPLAY_SINT_TEX 0x20 -#define TEXDISPLAY_NANS 0x80 -#define TEXDISPLAY_CLIPPING 0x100 -#define TEXDISPLAY_GAMMA_CURVE 0x200 - -#ifndef FLT_EPSILON -#define FLT_EPSILON 1.192092896e-07f -#endif - layout (binding = 1) uniform sampler2D tex; void main(void) diff --git a/renderdoc/data/spv/text.frag b/renderdoc/data/spv/text.frag index c142597db..3c398c393 100644 --- a/renderdoc/data/spv/text.frag +++ b/renderdoc/data/spv/text.frag @@ -22,24 +22,25 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - layout (binding = 3) uniform sampler2D tex0; layout (location = 0) out vec4 color_out; -layout (location = 0) in vec4 INtex; -layout (location = 1) in vec2 INglyphuv; +in v2f +{ + vec4 tex; + vec2 glyphuv; +} IN; void main(void) { float text = 0; - if(INglyphuv.x >= 0.0f && INglyphuv.x <= 1.0f && - INglyphuv.y >= 0.0f && INglyphuv.y <= 1.0f) + if(IN.glyphuv.x >= 0.0f && IN.glyphuv.x <= 1.0f && + IN.glyphuv.y >= 0.0f && IN.glyphuv.y <= 1.0f) { vec2 uv; - uv.x = mix(INtex.x, INtex.z, INglyphuv.x); - uv.y = mix(INtex.y, INtex.w, INglyphuv.y); + uv.x = mix(IN.tex.x, IN.tex.z, IN.glyphuv.x); + uv.y = mix(IN.tex.y, IN.tex.w, IN.glyphuv.y); text = texture(tex0, uv.xy).x; } diff --git a/renderdoc/data/spv/text.vert b/renderdoc/data/spv/text.vert index ee7def572..e5634edf4 100644 --- a/renderdoc/data/spv/text.vert +++ b/renderdoc/data/spv/text.vert @@ -22,34 +22,6 @@ * THE SOFTWARE. ******************************************************************************/ -#version 420 core - -layout (binding = 0, std140) uniform fontuniforms -{ - vec2 TextPosition; - float txtpadding; - float TextSize; - - vec2 CharacterSize; - vec2 FontScreenAspect; -} general; - -struct glyph -{ - vec4 posdata; - vec4 uvdata; -}; - -layout (binding = 1, std140) uniform glyphdata -{ - glyph data[127-32]; -} glyphs; - -layout (binding = 2, std140) uniform stringdata -{ - uvec4 chars[256]; -} str; - out gl_PerVertex { vec4 gl_Position; @@ -57,8 +29,11 @@ out gl_PerVertex float gl_ClipDistance[]; }; -layout (location = 0) out vec4 OUTtex; -layout (location = 1) out vec2 OUTglyphuv; +out v2f +{ + vec4 tex; + vec2 glyphuv; +} OUT; void main(void) { @@ -73,9 +48,9 @@ void main(void) vec2 charPos = vec2(strindex + pos.x + general.TextPosition.x, pos.y + general.TextPosition.y); - glyph G = glyphs.data[ str.chars[strindex].x ]; + FontGlyphData G = glyphs.data[ str.chars[strindex].x ]; gl_Position = vec4(charPos.xy*2.0f*general.TextSize*general.FontScreenAspect.xy + vec2(-1, -1), 1, 1); - OUTglyphuv.xy = (pos.xy - G.posdata.xy) * G.posdata.zw; - OUTtex = G.uvdata * general.CharacterSize.xyxy; + OUT.glyphuv.xy = (pos.xy - G.posdata.xy) * G.posdata.zw; + OUT.tex = G.uvdata * general.CharacterSize.xyxy; } diff --git a/renderdoc/driver/vulkan/vk_debug.cpp b/renderdoc/driver/vulkan/vk_debug.cpp index 1972313a9..3d0193420 100644 --- a/renderdoc/driver/vulkan/vk_debug.cpp +++ b/renderdoc/driver/vulkan/vk_debug.cpp @@ -34,105 +34,7 @@ #include "3rdparty/stb/stb_truetype.h" #include "3rdparty/glslang/SPIRV/spirv.hpp" -// VKTODOMED should share this between shader and C++ - need #include support in glslang -struct displayuniforms -{ - Vec2f Position; - float Scale; - float HDRMul; - - Vec4f Channels; - - float RangeMinimum; - float InverseRangeSize; - float MipLevel; - int FlipY; - - Vec3f TextureResolutionPS; - int OutputDisplayFormat; - - Vec2f OutputRes; - int RawOutput; - float Slice; - - int SampleIdx; - int NumSamples; - Vec2f Padding; -}; - -struct fontuniforms -{ - Vec2f TextPosition; - float txtpadding; - float TextSize; - - Vec2f CharacterSize; - Vec2f FontScreenAspect; -}; - -struct glyph -{ - Vec4f posdata; - Vec4f uvdata; -}; - -struct glyphdata -{ - glyph glyphs[127-32]; -}; - -struct stringdata -{ - uint32_t str[256][4]; -}; - -struct meshuniforms -{ - Matrix4f mvp; - Matrix4f invProj; - Vec4f color; - uint32_t displayFormat; - uint32_t homogenousInput; - Vec2f pointSpriteSize; -}; - -// histogram/minmax is calculated in blocks of NxN each with MxM tiles. -// e.g. a tile is 32x32 pixels, then this is arranged in blocks of 32x32 tiles. -// 1 compute thread = 1 tile, 1 compute group = 1 block -// -// NOTE because of this a block can cover more than the texture (think of a 1280x720 -// texture covered by 2x1 blocks) -// -// these values are in each dimension -#define HGRAM_PIXELS_PER_TILE 64 -#define HGRAM_TILES_PER_BLOCK 32 - -#define HGRAM_NUM_BUCKETS 256 - -struct histogramuniforms -{ - uint32_t HistogramChannels; - float HistogramMin; - float HistogramMax; - uint32_t HistogramFlags; - - float HistogramSlice; - uint32_t HistogramMip; - int HistogramSample; - int HistogramNumSamples; - - Vec3f HistogramTextureResolution; - float Padding3; -}; - -struct outlineuniforms -{ - Vec4f Inner_Color; - Vec4f Border_Color; - Vec4f ViewRect; - uint32_t Scissor; - Vec3f padding; -}; +#include "data/spv/debuguniforms.h" void VulkanDebugManager::GPUBuffer::Create(WrappedVulkan *driver, VkDevice dev, VkDeviceSize size, uint32_t ringSize, uint32_t flags) { @@ -656,18 +558,18 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev) m_ReadbackWindow.Create(driver, dev, STAGE_BUFFER_BYTE_SIZE, 1, GPUBuffer::eGPUBufferReadback); m_OutlineUBO.Create(driver, dev, 128, 10, 0); - RDCCOMPILE_ASSERT(sizeof(outlineuniforms) <= 128, "outline UBO size"); + RDCCOMPILE_ASSERT(sizeof(OutlineUBOData) <= 128, "outline UBO size"); m_CheckerboardUBO.Create(driver, dev, 128, 10, 0); m_TexDisplayUBO.Create(driver, dev, 128, 10, 0); - RDCCOMPILE_ASSERT(sizeof(displayuniforms) <= 128, "tex display size"); + RDCCOMPILE_ASSERT(sizeof(TexDisplayUBOData) <= 128, "tex display size"); m_TextGeneralUBO.Create(driver, dev, 128, 100, 0); // make the ring conservatively large to handle many lines of text * several frames - RDCCOMPILE_ASSERT(sizeof(fontuniforms) <= 128, "font uniforms size"); + RDCCOMPILE_ASSERT(sizeof(FontUBOData) <= 128, "font uniforms size"); - m_TextStringUBO.Create(driver, dev, 4096, 10, 0); // we only use a subset of the [256] array needed for each line, so this ring can be smaller - RDCCOMPILE_ASSERT(sizeof(stringdata) <= 4096, "font uniforms size"); + m_TextStringUBO.Create(driver, dev, 4096, 10, 0); // we only use a subset of the [MAX_SINGLE_LINE_LENGTH] array needed for each line, so this ring can be smaller + RDCCOMPILE_ASSERT(sizeof(StringUBOData) <= 4096, "font uniforms size"); string shaderSources[] = { GetEmbeddedResource(spirv_blit_vert), @@ -730,11 +632,15 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev) string err = GetSPIRVBlob(eSPIRVFragment, sources, &m_FixedColSPIRV); RDCASSERT(err.empty() && m_FixedColSPIRV); + + sources.resize(4); + sources[0] = "#version 430 core\n"; + sources[1] = GetEmbeddedResource(spirv_debuguniforms_h); + sources[2] = ""; // #defines for(size_t i=0; i < ARRAY_COUNT(module); i++) { - sources.clear(); - sources.push_back(shaderSources[i]); + sources[3] = shaderSources[i]; string err = GetSPIRVBlob(shaderStages[i], sources, &shaderSPIRV[i]); RDCASSERT(err.empty() && shaderSPIRV); @@ -1027,9 +933,11 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev) string font = GetEmbeddedResource(sourcecodepro_ttf); byte *ttfdata = (byte *)font.c_str(); - const int firstChar = int(' ') + 1; - const int lastChar = 127; - const int numChars = lastChar-firstChar; + const int firstChar = FONT_FIRST_CHAR; + const int lastChar = FONT_LAST_CHAR; + const int numChars = lastChar-firstChar+1; + + RDCCOMPILE_ASSERT(FONT_FIRST_CHAR == int(' '), "Font defines are messed up"); byte *buf = new byte[width*height]; @@ -1126,7 +1034,7 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev) m_TextGlyphUBO.Create(driver, dev, 4096, 1, 0); // doesn't need to be ring'd, as it's static RDCCOMPILE_ASSERT(sizeof(Vec4f)*2*(numChars+1) < 4096, "font uniform size"); - Vec4f *glyphData = (Vec4f *)m_TextGlyphUBO.Map(vt, dev, (uint32_t *)NULL); + FontGlyphData *glyphData = (FontGlyphData *)m_TextGlyphUBO.Map(vt, dev, (uint32_t *)NULL); for(int i=0; i < numChars; i++) { @@ -1135,8 +1043,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev) float x = b->xoff; float y = b->yoff + maxheight; - glyphData[(i+1)*2 + 0] = Vec4f(x/b->xadvance, y/pixelHeight, b->xadvance/float(b->x1 - b->x0), pixelHeight/float(b->y1 - b->y0)); - glyphData[(i+1)*2 + 1] = Vec4f(b->x0, b->y0, b->x1, b->y1); + glyphData[i].posdata = Vec4f(x/b->xadvance, y/pixelHeight, b->xadvance/float(b->x1 - b->x0), pixelHeight/float(b->y1 - b->y0)); + glyphData[i].uvdata = Vec4f(b->x0, b->y0, b->x1, b->y1); } m_TextGlyphUBO.Unmap(vt, dev); @@ -1259,7 +1167,7 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev) m_PickPixelReadbackBuffer.Create(driver, dev, sizeof(float)*4, 1, GPUBuffer::eGPUBufferReadback); } - m_MeshUBO.Create(driver, dev, sizeof(meshuniforms), 16, 0); + m_MeshUBO.Create(driver, dev, sizeof(MeshUBOData), 16, 0); m_MeshBBoxVB.Create(driver, dev, sizeof(Vec4f)*128, 16, GPUBuffer::eGPUBufferVBuffer); Vec4f TLN = Vec4f(-1.0f, 1.0f, 0.0f, 1.0f); // TopLeftNear, etc... @@ -1320,7 +1228,7 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev) m_HistogramReadback.Create(driver, dev, sizeof(uint32_t)*HGRAM_NUM_BUCKETS, 1, GPUBuffer::eGPUBufferReadback); // don't need to ring this, as we hard-sync for readback anyway - m_HistogramUBO.Create(driver, dev, sizeof(histogramuniforms), 1, 0); + m_HistogramUBO.Create(driver, dev, sizeof(HistogramUBOData), 1, 0); VkDescriptorBufferInfo bufInfo[6]; RDCEraseEl(bufInfo); @@ -1733,7 +1641,7 @@ void VulkanDebugManager::RenderTextInternal(const TextPrintState &textstate, flo uint32_t offsets[2] = { 0 }; - fontuniforms *ubo = (fontuniforms *)m_TextGeneralUBO.Map(vt, m_Device, &offsets[0]); + FontUBOData *ubo = (FontUBOData *)m_TextGeneralUBO.Map(vt, m_Device, &offsets[0]); ubo->TextPosition.x = x; ubo->TextPosition.y = y; @@ -1749,11 +1657,15 @@ void VulkanDebugManager::RenderTextInternal(const TextPrintState &textstate, flo m_TextGeneralUBO.Unmap(vt, m_Device); + size_t len = strlen(text); + + RDCASSERT(len <= MAX_SINGLE_LINE_LENGTH); + // only map enough for our string - stringdata *stringData = (stringdata *)m_TextStringUBO.Map(vt, m_Device, &offsets[1], strlen(text)*sizeof(Vec4f)); + StringUBOData *stringData = (StringUBOData *)m_TextStringUBO.Map(vt, m_Device, &offsets[1], len*sizeof(Vec4u)); for(size_t i=0; i < strlen(text); i++) - stringData->str[i][0] = uint32_t(text[i] - ' '); + stringData->chars[i].x = uint32_t(text[i] - ' '); m_TextStringUBO.Unmap(vt, m_Device); @@ -2416,7 +2328,7 @@ ResourceId VulkanDebugManager::RenderOverlay(ResourceId texid, TextureDisplayOve uint32_t uboOffs = 0; - outlineuniforms *ubo = (outlineuniforms *)m_OutlineUBO.Map(vt, m_Device, &uboOffs); + OutlineUBOData *ubo = (OutlineUBOData *)m_OutlineUBO.Map(vt, m_Device, &uboOffs); ubo->Inner_Color = Vec4f(0.2f, 0.2f, 0.9f, 0.7f); ubo->Border_Color = Vec4f(0.1f, 0.1f, 0.1f, 1.0f); @@ -2438,7 +2350,7 @@ ResourceId VulkanDebugManager::RenderOverlay(ResourceId texid, TextureDisplayOve (float)m_pDriver->m_RenderState.scissors[0].extent.width, (float)m_pDriver->m_RenderState.scissors[0].extent.height); - outlineuniforms *ubo = (outlineuniforms *)m_OutlineUBO.Map(vt, m_Device, &uboOffs); + OutlineUBOData *ubo = (OutlineUBOData *)m_OutlineUBO.Map(vt, m_Device, &uboOffs); ubo->Inner_Color = Vec4f(0.2f, 0.2f, 0.9f, 0.7f); ubo->Border_Color = Vec4f(0.1f, 0.1f, 0.1f, 1.0f); diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index ae5f36ff9..dd35a4b7e 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -32,74 +32,7 @@ #include "serialise/string_utils.h" -// VKTODOMED should share this between shader and C++ - need #include support in glslang -struct displayuniforms -{ - Vec2f Position; - float Scale; - float HDRMul; - - Vec4f Channels; - - float RangeMinimum; - float InverseRangeSize; - float MipLevel; - int FlipY; - - Vec3f TextureResolutionPS; - int OutputDisplayFormat; - - Vec2f OutputRes; - int RawOutput; - float Slice; - - int SampleIdx; - int NumSamples; - Vec2f Padding; -}; - -#define TEXDISPLAY_TYPEMASK 0xF -#define TEXDISPLAY_UINT_TEX 0x10 -#define TEXDISPLAY_SINT_TEX 0x20 -#define TEXDISPLAY_NANS 0x80 -#define TEXDISPLAY_CLIPPING 0x100 -#define TEXDISPLAY_GAMMA_CURVE 0x200 - -struct meshuniforms -{ - Matrix4f mvp; - Matrix4f invProj; - Vec4f color; - uint32_t displayFormat; - uint32_t homogenousInput; - Vec2f pointSpriteSize; -}; - -#define MESHDISPLAY_SOLID 0x1 -#define MESHDISPLAY_FACELIT 0x2 -#define MESHDISPLAY_SECONDARY 0x3 -#define MESHDISPLAY_SECONDARY_ALPHA 0x4 - -#define HGRAM_PIXELS_PER_TILE 64 -#define HGRAM_TILES_PER_BLOCK 32 - -#define HGRAM_NUM_BUCKETS 256 - -struct histogramuniforms -{ - uint32_t HistogramChannels; - float HistogramMin; - float HistogramMax; - uint32_t HistogramFlags; - - float HistogramSlice; - uint32_t HistogramMip; - int HistogramSample; - int HistogramNumSamples; - - Vec3f HistogramTextureResolution; - float Padding3; -}; +#include "data/spv/debuguniforms.h" VulkanReplay::OutputWindow::OutputWindow() : wnd(NULL_WND_HANDLE), width(0), height(0), dsimg(VK_NULL_HANDLE), dsmem(VK_NULL_HANDLE) @@ -976,7 +909,7 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn uint32_t uboOffs = 0; - displayuniforms *data = (displayuniforms *)GetDebugManager()->m_TexDisplayUBO.Map(vt, dev, &uboOffs); + TexDisplayUBOData *data = (TexDisplayUBOData *)GetDebugManager()->m_TexDisplayUBO.Map(vt, dev, &uboOffs); data->Padding = 0; @@ -1438,7 +1371,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); data->mvp = ModelViewProj; data->color = (Vec4f &)cfg.prevMeshColour; @@ -1528,7 +1461,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); if(cfg.solidShadeMode == eShade_Lit) data->invProj = projMat.Inverse(); @@ -1581,7 +1514,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); data->mvp = ModelViewProj; data->color = wireCol; @@ -1674,7 +1607,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorCmdBindVertexBuffers(Unwrap(cmd), 0, 1, UnwrapPtr(GetDebugManager()->m_MeshBBoxVB.buf), &vboffs); uint32_t uboOffs = 0; - meshuniforms *data = (meshuniforms *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); + MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); data->mvp = ModelViewProj; data->color = Vec4f(0.2f, 0.2f, 1.0f, 1.0f); @@ -1699,7 +1632,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorCmdBindVertexBuffers(Unwrap(cmd), 0, 1, UnwrapPtr(GetDebugManager()->m_MeshAxisFrustumVB.buf), &vboffs); uint32_t uboOffs = 0; - meshuniforms *data = (meshuniforms *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); + MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); data->mvp = ModelViewProj; data->color = Vec4f(1.0f, 0.0f, 0.0f, 1.0f); @@ -1717,7 +1650,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorCmdDraw(Unwrap(cmd), 2, 1, 0, 0); // poke the color (this would be a good candidate for a push constant) - data = (meshuniforms *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); + data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); data->mvp = ModelViewProj; data->color = Vec4f(0.0f, 1.0f, 0.0f, 1.0f); @@ -1731,7 +1664,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshDescSet), 1, &uboOffs); vt->CmdDraw(Unwrap(cmd), 2, 1, 2, 0); - data = (meshuniforms *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); + data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); data->mvp = ModelViewProj; data->color = Vec4f(0.0f, 0.0f, 1.0f, 1.0f); @@ -1753,7 +1686,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorCmdBindVertexBuffers(Unwrap(cmd), 0, 1, UnwrapPtr(GetDebugManager()->m_MeshAxisFrustumVB.buf), &vboffs); uint32_t uboOffs = 0; - meshuniforms *data = (meshuniforms *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); + MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); data->mvp = ModelViewProj; data->color = Vec4f(1.0f, 1.0f, 1.0f, 1.0f); @@ -2158,7 +2091,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); *data = uniforms; GetDebugManager()->m_MeshUBO.Unmap(vt, dev); @@ -2181,7 +2114,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); *data = uniforms; GetDebugManager()->m_MeshUBO.Unmap(vt, dev); vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_MeshPipeLayout), @@ -2204,7 +2137,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); *data = uniforms; GetDebugManager()->m_MeshUBO.Unmap(vt, dev); vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_MeshPipeLayout), @@ -2234,7 +2167,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); *data = uniforms; GetDebugManager()->m_MeshUBO.Unmap(vt, dev); vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_MeshPipeLayout), @@ -2272,7 +2205,7 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vectorm_MeshUBO.Map(vt, dev, &uboOffs); + data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(vt, dev, &uboOffs); *data = uniforms; GetDebugManager()->m_MeshUBO.Unmap(vt, dev); vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_MeshPipeLayout), @@ -3373,7 +3306,7 @@ bool VulkanReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, vt->UpdateDescriptorSets(Unwrap(dev), ARRAY_COUNT(writeSet), writeSet, 0, NULL); - histogramuniforms *data = (histogramuniforms *)GetDebugManager()->m_HistogramUBO.Map(vt, dev, NULL); + HistogramUBOData *data = (HistogramUBOData *)GetDebugManager()->m_HistogramUBO.Map(vt, dev, NULL); data->HistogramTextureResolution.x = (float)RDCMAX(uint32_t(iminfo.extent.width)>>mip, 1U); data->HistogramTextureResolution.y = (float)RDCMAX(uint32_t(iminfo.extent.height)>>mip, 1U); @@ -3584,7 +3517,7 @@ bool VulkanReplay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t m vt->UpdateDescriptorSets(Unwrap(dev), ARRAY_COUNT(writeSet), writeSet, 0, NULL); - histogramuniforms *data = (histogramuniforms *)GetDebugManager()->m_HistogramUBO.Map(vt, dev, NULL); + HistogramUBOData *data = (HistogramUBOData *)GetDebugManager()->m_HistogramUBO.Map(vt, dev, NULL); data->HistogramTextureResolution.x = (float)RDCMAX(uint32_t(iminfo.extent.width)>>mip, 1U); data->HistogramTextureResolution.y = (float)RDCMAX(uint32_t(iminfo.extent.height)>>mip, 1U); diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index 5c1a395aa..ed28b77ac 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -255,6 +255,7 @@ + @@ -361,8 +362,6 @@ - - diff --git a/renderdoc/renderdoc.vcxproj.filters b/renderdoc/renderdoc.vcxproj.filters index cd6c0108b..2a0e7765f 100644 --- a/renderdoc/renderdoc.vcxproj.filters +++ b/renderdoc/renderdoc.vcxproj.filters @@ -231,6 +231,9 @@ Common + + Resources\spv + @@ -448,12 +451,6 @@ Resources\spv - - Resources\spv - - - Resources\spv - Resources\spv