Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bedrock Updates 041110 #438

Merged
merged 5 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions base/src/graphics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::mthelper::SharedRef;
use bedrock::{self as br, CommandBufferMut, CommandPoolMut, QueueMut};
use br::{Device, Instance, InstanceChild, PhysicalDevice, SubmissionBatch};
use cfg_if::cfg_if;
use log::{info, warn};
use std::{
collections::HashSet,
Expand Down Expand Up @@ -269,10 +268,12 @@ impl Graphics {
batches: &[br::vk::VkSubmitInfo],
fence: &mut impl br::FenceMut,
) -> br::Result<()> {
self.graphics_queue
.q
.get_mut()
.submit_raw(batches, Some(fence.as_transparent_mut_ref()))
unsafe {
self.graphics_queue
.q
.get_mut()
.submit_raw(batches, Some(fence.as_transparent_mut_ref()))
}
}

/// Submits any commands as transient commands.
Expand Down
41 changes: 39 additions & 2 deletions base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ impl<NL: NativeLinker> Engine<NL> {
pub fn back_buffer(
&self,
index: usize,
) -> Option<SharedRef<<NL::Presenter as PlatformPresenter>::BackBuffer>> {
) -> Option<&SharedRef<<NL::Presenter as PlatformPresenter>::BackBuffer>> {
self.presenter.back_buffer(index)
}
pub fn iter_back_buffers<'s>(
&'s self,
) -> impl Iterator<Item = SharedRef<<NL::Presenter as PlatformPresenter>::BackBuffer>> + 's
) -> impl Iterator<Item = &'s SharedRef<<NL::Presenter as PlatformPresenter>::BackBuffer>> + 's
{
(0..self.back_buffer_count())
.map(move |x| self.back_buffer(x).expect("unreachable while iteration"))
Expand Down Expand Up @@ -537,6 +537,43 @@ impl<T> LateInit<T> {
}
}

pub struct Discardable1<T>(Option<T>);
impl<T> Discardable1<T> {
pub const fn new() -> Self {
Self(None)
}

pub fn set(&mut self, v: T) {
self.0 = Some(v);
}

pub fn get<'v>(&'v self) -> &'v T {
self.0.as_ref().expect("value unset")
}

pub fn get_mut<'v>(&'v mut self) -> &'v mut T {
self.0.as_mut().expect("value unset")
}

pub fn discard(&mut self) {
self.0 = None;
}

pub fn take(&mut self) -> Option<T> {
self.0.take()
}

pub const fn is_available(&self) -> bool {
self.0.is_some()
}
}
impl<T> From<T> for Discardable1<T> {
#[inline(always)]
fn from(value: T) -> Self {
Self(Some(value))
}
}

