Skip to content

Commit d82c005

Browse files
committed
Hold references from init so objects don't go out of bounds and get destroyed.
Fixed a lot of validation errors
1 parent f9e941e commit d82c005

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

examples_tests/56.RayQuery/main.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ class RayQuerySampleApp : public ApplicationBase
141141
core::smart_refctd_ptr<video::IGPUDescriptorSet> descriptorSets0[FBO_COUNT] = {};
142142
core::smart_refctd_ptr<video::IGPUDescriptorSet> descriptorSet2 = nullptr;
143143
core::smart_refctd_ptr<video::IGPUDescriptorSet> uboDescriptorSet1 = nullptr;
144+
145+
core::smart_refctd_ptr<IGPUBuffer> aabbsBuffer = nullptr;
146+
core::smart_refctd_ptr<IGPUAccelerationStructure> gpuBlas = nullptr;
147+
core::smart_refctd_ptr<IGPUAccelerationStructure> gpuTlas = nullptr;
148+
core::smart_refctd_ptr<IGPUBuffer> instancesBuffer = nullptr;
149+
150+
core::smart_refctd_ptr<IGPUBufferView> gpuSequenceBufferView = nullptr;
151+
152+
core::smart_refctd_ptr<video::IGPUSampler> sampler0 = nullptr;
153+
core::smart_refctd_ptr<video::IGPUSampler> sampler1 = nullptr;
154+
155+
core::smart_refctd_ptr<IGPUBuffer> gpuSequenceBuffer = nullptr;
156+
157+
core::smart_refctd_ptr<IGPUBuffer> spheresBuffer = nullptr;
144158

145159
// TODO: Temp Fix because of validation error: VkPhysicalDeviceLimits::nonCoherentAtomSize
146160
struct alignas(64) SBasicViewParametersAligned
@@ -180,7 +194,7 @@ class RayQuerySampleApp : public ApplicationBase
180194

181195
CommonAPI::SFeatureRequest< video::ILogicalDevice::E_FEATURE> optionalDeviceFeatures = {};
182196

183-
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
197+
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT | asset::IImage::EUF_TRANSFER_DST_BIT);
184198
const video::ISurface::SFormat surfaceFormat(asset::EF_B8G8R8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
185199

186200
CommonAPI::InitOutput initOutput;
@@ -310,8 +324,8 @@ class RayQuerySampleApp : public ApplicationBase
310324
spheres[6] = Sphere(core::vector3df(-3.0,0.0,1.0), 0.5, 5u, INVALID_ID_16BIT);
311325
spheres[7] = Sphere(core::vector3df(0.5,1.0,0.5), 0.5, 6u, INVALID_ID_16BIT);
312326
spheres[8] = Sphere(core::vector3df(-1.5,1.5,0.0), 0.3, INVALID_ID_16BIT, 0u);
327+
313328
// Create Spheres Buffer
314-
core::smart_refctd_ptr<IGPUBuffer> spheresBuffer;
315329
uint32_t spheresBufferSize = sizeof(Sphere) * SphereCount;
316330

317331
{
@@ -384,8 +398,6 @@ class RayQuerySampleApp : public ApplicationBase
384398
}
385399
#endif
386400

387-
core::smart_refctd_ptr<IGPUBuffer> aabbsBuffer;
388-
core::smart_refctd_ptr<IGPUAccelerationStructure> gpuBlas;
389401
// Create + Build BLAS
390402
{
391403
// Build BLAS with AABBS
@@ -482,8 +494,6 @@ class RayQuerySampleApp : public ApplicationBase
482494
}
483495
}
484496

485-
core::smart_refctd_ptr<IGPUAccelerationStructure> gpuTlas;
486-
core::smart_refctd_ptr<IGPUBuffer> instancesBuffer;
487497
// Create + Build TLAS
488498
{
489499
// TODO: Temp fix before nonCoherentAtomSize fix
@@ -670,7 +680,6 @@ class RayQuerySampleApp : public ApplicationBase
670680

671681
gpuEnvmapImageView = createGPUImageView("../../media/envmap/envmap_0.exr");
672682

673-
smart_refctd_ptr<IGPUBufferView> gpuSequenceBufferView;
674683
{
675684
const uint32_t MaxDimensions = 3u<<kShaderParameters.MaxDepthLog2;
676685
const uint32_t MaxSamples = 1u<<kShaderParameters.MaxSamplesLog2;
@@ -689,7 +698,6 @@ class RayQuerySampleApp : public ApplicationBase
689698

690699
// TODO: Temp Fix because createFilledDeviceLocalGPUBufferOnDedMem doesn't take in params
691700
// auto gpuSequenceBuffer = utilities->createFilledDeviceLocalGPUBufferOnDedMem(graphicsQueue, sampleSequence->getSize(), sampleSequence->getPointer());
692-
core::smart_refctd_ptr<IGPUBuffer> gpuSequenceBuffer;
693701
{
694702
IGPUBuffer::SCreationParams params = {};
695703
const size_t size = sampleSequence->getSize();
@@ -801,9 +809,9 @@ class RayQuerySampleApp : public ApplicationBase
801809
}
802810

803811
ISampler::SParams samplerParams0 = { ISampler::ETC_CLAMP_TO_EDGE, ISampler::ETC_CLAMP_TO_EDGE, ISampler::ETC_CLAMP_TO_EDGE, ISampler::ETBC_FLOAT_OPAQUE_BLACK, ISampler::ETF_LINEAR, ISampler::ETF_LINEAR, ISampler::ESMM_LINEAR, 0u, false, ECO_ALWAYS };
804-
auto sampler0 = logicalDevice->createGPUSampler(samplerParams0);
812+
sampler0 = logicalDevice->createGPUSampler(samplerParams0);
805813
ISampler::SParams samplerParams1 = { ISampler::ETC_CLAMP_TO_EDGE, ISampler::ETC_CLAMP_TO_EDGE, ISampler::ETC_CLAMP_TO_EDGE, ISampler::ETBC_INT_OPAQUE_BLACK, ISampler::ETF_NEAREST, ISampler::ETF_NEAREST, ISampler::ESMM_NEAREST, 0u, false, ECO_ALWAYS };
806-
auto sampler1 = logicalDevice->createGPUSampler(samplerParams1);
814+
sampler1 = logicalDevice->createGPUSampler(samplerParams1);
807815

808816
descriptorSet2 = logicalDevice->createGPUDescriptorSet(descriptorPool.get(), core::smart_refctd_ptr(gpuDescriptorSetLayout2));
809817
{

0 commit comments

Comments
 (0)