mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-09 00:01:07 +00:00
121 lines
3.8 KiB
Plaintext
121 lines
3.8 KiB
Plaintext
/******************************************************************************
|
|
* The MIT License (MIT)
|
|
*
|
|
* Copyright (c) 2020-2022 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.
|
|
******************************************************************************/
|
|
|
|
#if defined(OPENGL_CORE)
|
|
#extension GL_ARB_compute_shader : require
|
|
#extension GL_ARB_shader_storage_buffer_object : require
|
|
|
|
// safe to assume this extension in compute shaders as it pre-dates compute shaders
|
|
#extension GL_ARB_shading_language_420pack : require
|
|
#endif
|
|
|
|
#define HISTOGRAM_UBO
|
|
|
|
#include "glsl_ubos.h"
|
|
|
|
layout(binding = 0, std140) writeonly buffer minmaxresultdest
|
|
{
|
|
#if UINT_TEX
|
|
uvec4 result[2];
|
|
#elif SINT_TEX
|
|
ivec4 result[2];
|
|
#else
|
|
vec4 result[2];
|
|
#endif
|
|
}
|
|
dest;
|
|
|
|
layout(binding = 1, std140) readonly buffer minmaxtilesrc
|
|
{
|
|
#if UINT_TEX
|
|
uvec4 tiles[];
|
|
#elif SINT_TEX
|
|
ivec4 tiles[];
|
|
#else
|
|
vec4 tiles[];
|
|
#endif
|
|
}
|
|
src;
|
|
|
|
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
|
|
|
void main()
|
|
{
|
|
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)));
|
|
|
|
#if UINT_TEX
|
|
uvec4 minvalU = src.tiles[0];
|
|
uvec4 maxvalU = src.tiles[1];
|
|
#elif SINT_TEX
|
|
ivec4 minvalI = src.tiles[0];
|
|
ivec4 maxvalI = src.tiles[1];
|
|
#else
|
|
vec4 minvalF = src.tiles[0];
|
|
vec4 maxvalF = src.tiles[1];
|
|
#endif
|
|
|
|
// i is the tile we're looking at
|
|
for(uint i = 1u; i < blocksX * blocksY * HGRAM_TILES_PER_BLOCK * HGRAM_TILES_PER_BLOCK; i++)
|
|
{
|
|
uint blockIdx = i / (HGRAM_TILES_PER_BLOCK * HGRAM_TILES_PER_BLOCK);
|
|
uint tileIdx = i % (HGRAM_TILES_PER_BLOCK * HGRAM_TILES_PER_BLOCK);
|
|
|
|
// which block and tile is this in
|
|
uvec2 blockXY = uvec2(blockIdx % blocksX, blockIdx / blocksX);
|
|
uvec2 tileXY = uvec2(tileIdx % HGRAM_TILES_PER_BLOCK, tileIdx / HGRAM_TILES_PER_BLOCK);
|
|
|
|
// if this is at least partially within the texture, include it.
|
|
if(blockXY.x * (HGRAM_TILES_PER_BLOCK * HGRAM_PIXELS_PER_TILE) + tileXY.x * HGRAM_PIXELS_PER_TILE <
|
|
texDim.x &&
|
|
blockXY.y * (HGRAM_TILES_PER_BLOCK * HGRAM_PIXELS_PER_TILE) + tileXY.y * HGRAM_PIXELS_PER_TILE <
|
|
texDim.y)
|
|
{
|
|
#if UINT_TEX
|
|
minvalU = min(minvalU, src.tiles[i * 2u + 0u]);
|
|
maxvalU = max(maxvalU, src.tiles[i * 2u + 1u]);
|
|
#elif SINT_TEX
|
|
minvalI = min(minvalI, src.tiles[i * 2u + 0u]);
|
|
maxvalI = max(maxvalI, src.tiles[i * 2u + 1u]);
|
|
#else
|
|
minvalF = min(minvalF, src.tiles[i * 2u + 0u]);
|
|
maxvalF = max(maxvalF, src.tiles[i * 2u + 1u]);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#if UINT_TEX
|
|
dest.result[0] = minvalU;
|
|
dest.result[1] = maxvalU;
|
|
#elif SINT_TEX
|
|
dest.result[0] = minvalI;
|
|
dest.result[1] = maxvalI;
|
|
#else
|
|
dest.result[0] = minvalF;
|
|
dest.result[1] = maxvalF;
|
|
#endif
|
|
}
|