Skip to content

Commit da852fa

Browse files
committed
Day 32: Final descriptor cleanup
Replace the remaining combined image/sampler objects with separate ones; after the texelFetch cleanup this just involved a couple of stragglers. DescriptorInfo ctor from image+sampler is now redundant. Also, similarly to what we did on stream, remove .buffer from the DescriptorInfo calls so that the descriptor infos track the original resource. This was done after the stream.
1 parent 18a56e7 commit da852fa

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

src/niagara.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void pushDescriptors(VkCommandBuffer commandBuffer, FrameDescriptors& framedesc,
144144

145145
const Image* image = static_cast<const Image*>(info.resource);
146146
char descriptor[128];
147-
getDescriptor(framedesc.device, image->image, image->format, 0, 1, program.resourceTypes[i], descriptor, framedesc.descriptorSize);
147+
getDescriptor(framedesc.device, image->image, image->format, 0, VK_REMAINING_MIP_LEVELS, program.resourceTypes[i], descriptor, framedesc.descriptorSize);
148148

149149
memcpy(static_cast<char*>(framedesc.descriptorHeap) + (framedesc.descriptorOffset + i) * framedesc.descriptorSize, descriptor, framedesc.descriptorSize);
150150
}
@@ -1370,8 +1370,7 @@ int main(int argc, const char** argv)
13701370

13711371
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
13721372

1373-
DescriptorInfo pyramidDesc(depthSampler, depthPyramid.imageView);
1374-
DescriptorInfo descriptors[] = { db.buffer, mb.buffer, dcb.buffer, dccb.buffer, dvb.buffer, pyramidDesc };
1373+
DescriptorInfo descriptors[] = { db, mb, dcb, dccb, dvb, depthPyramid, depthSampler };
13751374

13761375
dispatch(commandBuffer, framedesc, drawcullProgram, uint32_t(draws.size()), 1, passData, descriptors);
13771376
}
@@ -1382,7 +1381,7 @@ int main(int argc, const char** argv)
13821381

13831382
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, tasksubmitPipeline);
13841383

1385-
DescriptorInfo descriptors[] = { dccb.buffer, dcb.buffer };
1384+
DescriptorInfo descriptors[] = { dccb, dcb };
13861385
pushDescriptors(commandBuffer, framedesc, tasksubmitProgram, descriptors);
13871386

13881387
vkCmdDispatch(commandBuffer, 1, 1, 1);
@@ -1409,8 +1408,7 @@ int main(int argc, const char** argv)
14091408

14101409
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, late ? clusterculllatePipeline : clustercullPipeline);
14111410

1412-
DescriptorInfo pyramidDesc(depthSampler, depthPyramid.imageView);
1413-
DescriptorInfo descriptors[] = { dcb.buffer, db.buffer, mlb.buffer, mvb.buffer, pyramidDesc, cib.buffer, ccb.buffer };
1411+
DescriptorInfo descriptors[] = { dcb, db, mlb, mvb, depthPyramid, cib, ccb, depthSampler };
14141412
pushDescriptors(commandBuffer, framedesc, clustercullProgram, descriptors);
14151413

14161414
CullData passData = cullData;
@@ -1423,7 +1421,7 @@ int main(int argc, const char** argv)
14231421

14241422
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, clustersubmitPipeline);
14251423

1426-
DescriptorInfo descriptors2[] = { ccb.buffer, cib.buffer };
1424+
DescriptorInfo descriptors2[] = { ccb, cib };
14271425
pushDescriptors(commandBuffer, framedesc, clustersubmitProgram, descriptors2);
14281426

14291427
vkCmdDispatch(commandBuffer, 1, 1, 1);
@@ -1475,7 +1473,7 @@ int main(int argc, const char** argv)
14751473
{
14761474
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, postPass >= 1 ? clusterpostPipeline : clusterPipeline);
14771475

1478-
DescriptorInfo descriptors[] = { dcb.buffer, db.buffer, mlb.buffer, mdb.buffer, vb.buffer, cib.buffer, DescriptorInfo(), textureSampler, mtb.buffer };
1476+
DescriptorInfo descriptors[] = { dcb, db, mlb, mdb, vb, cib, DescriptorInfo(), textureSampler, mtb };
14791477
pushDescriptors(commandBuffer, framedesc, clusterProgram, descriptors);
14801478

