@@ -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 = ℑ
297299}
298300
301+ DescriptorInfo::DescriptorInfo (const struct Image & image, VkImageView mipView, int mipIndex)
302+ : DescriptorInfo(mipView)
303+ {
304+ resource = ℑ
305+ resourceMip = mipIndex;
306+ }
307+
299308void 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);
0 commit comments