forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvklayertests_ray_tracing_gpu.cpp
543 lines (446 loc) · 25.1 KB
/
vklayertests_ray_tracing_gpu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/*
* Copyright (c) 2020-2022 The Khronos Group Inc.
* Copyright (c) 2020-2022 Valve Corporation
* Copyright (c) 2020-2022 LunarG, Inc.
* Copyright (c) 2020-2022 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Author: Mark Lobodzinski <mark@lunarg.com>
* Author: Tony Barbour <tony@LunarG.com>
*/
#include "layer_validation_tests.h"
TEST_F(VkGpuAssistedLayerTest, RayTracingGpuValidationArrayOOBRayTracingShaders) {
TEST_DESCRIPTION(
"GPU validation: Verify detection of out-of-bounds descriptor array indexing and use of uninitialized descriptors for "
"ray tracing shaders using gpu assited validation.");
OOBRayTracingShadersTestBody(true);
}
TEST_F(VkGpuAssistedLayerTest, NVRayTracingGpuBuildAccelerationStructureValidationInvalidHandle) {
TEST_DESCRIPTION(
"Acceleration structure gpu validation should report an invalid handle when trying to build a top level "
"acceleration structure with an invalid handle for a bottom level acceleration structure.");
SetTargetApiVersion(VK_API_VERSION_1_1);
VkValidationFeaturesEXT validation_features = GetValidationFeatures();
if (!InitFrameworkForRayTracingTest(this, false, nullptr, &validation_features)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
if (!CanEnableGpuAV()) {
GTEST_SKIP() << "Requirements for GPU-AV are not met";
}
ASSERT_NO_FATAL_FAILURE(InitState());
const auto vkCmdBuildAccelerationStructureNV =
GetDeviceProcAddr<PFN_vkCmdBuildAccelerationStructureNV>("vkCmdBuildAccelerationStructureNV");
VkBufferObj vbo;
VkBufferObj ibo;
VkGeometryNV geometry;
GetSimpleGeometryForAccelerationStructureTests(*m_device, &vbo, &ibo, &geometry);
VkAccelerationStructureCreateInfoNV top_level_as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoNV>();
top_level_as_create_info.info = LvlInitStruct<VkAccelerationStructureInfoNV>();
top_level_as_create_info.info.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV;
top_level_as_create_info.info.instanceCount = 1;
top_level_as_create_info.info.geometryCount = 0;
VkCommandPoolObj command_pool(m_device, 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
struct VkGeometryInstanceNV {
float transform[12];
uint32_t instanceCustomIndex : 24;
uint32_t mask : 8;
uint32_t instanceOffset : 24;
uint32_t flags : 8;
uint64_t accelerationStructureHandle;
};
VkGeometryInstanceNV instance = {
{
// clang-format off
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
// clang-format on
},
0,
0xFF,
0,
VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV,
1234567890, // invalid
};
VkDeviceSize instance_buffer_size = sizeof(VkGeometryInstanceNV);
VkBufferObj instance_buffer;
instance_buffer.init(*m_device, instance_buffer_size,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_RAY_TRACING_BIT_NV);
uint8_t *mapped_instance_buffer_data = (uint8_t *)instance_buffer.memory().map();
std::memcpy(mapped_instance_buffer_data, (uint8_t *)&instance, static_cast<std::size_t>(instance_buffer_size));
instance_buffer.memory().unmap();
VkAccelerationStructureObj top_level_as(*m_device, top_level_as_create_info);
const VkBufferObj top_level_as_scratch = top_level_as.create_scratch_buffer(*m_device);
VkCommandBufferObj command_buffer(m_device, &command_pool);
command_buffer.begin();
vkCmdBuildAccelerationStructureNV(command_buffer.handle(), &top_level_as_create_info.info, instance_buffer.handle(), 0,
VK_FALSE, top_level_as.handle(), VK_NULL_HANDLE, top_level_as_scratch.handle(), 0);
command_buffer.end();
m_errorMonitor->SetDesiredFailureMsg(
kErrorBit, "Attempted to build top level acceleration structure using invalid bottom level acceleration structure handle");
VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &command_buffer.handle();
vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(m_device->m_queue);
m_errorMonitor->VerifyFound();
}
TEST_F(VkGpuAssistedLayerTest, NVRayTracingGpuBuildAccelerationStructureValidationBottomLevelNotYetBuilt) {
TEST_DESCRIPTION(
"Acceleration structure gpu validation should report an invalid handle when trying to build a top level "
"acceleration structure with a handle for a bottom level acceleration structure that has not yet been built.");
SetTargetApiVersion(VK_API_VERSION_1_1);
VkValidationFeaturesEXT validation_features = GetValidationFeatures();
if (!InitFrameworkForRayTracingTest(this, false, nullptr, &validation_features)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
if (!CanEnableGpuAV()) {
GTEST_SKIP() << "Requirements for GPU-AV are not met";
}
ASSERT_NO_FATAL_FAILURE(InitState());
const auto vkCmdBuildAccelerationStructureNV =
GetDeviceProcAddr<PFN_vkCmdBuildAccelerationStructureNV>("vkCmdBuildAccelerationStructureNV");
VkBufferObj vbo;
VkBufferObj ibo;
VkGeometryNV geometry;
GetSimpleGeometryForAccelerationStructureTests(*m_device, &vbo, &ibo, &geometry);
VkAccelerationStructureCreateInfoNV bot_level_as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoNV>();
bot_level_as_create_info.info = LvlInitStruct<VkAccelerationStructureInfoNV>();
bot_level_as_create_info.info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV;
bot_level_as_create_info.info.instanceCount = 0;
bot_level_as_create_info.info.geometryCount = 1;
bot_level_as_create_info.info.pGeometries = &geometry;
VkAccelerationStructureCreateInfoNV top_level_as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoNV>();
top_level_as_create_info.info = LvlInitStruct<VkAccelerationStructureInfoNV>();
top_level_as_create_info.info.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV;
top_level_as_create_info.info.instanceCount = 1;
top_level_as_create_info.info.geometryCount = 0;
VkCommandPoolObj command_pool(m_device, 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
struct VkGeometryInstanceNV {
float transform[12];
uint32_t instanceCustomIndex : 24;
uint32_t mask : 8;
uint32_t instanceOffset : 24;
uint32_t flags : 8;
uint64_t accelerationStructureHandle;
};
VkAccelerationStructureObj bot_level_as_never_built(*m_device, bot_level_as_create_info);
VkGeometryInstanceNV instance = {
{
// clang-format off
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
// clang-format on
},
0,
0xFF,
0,
VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV,
bot_level_as_never_built.opaque_handle(),
};
VkDeviceSize instance_buffer_size = sizeof(VkGeometryInstanceNV);
VkBufferObj instance_buffer;
instance_buffer.init(*m_device, instance_buffer_size,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_RAY_TRACING_BIT_NV);
uint8_t *mapped_instance_buffer_data = (uint8_t *)instance_buffer.memory().map();
std::memcpy(mapped_instance_buffer_data, (uint8_t *)&instance, static_cast<std::size_t>(instance_buffer_size));
instance_buffer.memory().unmap();
VkAccelerationStructureObj top_level_as(*m_device, top_level_as_create_info);
const VkBufferObj top_level_as_scratch = top_level_as.create_scratch_buffer(*m_device);
VkCommandBufferObj command_buffer(m_device, &command_pool);
command_buffer.begin();
vkCmdBuildAccelerationStructureNV(command_buffer.handle(), &top_level_as_create_info.info, instance_buffer.handle(), 0,
VK_FALSE, top_level_as.handle(), VK_NULL_HANDLE, top_level_as_scratch.handle(), 0);
command_buffer.end();
m_errorMonitor->SetDesiredFailureMsg(
kErrorBit, "Attempted to build top level acceleration structure using invalid bottom level acceleration structure handle");
VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &command_buffer.handle();
vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(m_device->m_queue);
m_errorMonitor->VerifyFound();
}
TEST_F(VkGpuAssistedLayerTest, NVRayTracingGpuBuildAccelerationStructureValidationBottomLevelDestroyed) {
TEST_DESCRIPTION(
"Acceleration structure gpu validation should report an invalid handle when trying to build a top level "
"acceleration structure with a handle for a destroyed bottom level acceleration structure.");
SetTargetApiVersion(VK_API_VERSION_1_1);
VkValidationFeaturesEXT validation_features = GetValidationFeatures();
if (!InitFrameworkForRayTracingTest(this, false, nullptr, &validation_features)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
if (!CanEnableGpuAV()) {
GTEST_SKIP() << "Requirements for GPU-AV are not met";
}
ASSERT_NO_FATAL_FAILURE(InitState());
const auto vkCmdBuildAccelerationStructureNV =
GetDeviceProcAddr<PFN_vkCmdBuildAccelerationStructureNV>("vkCmdBuildAccelerationStructureNV");
VkBufferObj vbo;
VkBufferObj ibo;
VkGeometryNV geometry;
GetSimpleGeometryForAccelerationStructureTests(*m_device, &vbo, &ibo, &geometry);
VkAccelerationStructureCreateInfoNV bot_level_as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoNV>();
bot_level_as_create_info.info = LvlInitStruct<VkAccelerationStructureInfoNV>();
bot_level_as_create_info.info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV;
bot_level_as_create_info.info.instanceCount = 0;
bot_level_as_create_info.info.geometryCount = 1;
bot_level_as_create_info.info.pGeometries = &geometry;
VkAccelerationStructureCreateInfoNV top_level_as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoNV>();
top_level_as_create_info.info = LvlInitStruct<VkAccelerationStructureInfoNV>();
top_level_as_create_info.info.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV;
top_level_as_create_info.info.instanceCount = 1;
top_level_as_create_info.info.geometryCount = 0;
VkCommandPoolObj command_pool(m_device, 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
struct VkGeometryInstanceNV {
float transform[12];
uint32_t instanceCustomIndex : 24;
uint32_t mask : 8;
uint32_t instanceOffset : 24;
uint32_t flags : 8;
uint64_t accelerationStructureHandle;
};
uint64_t destroyed_bot_level_as_handle = 0;
{
VkAccelerationStructureObj destroyed_bot_level_as(*m_device, bot_level_as_create_info);
destroyed_bot_level_as_handle = destroyed_bot_level_as.opaque_handle();
const VkBufferObj bot_level_as_scratch = destroyed_bot_level_as.create_scratch_buffer(*m_device);
VkCommandBufferObj command_buffer(m_device, &command_pool);
command_buffer.begin();
vkCmdBuildAccelerationStructureNV(command_buffer.handle(), &bot_level_as_create_info.info, VK_NULL_HANDLE, 0, VK_FALSE,
destroyed_bot_level_as.handle(), VK_NULL_HANDLE, bot_level_as_scratch.handle(), 0);
command_buffer.end();
VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &command_buffer.handle();
vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(m_device->m_queue);
// vk::DestroyAccelerationStructureNV called on destroyed_bot_level_as during destruction.
}
VkGeometryInstanceNV instance = {
{
// clang-format off
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
// clang-format on
},
0,
0xFF,
0,
VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV,
destroyed_bot_level_as_handle,
};
VkDeviceSize instance_buffer_size = sizeof(VkGeometryInstanceNV);
VkBufferObj instance_buffer;
instance_buffer.init(*m_device, instance_buffer_size,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_RAY_TRACING_BIT_NV);
uint8_t *mapped_instance_buffer_data = (uint8_t *)instance_buffer.memory().map();
std::memcpy(mapped_instance_buffer_data, (uint8_t *)&instance, static_cast<std::size_t>(instance_buffer_size));
instance_buffer.memory().unmap();
VkAccelerationStructureObj top_level_as(*m_device, top_level_as_create_info);
const VkBufferObj top_level_as_scratch = top_level_as.create_scratch_buffer(*m_device);
VkCommandBufferObj command_buffer(m_device, &command_pool);
command_buffer.begin();
vkCmdBuildAccelerationStructureNV(command_buffer.handle(), &top_level_as_create_info.info, instance_buffer.handle(), 0,
VK_FALSE, top_level_as.handle(), VK_NULL_HANDLE, top_level_as_scratch.handle(), 0);
command_buffer.end();
m_errorMonitor->SetDesiredFailureMsg(
kErrorBit, "Attempted to build top level acceleration structure using invalid bottom level acceleration structure handle");
VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &command_buffer.handle();
vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(m_device->m_queue);
m_errorMonitor->VerifyFound();
}
TEST_F(VkGpuAssistedLayerTest, NVRayTracingGpuBuildAccelerationStructureValidationRestoresState) {
TEST_DESCRIPTION("Validate that acceleration structure gpu validation correctly restores compute state.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
VkValidationFeaturesEXT validation_features = GetValidationFeatures();
if (!InitFrameworkForRayTracingTest(this, false, nullptr, &validation_features)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
if (!CanEnableGpuAV()) {
GTEST_SKIP() << "Requirements for GPU-AV are not met";
}
ASSERT_NO_FATAL_FAILURE(InitState());
const auto vkCmdBuildAccelerationStructureNV =
GetDeviceProcAddr<PFN_vkCmdBuildAccelerationStructureNV>("vkCmdBuildAccelerationStructureNV");
const auto vkCmdPushDescriptorSetKHR = GetDeviceProcAddr<PFN_vkCmdPushDescriptorSetKHR>("vkCmdPushDescriptorSetKHR");
VkBufferObj vbo;
VkBufferObj ibo;
VkGeometryNV geometry;
GetSimpleGeometryForAccelerationStructureTests(*m_device, &vbo, &ibo, &geometry);
VkAccelerationStructureCreateInfoNV top_level_as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoNV>();
top_level_as_create_info.info = LvlInitStruct<VkAccelerationStructureInfoNV>();
top_level_as_create_info.info.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV;
top_level_as_create_info.info.instanceCount = 1;
top_level_as_create_info.info.geometryCount = 0;
VkCommandPoolObj command_pool(m_device, 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
struct VkGeometryInstanceNV {
float transform[12];
uint32_t instanceCustomIndex : 24;
uint32_t mask : 8;
uint32_t instanceOffset : 24;
uint32_t flags : 8;
uint64_t accelerationStructureHandle;
};
VkGeometryInstanceNV instance = {
{
// clang-format off
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
// clang-format on
},
0,
0xFF,
0,
VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV,
1234567,
};
VkDeviceSize instance_buffer_size = sizeof(VkGeometryInstanceNV);
VkBufferObj instance_buffer;
instance_buffer.init(*m_device, instance_buffer_size,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_RAY_TRACING_BIT_NV);
uint8_t *mapped_instance_buffer_data = (uint8_t *)instance_buffer.memory().map();
std::memcpy(mapped_instance_buffer_data, (uint8_t *)&instance, static_cast<std::size_t>(instance_buffer_size));
instance_buffer.memory().unmap();
VkAccelerationStructureObj top_level_as(*m_device, top_level_as_create_info);
const VkBufferObj top_level_as_scratch = top_level_as.create_scratch_buffer(*m_device);
struct ComputeOutput {
uint32_t push_constant_value;
uint32_t push_descriptor_value;
uint32_t normal_descriptor_value;
};
VkBufferObj push_descriptor_buffer;
push_descriptor_buffer.init(*m_device, 4, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
VkBufferObj normal_descriptor_buffer;
normal_descriptor_buffer.init(*m_device, 4, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
VkDeviceSize output_descriptor_buffer_size = static_cast<VkDeviceSize>(sizeof(ComputeOutput));
VkBufferObj output_descriptor_buffer;
output_descriptor_buffer.init(*m_device, output_descriptor_buffer_size,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
const char *cs_source = R"glsl(
#version 450
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(push_constant) uniform PushConstants { uint value; } push_constant;
layout(set = 0, binding = 0, std430) buffer PushDescriptorBuffer { uint value; } push_descriptor;
layout(set = 1, binding = 0, std430) buffer NormalDescriptorBuffer { uint value; } normal_descriptor;
layout(set = 2, binding = 0, std430) buffer ComputeOutputBuffer {
uint push_constant_value;
uint push_descriptor_value;
uint normal_descriptor_value;
} compute_output;
void main() {
compute_output.push_constant_value = push_constant.value;
compute_output.push_descriptor_value = push_descriptor.value;
compute_output.normal_descriptor_value = normal_descriptor.value;
}
)glsl";
VkShaderObj cs(this, cs_source, VK_SHADER_STAGE_COMPUTE_BIT);
OneOffDescriptorSet push_descriptor_set(m_device,
{
{0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
},
VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR);
OneOffDescriptorSet normal_descriptor_set(m_device,
{
{0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
});
OneOffDescriptorSet output_descriptor_set(m_device,
{
{0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
});
VkPushConstantRange push_constant_range = {};
push_constant_range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
push_constant_range.size = 4;
push_constant_range.offset = 0;
const VkPipelineLayoutObj compute_pipeline_layout(m_device,
{
&push_descriptor_set.layout_,
&normal_descriptor_set.layout_,
&output_descriptor_set.layout_,
},
{push_constant_range});
VkComputePipelineCreateInfo compute_pipeline_ci = LvlInitStruct<VkComputePipelineCreateInfo>();
compute_pipeline_ci.layout = compute_pipeline_layout.handle();
compute_pipeline_ci.stage = cs.GetStageCreateInfo();
VkPipeline compute_pipeline;
ASSERT_VK_SUCCESS(
vk::CreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &compute_pipeline_ci, nullptr, &compute_pipeline));
normal_descriptor_set.WriteDescriptorBufferInfo(0, normal_descriptor_buffer.handle(), 0, 4, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
normal_descriptor_set.UpdateDescriptorSets();
output_descriptor_set.WriteDescriptorBufferInfo(0, output_descriptor_buffer.handle(), 0, output_descriptor_buffer_size,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
output_descriptor_set.UpdateDescriptorSets();
// Set input data
const uint32_t push_constant_value = 1234567890;
const uint32_t push_descriptor_value = 98765432;
const uint32_t normal_descriptor_value = 1111111;
uint32_t *mapped_push_descriptor_buffer_data = (uint32_t *)push_descriptor_buffer.memory().map();
*mapped_push_descriptor_buffer_data = push_descriptor_value;
push_descriptor_buffer.memory().unmap();
uint32_t *mapped_normal_descriptor_buffer_data = (uint32_t *)normal_descriptor_buffer.memory().map();
*mapped_normal_descriptor_buffer_data = normal_descriptor_value;
normal_descriptor_buffer.memory().unmap();
ComputeOutput *mapped_output_buffer_data = (ComputeOutput *)output_descriptor_buffer.memory().map();
mapped_output_buffer_data->push_constant_value = 0;
mapped_output_buffer_data->push_descriptor_value = 0;
mapped_output_buffer_data->normal_descriptor_value = 0;
output_descriptor_buffer.memory().unmap();
VkDescriptorBufferInfo push_descriptor_buffer_info = {};
push_descriptor_buffer_info.buffer = push_descriptor_buffer.handle();
push_descriptor_buffer_info.offset = 0;
push_descriptor_buffer_info.range = 4;
VkWriteDescriptorSet push_descriptor_set_write = LvlInitStruct<VkWriteDescriptorSet>();
push_descriptor_set_write.descriptorCount = 1;
push_descriptor_set_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
push_descriptor_set_write.dstBinding = 0;
push_descriptor_set_write.pBufferInfo = &push_descriptor_buffer_info;
VkCommandBufferObj command_buffer(m_device, &command_pool);
command_buffer.begin();
vk::CmdBindPipeline(command_buffer.handle(), VK_PIPELINE_BIND_POINT_COMPUTE, compute_pipeline);
vk::CmdPushConstants(command_buffer.handle(), compute_pipeline_layout.handle(), VK_SHADER_STAGE_COMPUTE_BIT, 0, 4,
&push_constant_value);
vkCmdPushDescriptorSetKHR(command_buffer.handle(), VK_PIPELINE_BIND_POINT_COMPUTE, compute_pipeline_layout.handle(), 0, 1,
&push_descriptor_set_write);
vk::CmdBindDescriptorSets(command_buffer.handle(), VK_PIPELINE_BIND_POINT_COMPUTE, compute_pipeline_layout.handle(), 1, 1,
&normal_descriptor_set.set_, 0, nullptr);
vk::CmdBindDescriptorSets(command_buffer.handle(), VK_PIPELINE_BIND_POINT_COMPUTE, compute_pipeline_layout.handle(), 2, 1,
&output_descriptor_set.set_, 0, nullptr);
vkCmdBuildAccelerationStructureNV(command_buffer.handle(), &top_level_as_create_info.info, instance_buffer.handle(), 0,
VK_FALSE, top_level_as.handle(), VK_NULL_HANDLE, top_level_as_scratch.handle(), 0);
vk::CmdDispatch(command_buffer.handle(), 1, 1, 1);
command_buffer.end();
m_errorMonitor->SetDesiredFailureMsg(
kErrorBit, "Attempted to build top level acceleration structure using invalid bottom level acceleration structure handle");
VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &command_buffer.handle();
vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(m_device->m_queue);
m_errorMonitor->VerifyFound();
mapped_output_buffer_data = (ComputeOutput *)output_descriptor_buffer.memory().map();
EXPECT_EQ(mapped_output_buffer_data->push_constant_value, push_constant_value);
EXPECT_EQ(mapped_output_buffer_data->push_descriptor_value, push_descriptor_value);
EXPECT_EQ(mapped_output_buffer_data->normal_descriptor_value, normal_descriptor_value);
output_descriptor_buffer.memory().unmap();
// Clean up
vk::DestroyPipeline(m_device->device(), compute_pipeline, nullptr);
}