File tree Expand file tree Collapse file tree 6 files changed +567
-41
lines changed
07_StagingAndMultipleQueues Expand file tree Collapse file tree 6 files changed +567
-41
lines changed Original file line number Diff line number Diff line change 2
2
3
3
NBL_CONSTEXPR uint32_t WorkgroupSizeX = 16 ;
4
4
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
+ };
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments