@@ -134,28 +134,60 @@ void pushDescriptors(VkCommandBuffer commandBuffer, FrameDescriptors& framedesc,
134134#if VK_EXT_descriptor_heap
135135 assert (framedesc.descriptorOffset + program.pushDescriptorCount <= framedesc.descriptorOffsetEnd );
136136
137+ uint32_t descriptorOffset = framedesc.descriptorOffset ;
138+ VkPushDataInfoEXT pushDataInfo = { VK_STRUCTURE_TYPE_PUSH_DATA_INFO_EXT };
139+ pushDataInfo.offset = program.pushConstantSize ;
140+ pushDataInfo.data .address = &descriptorOffset;
141+ pushDataInfo.data .size = sizeof (descriptorOffset);
142+
143+ vkCmdPushDataEXT (commandBuffer, &pushDataInfo);
144+
137145 for (int i = 0 ; i < 32 ; ++i)
138146 if (program.resourceMask & (1 << i))
139147 {
140148 const DescriptorInfo& info = descriptors[i];
141149
142- assert (program.resourceTypes [i] == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE || program.resourceTypes [i] == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
143- assert (info.resource );
144-
145- const Image* image = static_cast <const Image*>(info.resource );
146150 char descriptor[128 ];
147- getDescriptor (framedesc.device , image->image , image->format , 0 , VK_REMAINING_MIP_LEVELS, program.resourceTypes [i], descriptor, framedesc.descriptorSize );
148151
149- memcpy (static_cast <char *>(framedesc.descriptorHeap ) + (framedesc.descriptorOffset + i) * framedesc.descriptorSize , descriptor, framedesc.descriptorSize );
150- }
152+ switch (program.resourceTypes [i])
153+ {
154+ case VK_DESCRIPTOR_TYPE_SAMPLER:
155+ {
156+ // mapped via constant offsets... sloppily
157+ continue ;
158+ }
159+ case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
160+ case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
161+ {
162+ const Image* image = static_cast <const Image*>(info.resource );
163+ assert (image);
164+ getDescriptor (framedesc.device , image->image , image->format , 0 , VK_REMAINING_MIP_LEVELS, program.resourceTypes [i], descriptor, framedesc.descriptorSize );
165+ break ;
166+ }
151167
152- uint32_t descriptorOffset = framedesc.descriptorOffset ;
153- VkPushDataInfoEXT pushDataInfo = { VK_STRUCTURE_TYPE_PUSH_DATA_INFO_EXT };
154- pushDataInfo.offset = program.pushConstantSize ;
155- pushDataInfo.data .address = &descriptorOffset;
156- pushDataInfo.data .size = sizeof (descriptorOffset);
168+ case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
169+ case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
170+ {
171+ const Buffer* buffer = static_cast <const Buffer*>(info.resource );
172+ assert (buffer);
173+ getDescriptor (framedesc.device , buffer->address , buffer->size , program.resourceTypes [i], descriptor, framedesc.descriptorSize );
174+ break ;
175+ }
157176
158- vkCmdPushDataEXT (commandBuffer, &pushDataInfo);
177+ case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
178+ {
179+ VkAccelerationStructureDeviceAddressInfoKHR addressInfo = { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR };
180+ addressInfo.accelerationStructure = info.accelerationStructure ;
181+ VkDeviceAddress address = vkGetAccelerationStructureDeviceAddressKHR (framedesc.device , &addressInfo);
182+ getDescriptor (framedesc.device , address, 0 , program.resourceTypes [i], descriptor, framedesc.descriptorSize );
183+ break ;
184+ }
185+ default :
186+ assert (!" Unsupported descriptor type" );
187+ }
188+
189+ memcpy (static_cast <char *>(framedesc.descriptorHeap ) + (framedesc.descriptorOffset + i) * framedesc.descriptorSize , descriptor, framedesc.descriptorSize );
190+ }
159191
160192 framedesc.descriptorOffset += program.pushDescriptorCount ;
161193#endif
@@ -581,7 +613,7 @@ int main(int argc, const char** argv)
581613 Program shadowblurProgram = {};
582614 if (raytracingSupported)
583615 {
584- shadowProgram = createProgram (device, VK_PIPELINE_BIND_POINT_COMPUTE, { &shaders[" shadow.comp" ] }, sizeof (ShadowData), false , textureSetLayout);
616+ shadowProgram = createProgram (device, VK_PIPELINE_BIND_POINT_COMPUTE, { &shaders[" shadow.comp" ] }, sizeof (ShadowData), 0 , textureSetLayout);
585617 shadowfillProgram = createProgram (device, VK_PIPELINE_BIND_POINT_COMPUTE, { &shaders[" shadowfill.comp" ] }, sizeof (vec4));
586618 shadowblurProgram = createProgram (device, VK_PIPELINE_BIND_POINT_COMPUTE, { &shaders[" shadowblur.comp" ] }, sizeof (vec4));
587619 }
@@ -705,6 +737,12 @@ int main(int argc, const char** argv)
705737
706738 createBuffer (resourceHeap, device, memoryProperties, resourceDescriptorCount * resourceDescriptorSize + descheapProperties.minResourceHeapReservedRange , VK_BUFFER_USAGE_DESCRIPTOR_HEAP_BIT_EXT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
707739 createBuffer (samplerHeap, device, memoryProperties, DESCRIPTOR_LIMIT_SAMPLERS * descheapProperties.samplerDescriptorSize + descheapProperties.minSamplerHeapReservedRange , VK_BUFFER_USAGE_DESCRIPTOR_HEAP_BIT_EXT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
740+
741+ // fill sampler[0] with texture sampler and sampler[1] with depth sampler
742+ getDescriptor (device, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE,
743+ static_cast <char *>(samplerHeap.data ) + 0 * descheapProperties.samplerDescriptorSize , descheapProperties.samplerDescriptorSize );
744+ getDescriptor (device, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_NEAREST, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_REDUCTION_MODE_MIN,
745+ static_cast <char *>(samplerHeap.data ) + 1 * descheapProperties.samplerDescriptorSize , descheapProperties.samplerDescriptorSize );
708746 }
709747#endif
710748
@@ -1470,7 +1508,8 @@ int main(int argc, const char** argv)
14701508 DescriptorInfo descriptors[] = { dcb, db, mlb, mdb, vb, cib, DescriptorInfo (), textureSampler, mtb };
14711509 pushDescriptors (commandBuffer, framedesc, clusterProgram, descriptors);
14721510
1473- vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, clusterProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
1511+ if (!clusterProgram.descriptorSize )
1512+ vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, clusterProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
14741513
14751514 pushConstants (commandBuffer, framedesc, clusterProgram, passGlobals);
14761515 vkCmdDrawMeshTasksIndirectEXT (commandBuffer, ccb.buffer , 4 , 1 , 0 );
@@ -1483,7 +1522,8 @@ int main(int argc, const char** argv)
14831522 DescriptorInfo descriptors[] = { dcb, db, mlb, mdb, vb, mvb, depthPyramid, textureSampler, mtb, depthSampler };
14841523 pushDescriptors (commandBuffer, framedesc, meshtaskProgram, descriptors);
14851524
1486- vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, meshtaskProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
1525+ if (!meshtaskProgram.descriptorSize )
1526+ vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, meshtaskProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
14871527
14881528 pushConstants (commandBuffer, framedesc, meshtaskProgram, passGlobals);
14891529 vkCmdDrawMeshTasksIndirectEXT (commandBuffer, dccb.buffer , 4 , 1 , 0 );
@@ -1495,7 +1535,8 @@ int main(int argc, const char** argv)
14951535 DescriptorInfo descriptors[] = { dcb, db, vb, DescriptorInfo (), DescriptorInfo (), DescriptorInfo (), DescriptorInfo (), textureSampler, mtb };
14961536 pushDescriptors (commandBuffer, framedesc, meshProgram, descriptors);
14971537
1498- vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, meshProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
1538+ if (!meshProgram.descriptorSize )
1539+ vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, meshProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
14991540
15001541 vkCmdBindIndexBuffer (commandBuffer, ib.buffer , 0 , VK_INDEX_TYPE_UINT32);
15011542
@@ -1589,7 +1630,8 @@ int main(int argc, const char** argv)
15891630 {
15901631 vkCmdBindPipeline (commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, shadowQuality == 0 ? shadowlqPipeline : shadowhqPipeline);
15911632
1592- vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, shadowProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
1633+ if (!shadowProgram.descriptorSize )
1634+ vkCmdBindDescriptorSets (commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, shadowProgram.layout , 1 , 1 , &textureSet.second , 0 , nullptr );
15931635
15941636 DescriptorInfo descriptors[] = { shadowTarget, depthTarget, tlas, db, mb, mtb, vb, ib, textureSampler };
15951637
0 commit comments