Skip to content

Commit 86ed05d

Browse files
committed
More fixes to descriptor heap scaffolding
- Add a way to specify mip index for an image descriptor (for pyramid) - Upload static image descriptors to the descriptor heap with 1+ indexing - Fix .pNext confusion in graphics pipeline creation
1 parent 027f38d commit 86ed05d

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/niagara.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ void pushDescriptors(VkCommandBuffer commandBuffer, FrameDescriptors& framedesc,
161161
{
162162
const Image* image = static_cast<const Image*>(info.resource);
163163
assert(image);
164-
getDescriptor(framedesc.device, image->image, image->format, 0, VK_REMAINING_MIP_LEVELS, program.resourceTypes[i], descriptor, framedesc.descriptorSize);
164+
uint32_t mipLevel = (info.resourceMip < 0) ? 0 : uint32_t(info.resourceMip);
165+
uint32_t levelCount = (info.resourceMip < 0) ? VK_REMAINING_MIP_LEVELS : 1;
166+
getDescriptor(framedesc.device, image->image, image->format, mipLevel, levelCount, program.resourceTypes[i], descriptor, framedesc.descriptorSize);
165167
break;
166168
}
167169

@@ -296,6 +298,13 @@ DescriptorInfo::DescriptorInfo(const struct Image& image)
296298
resource = &image;
297299
}
298300

301+
DescriptorInfo::DescriptorInfo(const struct Image& image, VkImageView mipView, int mipIndex)
302+
: DescriptorInfo(mipView)
303+
{
304+
resource = &image;
305+
resourceMip = mipIndex;
306+
}
307+
299308
void errorCallback(int error_code, const char* description)
300309
{
301310
fprintf(stderr, "GLFW ERROR (%d): %s\n", error_code, description);
@@ -849,6 +858,10 @@ int main(int argc, const char** argv)
849858
write.pImageInfo = &imageInfo;
850859

851860
vkUpdateDescriptorSets(device, 1, &write, 0, nullptr);
861+
862+
if (descheapSupported)
863+
getDescriptor(device, images[i].image, images[i].format, 0, VK_REMAINING_MIP_LEVELS, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
864+
static_cast<char*>(resourceHeap.data) + (1 + i) * resourceDescriptorSize, resourceDescriptorSize);
852865
}
853866

854867
if (!sceneMode)
@@ -1559,11 +1572,12 @@ int main(int argc, const char** argv)
15591572

15601573
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, depthreducePipeline);
15611574

1575+
DescriptorInfo mipSource = depthTarget;
1576+
15621577
for (uint32_t i = 0; i < depthPyramidLevels; ++i)
15631578
{
1564-
VkImageView sourceDepth = (i == 0) ? depthTarget.imageView : depthPyramidMips[i - 1];
1565-
1566-
DescriptorInfo descriptors[] = { depthPyramidMips[i], sourceDepth, depthSampler };
1579+
DescriptorInfo mipTarget(depthPyramid, depthPyramidMips[i], int(i));
1580+
DescriptorInfo descriptors[] = { mipTarget, mipSource, depthSampler };
15671581

15681582
uint32_t levelWidth = std::max(1u, depthPyramidWidth >> i);
15691583
uint32_t levelHeight = std::max(1u, depthPyramidHeight >> i);
@@ -1573,6 +1587,8 @@ int main(int argc, const char** argv)
15731587
dispatch(commandBuffer, framedesc, depthreduceProgram, levelWidth, levelHeight, reduceData, descriptors);
15741588

15751589
stageBarrier(commandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
1590+
1591+
mipSource = mipTarget;
15761592
}
15771593

15781594
stageBarrier(commandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);

src/resources.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ void getDescriptor(VkDevice device, VkDeviceAddress address, VkDeviceSize size,
348348

349349
void getDescriptor(VkDevice device, VkFilter filter, VkSamplerMipmapMode mipmapMode, VkSamplerAddressMode addressMode, VkSamplerReductionModeEXT reductionMode, void* descriptor, size_t descriptorSize)
350350
{
351-
VkSamplerReductionModeCreateInfoEXT createInfoReduction = { VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT };
352-
353351
VkSamplerCreateInfo createInfo = getSamplerInfo(filter, mipmapMode, addressMode);
354352

355353
VkSamplerReductionModeCreateInfoEXT reductionInfo = { VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT };

src/shaders.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,10 @@ VkPipeline createGraphicsPipeline(VkDevice device, VkPipelineCache pipelineCache
587587
std::vector<VkSpecializationMapEntry> specializationEntries;
588588
VkSpecializationInfo specializationInfo = fillSpecializationInfo(specializationEntries, constants);
589589

590-
VkGraphicsPipelineCreateInfo createInfo = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO };
591-
592590
VkPipelineCreateFlags2CreateInfo extraFlags = { VK_STRUCTURE_TYPE_PIPELINE_CREATE_FLAGS_2_CREATE_INFO };
591+
extraFlags.pNext = &renderingInfo;
592+
593+
VkGraphicsPipelineCreateInfo createInfo = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO };
593594
createInfo.pNext = &extraFlags;
594595

595596
#if VK_EXT_descriptor_heap
@@ -677,7 +678,6 @@ VkPipeline createGraphicsPipeline(VkDevice device, VkPipelineCache pipelineCache
677678
createInfo.pDynamicState = &dynamicState;
678679

679680
createInfo.layout = program.layout;
680-
createInfo.pNext = &renderingInfo;
681681

682682
VkPipeline pipeline = 0;
683683
VK_CHECK(vkCreateGraphicsPipelines(device, pipelineCache, 1, &createInfo, 0, &pipeline));

src/shaders.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct DescriptorInfo
8181
};
8282

8383
const void* resource = NULL;
84+
int resourceMip = -1;
8485

8586
DescriptorInfo()
8687
{
@@ -114,4 +115,5 @@ struct DescriptorInfo
114115

115116
DescriptorInfo(const struct Buffer& buffer);
116117
DescriptorInfo(const struct Image& image);
118+
DescriptorInfo(const struct Image& image, VkImageView mipView, int mipIndex);
117119
};

0 commit comments

Comments
 (0)