14811479
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, clusterProgram.layout, 1, 1, &textureSet.second, 0, nullptr);
@@ -1488,8 +1486,7 @@ int main(int argc, const char** argv)
14881486
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, postPass >= 1 ? meshtaskpostPipeline : late ? meshtasklatePipeline
14891487
: meshtaskPipeline);
14901488

1491-
DescriptorInfo pyramidDesc(depthSampler, depthPyramid.imageView);
1492-
DescriptorInfo descriptors[] = { dcb.buffer, db.buffer, mlb.buffer, mdb.buffer, vb.buffer, mvb.buffer, pyramidDesc, textureSampler, mtb.buffer };
1489+
DescriptorInfo descriptors[] = { dcb, db, mlb, mdb, vb, mvb, depthPyramid, textureSampler, mtb, depthSampler };
14931490
pushDescriptors(commandBuffer, framedesc, meshtaskProgram, descriptors);
14941491

14951492
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, meshtaskProgram.layout, 1, 1, &textureSet.second, 0, nullptr);
@@ -1501,7 +1498,7 @@ int main(int argc, const char** argv)
15011498
{
15021499
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, postPass >= 1 ? meshpostPipeline : meshPipeline);
15031500

1504-
DescriptorInfo descriptors[] = { dcb.buffer, db.buffer, vb.buffer, DescriptorInfo(), DescriptorInfo(), DescriptorInfo(), DescriptorInfo(), textureSampler, mtb.buffer };
1501+
DescriptorInfo descriptors[] = { dcb, db, vb, DescriptorInfo(), DescriptorInfo(), DescriptorInfo(), DescriptorInfo(), textureSampler, mtb };
15051502
pushDescriptors(commandBuffer, framedesc, meshProgram, descriptors);
15061503

15071504
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, meshProgram.layout, 1, 1, &textureSet.second, 0, nullptr);
@@ -1529,11 +1526,9 @@ int main(int argc, const char** argv)
15291526

15301527
for (uint32_t i = 0; i < depthPyramidLevels; ++i)
15311528
{
1532-
DescriptorInfo sourceDepth = (i == 0)
1533-
? DescriptorInfo(depthSampler, depthTarget.imageView)
1534-
: DescriptorInfo(depthSampler, depthPyramidMips[i - 1]);
1529+
VkImageView sourceDepth = (i == 0) ? depthTarget.imageView : depthPyramidMips[i - 1];
15351530

1536-
DescriptorInfo descriptors[] = { depthPyramidMips[i], sourceDepth };
1531+
DescriptorInfo descriptors[] = { depthPyramidMips[i], sourceDepth, depthSampler };
15371532

15381533
uint32_t levelWidth = std::max(1u, depthPyramidWidth >> i);
15391534
uint32_t levelHeight = std::max(1u, depthPyramidHeight >> i);

src/shaders.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ struct DescriptorInfo
9191
accelerationStructure = structure;
9292
}
9393

94-
DescriptorInfo(VkImageView imageView, VkImageLayout imageLayout = VK_IMAGE_LAYOUT_GENERAL)
94+
DescriptorInfo(VkImageView imageView)
9595
{
9696
image.sampler = VK_NULL_HANDLE;
9797
image.imageView = imageView;
98-
image.imageLayout = imageLayout;
98+
image.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
9999
}
100100

101101
DescriptorInfo(VkSampler sampler)
@@ -105,13 +105,6 @@ struct DescriptorInfo
105105
image.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
106106
}
107107

108-
DescriptorInfo(VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout = VK_IMAGE_LAYOUT_GENERAL)
109-
{
110-
image.sampler = sampler;
111-
image.imageView = imageView;
112-
image.imageLayout = imageLayout;
113-
}
114-
115108
DescriptorInfo(VkBuffer buffer_)
116109
{
117110
buffer.buffer = buffer_;

src/shaders/clustercull.comp.glsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ layout(binding = 3) buffer MeshletVisibility
3939
uint meshletVisibility[];
4040
};
4141

