Skip to content

Commit a9ad4b2

Browse files
Merge pull request #99 from Devsh-Graphics-Programming/vulkan_1_3_example_07_fix
Vulkan_1_3 example 07 fix
2 parents d5a1482 + fde6714 commit a9ad4b2

File tree

6 files changed

+567
-41
lines changed

6 files changed

+567
-41
lines changed

07_StagingAndMultipleQueues/app_resources/common.hlsl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,21 @@
22

33
NBL_CONSTEXPR uint32_t WorkgroupSizeX = 16;
44
NBL_CONSTEXPR uint32_t WorkgroupSizeY = 16;
5-
NBL_CONSTEXPR uint32_t WorkgroupSize = WorkgroupSizeX*WorkgroupSizeY;
5+
NBL_CONSTEXPR uint32_t WorkgroupSize = WorkgroupSizeX*WorkgroupSizeY;
6+
7+
static const uint32_t FRAMES_IN_FLIGHT = 3u;
8+
9+
static const uint32_t RED_OFFSET = 0u;
10+
static const uint32_t GREEN_OFFSET = 256u;
11+
static const uint32_t BLUE_OFFSET = 256u * 2u;
12+
13+
static const uint32_t CHANEL_CNT = 3;
14+
static const uint32_t VAL_PER_CHANEL_CNT = 256;
15+
static const uint32_t HISTOGRAM_SIZE = CHANEL_CNT * VAL_PER_CHANEL_CNT;
16+
static const uint32_t HISTOGRAM_BYTE_SIZE = HISTOGRAM_SIZE * sizeof(uint32_t);
17+
static const uint32_t COMBINED_HISTOGRAM_BUFFER_BYTE_SIZE = HISTOGRAM_BYTE_SIZE * FRAMES_IN_FLIGHT;
18+
19+
struct PushConstants
20+
{
21+
uint32_t histogramBufferOffset;
22+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma wave shader_stage(compute)
2+
3+
#include "../app_resources/common.hlsl"
4+
5+
[[vk::combinedImageSampler]][[vk::binding(0,0)]] Texture2D texture;
6+
[[vk::combinedImageSampler]][[vk::binding(0,0)]] SamplerState samplerState;
7+
[[vk::binding(1,0)]] RWStructuredBuffer<uint32_t> histogram;
8+
9+
[[vk::push_constant]]
10+
PushConstants constants;
11+
12+
[numthreads(WorkgroupSizeX,WorkgroupSizeY,1)]
13+
void main(uint32_t3 ID : SV_DispatchThreadID)
14+
{
15+
uint width;
16+
uint height;
17+
texture.GetDimensions(width, height);
18+
if(ID.x >= width || ID.y >= height)
19+
return;
20+
21+
float4 texel = texture.SampleLevel(samplerState, ID.xy, 0.0);
22+
23+
const uint32_t redVal = uint32_t(texel.r * 255u);
24+
const uint32_t greenVal = uint32_t(texel.g * 255u);
25+
const uint32_t blueVal = uint32_t(texel.b * 255u);
26+
27+
InterlockedAdd(histogram[constants.histogramBufferOffset + RED_OFFSET + redVal], 1);
28+
InterlockedAdd(histogram[constants.histogramBufferOffset + GREEN_OFFSET + greenVal], 1);
29+
InterlockedAdd(histogram[constants.histogramBufferOffset + BLUE_OFFSET + blueVal], 1);
30+
}
238 Bytes
Loading
237 Bytes
Loading
232 Bytes
Loading

0 commit comments

Comments
 (0)