Skip to content

Commit

Permalink
Enable capture replay only if available and in debug build
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyas-taouaou committed Oct 30, 2024
1 parent ebfe411 commit 8bf7c01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
6 changes: 5 additions & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ gpu-allocator = { version = "0.27.0", default-features = false, features = ["vul

[build-dependencies]
shaderc = "0.8.3"
anyhow = "1.0.91"
anyhow = "1.0.91"

[profile.release]
codegen-units = 1
lto = "thin"
22 changes: 16 additions & 6 deletions engine/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::rendering_context::{RenderingContext, IS_DEBUG};
use crate::rendering_context::RenderingContext;
use anyhow::{Context as AnyhowContext, Result};
use ash::vk;
use gpu_allocator::vulkan::{Allocation, AllocationCreateDesc, AllocationScheme, Allocator};
Expand All @@ -25,15 +25,25 @@ pub struct Buffer {
impl Buffer {
pub fn new(allocator: &mut Allocator, attributes: BufferAttributes) -> Result<Self> {
unsafe {
let is_debug = cfg!(debug_assertions);
let is_capture_replay_supported = attributes
.context
.physical_device
.vulkan12_features
.buffer_device_address_capture_replay
== vk::TRUE;

let flags = if is_debug && is_capture_replay_supported {
vk::BufferCreateFlags::DEVICE_ADDRESS_CAPTURE_REPLAY
} else {
vk::BufferCreateFlags::empty()
};

let handle = attributes.context.device.create_buffer(
&vk::BufferCreateInfo::default()
.size(attributes.size)
.usage(attributes.usage)
.flags(if IS_DEBUG {
vk::BufferCreateFlags::DEVICE_ADDRESS_CAPTURE_REPLAY
} else {
vk::BufferCreateFlags::empty()
}),
.flags(flags),
None,
)?;

Expand Down
16 changes: 8 additions & 8 deletions engine/src/rendering_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
- The Vulkan instance is created only with the required extensions for the window system.
- The Vulkan instance is created with the required extensions for the dynamic rendering and buffer device address features.
*/

pub const IS_DEBUG: bool = true;

pub use crate::image::{Image, ImageAttributes, ImageLayoutState};
use anyhow::Result;
use ash::vk;
Expand Down Expand Up @@ -211,6 +208,13 @@ impl RenderingContext {
})
.collect::<Vec<_>>();

let is_debug = cfg!(debug_assertions);

let is_capture_replay_supported = physical_device
.vulkan12_features
.buffer_device_address_capture_replay
== vk::TRUE;

let device = instance.create_device(
physical_device.handle,
&vk::DeviceCreateInfo::default()
Expand All @@ -220,11 +224,7 @@ impl RenderingContext {
&mut vk::PhysicalDeviceVulkan12Features::default()
.buffer_device_address(true)
.buffer_device_address_capture_replay(
IS_DEBUG
&& (physical_device
.vulkan12_features
.buffer_device_address_capture_replay
== vk::TRUE),
is_debug && is_capture_replay_supported,
)
.descriptor_indexing(true)
.scalar_block_layout(true),
Expand Down

0 comments on commit 8bf7c01

Please sign in to comment.