-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathstream_allocator_freegaps_insert.comp.glsl
More file actions
113 lines (90 loc) · 3.97 KB
/
Copy pathstream_allocator_freegaps_insert.comp.glsl
File metadata and controls
113 lines (90 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright (c) 2024-2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/
/*
Shader Description
==================
Only used for TARGETS_RAY_TRACING
Note: The sample showcases two ways to manage CLAS memory on the device.
One using a persistent allocator system (`stream_allocator...` files),
and one using a simple compaction scheme (`stream_compaction...` files).
This file is part of the allocator system.
This compute shader bins the free gaps based on their size.
It enables the allocator to provide empty gaps of certain sizes during
the allocation process within `stream_allocator_load_groups.comp.glsl`.
We read `streaming.clasAllocator.freeGapsPos` and `streaming.clasAllocator.freeGapsSize`
and bin into `streaming.clasAllocator.freeGapsPosBinned` using the appropriate
`streaming.clasAllocator.freeSizeRanges.d[freeGapSize-1].offset`
One thread operates on one free gap
*/
#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int32 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : enable
#extension GL_EXT_buffer_reference : enable
#extension GL_EXT_buffer_reference2 : enable
#extension GL_EXT_scalar_block_layout : enable
#extension GL_EXT_shader_atomic_int64 : enable
#extension GL_EXT_control_flow_attributes : require
#extension GL_KHR_shader_subgroup_vote : require
#extension GL_KHR_shader_subgroup_ballot : require
#extension GL_KHR_shader_subgroup_shuffle : require
#extension GL_KHR_shader_subgroup_basic : require
#extension GL_KHR_shader_subgroup_clustered : require
#extension GL_KHR_shader_subgroup_arithmetic : require
#extension GL_EXT_shader_subgroup_extended_types_int64 : require
#include "shaderio.h"
////////////////////////////////////////////
layout(scalar, binding = BINDINGS_READBACK_SSBO, set = 0) buffer readbackBuffer
{
Readback readback;
};
layout(scalar, binding = BINDINGS_GEOMETRIES_SSBO, set = 0) buffer geometryBuffer
{
Geometry geometries[];
};
layout(scalar, binding = BINDINGS_STREAMING_UBO, set = 0) uniform streamingBuffer
{
SceneStreaming streaming;
};
layout(scalar, binding = BINDINGS_STREAMING_SSBO, set = 0) buffer streamingBufferRW
{
SceneStreaming streamingRW;
};
////////////////////////////////////////////
layout(local_size_x=STREAM_ALLOCATOR_FREEGAPS_INSERT_WORKGROUP) in;
////////////////////////////////////////////
void main()
{
uint threadID = getGlobalInvocationIndex(gl_GlobalInvocationID);
bool valid = threadID < streaming.clasAllocator.freeGapsCounter;
if (valid)
{
// get the details of the free gap, it was computed in
// `stream_allocator_build_freegaps.comp.glsl`.
uint freeGapPos = streaming.clasAllocator.freeGapsPos.d[threadID];
uint freeGapSize = streaming.clasAllocator.freeGapsSize.d[threadID];
// bin the gap into `streaming.clasAllocator.freeGapsPosBinned` based on size
int32_t rangeIndex = atomicAdd(streaming.clasAllocator.freeSizeRanges.d[freeGapSize-1].count, 1);
uint rangeOffset = streaming.clasAllocator.freeSizeRanges.d[freeGapSize-1].offset;
uint storeOffset = rangeIndex + uint(rangeOffset);
streaming.clasAllocator.freeGapsPosBinned.d[storeOffset] = freeGapPos;
}
}