42-
layout(binding = 4) uniform sampler2D depthPyramid;
42+
layout(binding = 4) uniform texture2D depthPyramid;
4343

4444
layout(binding = 5) writeonly buffer ClusterIndices
4545
{
@@ -51,6 +51,8 @@ layout(binding = 6) buffer ClusterCount
5151
uint clusterCount;
5252
};
5353

54+
layout(binding = 7) uniform sampler depthSampler;
55+
5456
void main()
5557
{
5658
// we convert 2D index to 1D index using a fixed *64 factor, see tasksubmit.comp.glsl
@@ -116,7 +118,7 @@ void main()
116118
float level = floor(log2(max(width, height)));
117119

118120
// Sampler is set up to do min reduction, so this computes the minimum depth of a 2x2 texel quad
119-
float depth = textureLod(depthPyramid, (aabb.xy + aabb.zw) * 0.5, level).x;
121+
float depth = textureLod(sampler2D(depthPyramid, depthSampler), (aabb.xy + aabb.zw) * 0.5, level).x;
120122
float depthSphere = cullData.znear / (center.z - radius);
121123

122124
visible = visible && depthSphere > depth;

src/shaders/depthreduce.comp.glsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
44

55
layout(binding = 0, r32f) uniform writeonly image2D outImage;
6-
layout(binding = 1) uniform sampler2D inImage;
6+
layout(binding = 1) uniform texture2D inImage;
7+
layout(binding = 2) uniform sampler depthSampler;
78

89
layout(push_constant) uniform block
910
{
@@ -15,7 +16,7 @@ void main()
1516
uvec2 pos = gl_GlobalInvocationID.xy;
1617

1718
// Sampler is set up to do min reduction, so this computes the minimum depth of a 2x2 texel quad
18-
float depth = texture(inImage, (vec2(pos) + vec2(0.5)) / imageSize).x;
19+
float depth = texture(sampler2D(inImage, depthSampler), (vec2(pos) + vec2(0.5)) / imageSize).x;
1920

2021
imageStore(outImage, ivec2(pos), vec4(depth));
2122
}

src/shaders/drawcull.comp.glsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ layout(binding = 4) buffer DrawVisibility
4848
uint drawVisibility[];
4949
};
5050

51-
layout(binding = 5) uniform sampler2D depthPyramid;
51+
layout(binding = 5) uniform texture2D depthPyramid;
52+
layout(binding = 6) uniform sampler depthSampler;
5253

5354
void main()
5455
{
@@ -96,7 +97,7 @@ void main()
9697
float level = ceil(log2(max(width, height)));
9798

9899
// Sampler is set up to do min reduction, so this computes the minimum depth of a 2x2 texel quad
99-
float depth = textureLod(depthPyramid, (aabb.xy + aabb.zw) * 0.5, level).x;
100+
float depth = textureLod(sampler2D(depthPyramid, depthSampler), (aabb.xy + aabb.zw) * 0.5, level).x;
100101
float depthSphere = cullData.znear / (center.z - radius);
101102

102103
visible = visible && depthSphere > depth;

src/shaders/meshlet.task.glsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ layout(binding = 5) buffer MeshletVisibility
4040
uint meshletVisibility[];
4141
};
4242

43-
layout(binding = 6) uniform sampler2D depthPyramid;
43+
layout(binding = 6) uniform texture2D depthPyramid;
44+
45+
layout(binding = 9) uniform sampler depthSampler;
4446

4547
taskPayloadSharedEXT MeshTaskPayload payload;
4648

@@ -118,7 +120,7 @@ void main()
118120
float level = floor(log2(max(width, height)));
119121

120122
// Sampler is set up to do min reduction, so this computes the minimum depth of a 2x2 texel quad
121-
float depth = textureLod(depthPyramid, (aabb.xy + aabb.zw) * 0.5, level).x;
123+
float depth = textureLod(sampler2D(depthPyramid, depthSampler), (aabb.xy + aabb.zw) * 0.5, level).x;
122124
float depthSphere = cullData.znear / (center.z - radius);
123125

124126
visible = visible && depthSphere > depth;

0 commit comments

Comments
 (0)