pub struct Discardable<T>(DynamicMut<Option<T>>);
impl<T> Discardable<T> {
pub fn new() -> Self {
Expand Down
6 changes: 3 additions & 3 deletions base/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait ModelData {
fn prealloc(&self, alloc: &mut BufferPrealloc) -> Self::PreallocOffsetType;
fn stage_data_into(
&self,
mem: &br::MappedMemoryRange<impl br::DeviceMemory + br::VkHandleMut + ?Sized>,
mem: &br::MappedMemoryRange<impl br::DeviceMemoryMut + ?Sized>,
offsets: Self::PreallocOffsetType,
) -> Self::RendererParams;
}
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<VT: Clone> ModelData for Primitive<VT> {
}
fn stage_data_into(
&self,
mem: &br::MappedMemoryRange<impl br::DeviceMemory + br::VkHandleMut + ?Sized>,
mem: &br::MappedMemoryRange<impl br::DeviceMemoryMut + ?Sized>,
vo: u64,
) {
unsafe {
Expand All @@ -70,7 +70,7 @@ impl<VT: Clone> ModelData for IndexedPrimitive<VT> {
}
fn stage_data_into(
&self,
mem: &br::MappedMemoryRange<impl br::DeviceMemory + br::VkHandleMut + ?Sized>,
mem: &br::MappedMemoryRange<impl br::DeviceMemoryMut + ?Sized>,
(vo, io): (u64, u64),
) {
unsafe {
Expand Down
42 changes: 16 additions & 26 deletions base/src/presenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait PlatformPresenter {

fn format(&self) -> br::vk::VkFormat;
fn back_buffer_count(&self) -> usize;
fn back_buffer(&self, index: usize) -> Option<SharedRef<Self::BackBuffer>>;
fn back_buffer(&self, index: usize) -> Option<&SharedRef<Self::BackBuffer>>;

fn emit_initialize_back_buffer_commands<'r, CB: br::CommandBufferMut + ?Sized>(
&self,
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<Surface: br::Surface> IntegratedSwapchainObject<DeviceObject, Surface> {
/// WSI Swapchain implementation for PlatformPresenter
pub struct IntegratedSwapchain<Surface: br::Surface> {
surface_info: crate::SurfaceInfo,
swapchain: crate::Discardable<IntegratedSwapchainObject<DeviceObject, Surface>>,
swapchain: crate::Discardable1<IntegratedSwapchainObject<DeviceObject, Surface>>,
rendering_order: br::SemaphoreObject<DeviceObject>,
buffer_ready_order: br::SemaphoreObject<DeviceObject>,
present_order: br::SemaphoreObject<DeviceObject>,
Expand All @@ -163,30 +163,20 @@ impl<Surface: br::Surface> IntegratedSwapchain<Surface> {
#[cfg(feature = "debug")]
{
rendering_order
.set_name(Some(unsafe {
std::ffi::CStr::from_bytes_with_nul_unchecked(
b"Peridot-Default Presenter-Rendering Order Semaphore\0",
)
}))
.set_name(Some(c"Peridot-Default Presenter-Rendering Order Semaphore"))
.expect("Failed to set Rendering Order Semaphore name");
buffer_ready_order
.set_name(Some(unsafe {
std::ffi::CStr::from_bytes_with_nul_unchecked(
b"Peridot-Default Presenter-BufferReady Order Semaphore\0",
)
}))
.set_name(Some(
c"Peridot-Default Presenter-BufferReady Order Semaphore",
))
.expect("Failed to set BufferReady Order Semaphore name");
present_order
.set_name(Some(unsafe {
std::ffi::CStr::from_bytes_with_nul_unchecked(
b"Peridot-Default Presenter-Present Order Semaphore\0",
)
}))
.set_name(Some(c"Peridot-Default Presenter-Present Order Semaphore"))
.expect("Failed to set Present Order Semaphore name");
}

Self {
swapchain: crate::Discardable::from(IntegratedSwapchainObject::new(
swapchain: crate::Discardable1::from(IntegratedSwapchainObject::new(
g,
surface,
&surface_info,
Expand All @@ -210,15 +200,15 @@ impl<Surface: br::Surface> IntegratedSwapchain<Surface> {
}

#[inline]
pub fn back_buffer(
&self,
pub fn back_buffer<'s>(
&'s self,
index: usize,
) -> Option<
SharedRef<
&'s SharedRef<
br::ImageViewObject<br::SwapchainImage<SharedSwapchainObject<DeviceObject, Surface>>>,
>,
> {
self.swapchain.get().back_buffer_images.get(index).cloned()
self.swapchain.get().back_buffer_images.get(index)
}

pub fn emit_initialize_back_buffer_commands<
Expand Down Expand Up @@ -252,7 +242,7 @@ impl<Surface: br::Surface> IntegratedSwapchain<Surface> {

#[inline]
pub fn acquire_next_back_buffer_index(&mut self) -> br::Result<u32> {
self.swapchain.get_mut_lw().swapchain.acquire_next(
self.swapchain.get_mut().swapchain.acquire_next(
None,
br::CompletionHandlerMut::Queue(self.rendering_order.as_transparent_mut_ref()),
)
Expand Down Expand Up @@ -316,15 +306,15 @@ impl<Surface: br::Surface> IntegratedSwapchain<Surface> {
g.submit_buffered_commands(&[render_submission], last_render_fence)?;
}

self.swapchain.get_mut_lw().swapchain.queue_present(
self.swapchain.get_mut().swapchain.queue_present(
g.graphics_queue.q.get_mut(),
bb_index,
&[self.present_order.as_transparent_ref()],
)
}

pub fn resize(&mut self, g: &crate::Graphics, new_size: peridot_math::Vector2<u32>) {
if let Some(mut old) = self.swapchain.take_lw() {
if let Some(mut old) = self.swapchain.take() {
old.back_buffer_images.clear();
let (_, s) = SharedRef::try_unwrap(old.swapchain)
.unwrap_or_else(|refs| {
Expand All @@ -335,7 +325,7 @@ impl<Surface: br::Surface> IntegratedSwapchain<Surface> {
)
})
.deconstruct();
self.swapchain.set_lw(IntegratedSwapchainObject::new(
self.swapchain.set(IntegratedSwapchainObject::new(
g,
s,
&self.surface_info,
Expand Down
10 changes: 2 additions & 8 deletions base/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ impl TexturePreallocatedGroup<br::ImageObject<DeviceObject>> {
}
impl<Device: br::Device + 'static> TextureInstantiatedGroup<Device> {
/// Copy texture pixels into a staging buffer.
pub fn stage_data(
&self,
mr: &br::MappedMemoryRange<impl br::DeviceMemory + br::VkHandleMut + ?Sized>,
) {
pub fn stage_data(&self, mr: &br::MappedMemoryRange<impl br::DeviceMemoryMut + ?Sized>) {
trace!("Staging Texture Data...");
for &(ref pd, offs) in &self.0 {
let s = unsafe {
Expand Down Expand Up @@ -626,10 +623,7 @@ impl<Object> BufferWithLength<Object> {
/// Describing the type that can be used as initializer of `FixedBuffer`s
pub trait FixedBufferInitializer {
/// Setup memory data in staging buffer
fn stage_data(
&mut self,
m: &br::MappedMemoryRange<impl br::DeviceMemory + br::VkHandleMut + ?Sized>,
);
fn stage_data(&mut self, m: &br::MappedMemoryRange<impl br::DeviceMemoryMut + ?Sized>);
fn buffer_graphics_ready<Device: br::Device + 'static>(
&self,
tfb: &mut TransferBatch,
Expand Down
5 changes: 4 additions & 1 deletion base/src/resource/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ impl<
&mut self,
range: std::ops::Range<u64>,
f: impl FnOnce(&br::MappedMemoryRange<Memory>) -> R,
) -> br::Result<R> {
) -> br::Result<R>
where
Memory: br::DeviceMemoryMut,
{
let mut mem = self.1.borrow_mut();
let mapped_range = AutocloseMappedMemoryRange(
mem.map((self.2 + range.start) as _..(self.2 + range.end) as _)?
Expand Down
11 changes: 5 additions & 6 deletions base/src/resource/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,10 @@ where
}

#[repr(transparent)]
pub struct AutocloseMappedMemoryRange<
'm,
DeviceMemory: br::DeviceMemory + br::VkHandleMut + ?Sized + 'm,
>(pub(super) Option<br::MappedMemoryRange<'m, DeviceMemory>>);
impl<'m, DeviceMemory: br::DeviceMemory + br::VkHandleMut + ?Sized + 'm> std::ops::Deref
pub struct AutocloseMappedMemoryRange<'m, DeviceMemory: br::DeviceMemoryMut + ?Sized + 'm>(
pub(super) Option<br::MappedMemoryRange<'m, DeviceMemory>>,
);
impl<'m, DeviceMemory: br::DeviceMemoryMut + ?Sized + 'm> std::ops::Deref
for AutocloseMappedMemoryRange<'m, DeviceMemory>
{
type Target = br::MappedMemoryRange<'m, DeviceMemory>;
Expand All @@ -190,7 +189,7 @@ impl<'m, DeviceMemory: br::DeviceMemory + br::VkHandleMut + ?Sized + 'm> std::op
self.0.as_ref().expect("object has been dropped")
}
}
impl<'m, DeviceMemory: br::DeviceMemory + br::VkHandleMut + ?Sized + 'm> Drop
impl<'m, DeviceMemory: br::DeviceMemoryMut + ?Sized + 'm> Drop
for AutocloseMappedMemoryRange<'m, DeviceMemory>
{
fn drop(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion cradle/android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl peridot::PlatformPresenter for Presenter {
fn back_buffer_count(&self) -> usize {
self.sc.back_buffer_count()
}
fn back_buffer(&self, index: usize) -> Option<SharedRef<Self::BackBuffer>> {
fn back_buffer(&self, index: usize) -> Option<&SharedRef<Self::BackBuffer>> {
self.sc.back_buffer(index)
}

Expand Down
3 changes: 3 additions & 0 deletions cradle/linux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl GameDriver {
PP: PointerPositionProvider + Send + Sync + 'static,
Arc<RwLock<PP>>: PresenterProvider,
<Arc<RwLock<PP>> as PresenterProvider>::Presenter: Sync + Send,
<<Arc<RwLock<PP>> as PresenterProvider>::Presenter as peridot::PlatformPresenter>::BackBuffer: Sync + Send
{
let (event_sender, event_receiver) = async_std::channel::unbounded();
let (frame_timing_sender, frame_timing_receiver) = async_std::channel::bounded(1);
Expand Down Expand Up @@ -188,6 +189,8 @@ where
W: WindowBackend + EventProcessor + PointerPositionProvider + Send + Sync + 'static,
Arc<RwLock<W>>: PresenterProvider,
<Arc<RwLock<W>> as PresenterProvider>::Presenter: Sync + Send,
<<Arc<RwLock<W>> as PresenterProvider>::Presenter as peridot::PlatformPresenter>::BackBuffer:
Sync + Send,
{
let gd = GameDriver::new(window_backend.clone());

Expand Down
2 changes: 1 addition & 1 deletion cradle/linux/src/presenter/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl peridot::PlatformPresenter for Presenter {
fn back_buffer_count(&self) -> usize {
self.sc.back_buffer_count()
}
fn back_buffer(&self, index: usize) -> Option<peridot::mthelper::SharedRef<Self::BackBuffer>> {
fn back_buffer(&self, index: usize) -> Option<&peridot::mthelper::SharedRef<Self::BackBuffer>> {
self.sc.back_buffer(index)
}
fn requesting_back_buffer_layout(&self) -> (br::ImageLayout, br::PipelineStageFlags) {
Expand Down
2 changes: 1 addition & 1 deletion cradle/linux/src/presenter/xcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl peridot::PlatformPresenter for Presenter {
fn back_buffer_count(&self) -> usize {
self.sc.back_buffer_count()
}
fn back_buffer(&self, index: usize) -> Option<peridot::mthelper::SharedRef<Self::BackBuffer>> {
fn back_buffer(&self, index: usize) -> Option<&peridot::mthelper::SharedRef<Self::BackBuffer>> {
self.sc.back_buffer(index)
}
fn requesting_back_buffer_layout(&self) -> (br::ImageLayout, br::PipelineStageFlags) {
Expand Down
2 changes: 1 addition & 1 deletion cradle/mac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl peridot::PlatformPresenter for Presenter {
fn back_buffer_count(&self) -> usize {
self.sc.back_buffer_count()
}
fn back_buffer(&self, index: usize) -> Option<SharedRef<Self::BackBuffer>> {
fn back_buffer(&self, index: usize) -> Option<&SharedRef<Self::BackBuffer>> {
self.sc.back_buffer(index)
}
fn requesting_back_buffer_layout(&self) -> (br::ImageLayout, br::PipelineStageFlags) {
Expand Down
6 changes: 3 additions & 3 deletions cradle/windows/src/presenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl peridot::PlatformPresenter for Presenter {
fn back_buffer_count(&self) -> usize {
self.sc.back_buffer_count()
}
fn back_buffer(&self, index: usize) -> Option<SharedRef<Self::BackBuffer>> {
fn back_buffer(&self, index: usize) -> Option<&SharedRef<Self::BackBuffer>> {
self.sc.back_buffer(index)
}

Expand Down Expand Up @@ -509,8 +509,8 @@ impl peridot::PlatformPresenter for Presenter {
fn back_buffer_count(&self) -> usize {
2
}
fn back_buffer(&self, index: usize) -> Option<SharedRef<Self::BackBuffer>> {
self.back_buffers.get(index).map(|b| b.image_view.clone())
fn back_buffer(&self, index: usize) -> Option<&SharedRef<Self::BackBuffer>> {
self.back_buffers.get(index).map(|b| &b.image_view)
}

fn emit_initialize_back_buffer_commands<
Expand Down
Loading
Loading