MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Tools / prepare_depth

Method prepare_depth

cube/cube.cpp:2452–2497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2450}
2451
2452void Demo::prepare_depth() {
2453 depth.format = vk::Format::eD16Unorm;
2454
2455 auto const image = vk::ImageCreateInfo()
2456 .setImageType(vk::ImageType::e2D)
2457 .setFormat(depth.format)
2458 .setExtent({width, height, 1})
2459 .setMipLevels(1)
2460 .setArrayLayers(1)
2461 .setSamples(vk::SampleCountFlagBits::e1)
2462 .setTiling(vk::ImageTiling::eOptimal)
2463 .setUsage(vk::ImageUsageFlagBits::eDepthStencilAttachment)
2464 .setSharingMode(vk::SharingMode::eExclusive)
2465 .setInitialLayout(vk::ImageLayout::eUndefined);
2466
2467 auto result = device.createImage(&image, nullptr, &depth.image);
2468 VERIFY(result == vk::Result::eSuccess);
2469
2470 vk::MemoryRequirements mem_reqs;
2471 device.getImageMemoryRequirements(depth.image, &mem_reqs);
2472
2473 depth.mem_alloc.setAllocationSize(mem_reqs.size);
2474 depth.mem_alloc.setMemoryTypeIndex(0);
2475
2476 auto const pass = memory_type_from_properties(mem_reqs.memoryTypeBits, vk::MemoryPropertyFlagBits::eDeviceLocal,
2477 depth.mem_alloc.memoryTypeIndex);
2478 VERIFY(pass);
2479
2480 result = device.allocateMemory(&depth.mem_alloc, nullptr, &depth.mem);
2481 VERIFY(result == vk::Result::eSuccess);
2482
2483 result = device.bindImageMemory(depth.image, depth.mem, 0);
2484 VERIFY(result == vk::Result::eSuccess);
2485
2486 auto view = vk::ImageViewCreateInfo()
2487 .setImage(depth.image)
2488 .setViewType(vk::ImageViewType::e2D)
2489 .setFormat(depth.format)
2490 .setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1));
2491 if (force_errors) {
2492 // Intentionally force a bad pNext value to generate a validation layer error
2493 view.pNext = ℑ
2494 }
2495 result = device.createImageView(&view, nullptr, &depth.view);
2496 VERIFY(result == vk::Result::eSuccess);
2497}
2498
2499void Demo::prepare_descriptor_layout() {
2500 std::array<vk::DescriptorSetLayoutBinding, 2> const layout_bindings = {

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected