mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
Merge #48
48: Set buffer data r=grovesNL a=kvark Simple and limited implementation, should be sufficient for the first examples. Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
commit
6c202f627c
@ -17,6 +17,7 @@ use hal::{self,
|
||||
Device as _Device,
|
||||
Surface as _Surface,
|
||||
};
|
||||
use log::trace;
|
||||
//use rendy_memory::{allocator, Config, Heaps};
|
||||
use parking_lot::{Mutex};
|
||||
|
||||
@ -1198,3 +1199,68 @@ pub extern "C" fn wgpu_device_create_swap_chain(
|
||||
|
||||
swap_chain_id
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_buffer_set_sub_data(
|
||||
buffer_id: BufferId,
|
||||
start: u32, count: u32, data: *const u8,
|
||||
) {
|
||||
let buffer_guard = HUB.buffers.read();
|
||||
let buffer = buffer_guard.get(buffer_id);
|
||||
let mut device_guard = HUB.devices.write();
|
||||
let device = device_guard.get_mut(buffer.device_id.value);
|
||||
|
||||
//Note: this is just doing `update_buffer`, which is limited to 64KB
|
||||
|
||||
trace!("transit {:?} to transfer dst", buffer_id);
|
||||
let barrier = device.buffer_tracker
|
||||
.lock()
|
||||
.transit(
|
||||
buffer_id,
|
||||
&buffer.life_guard.ref_count,
|
||||
resource::BufferUsageFlags::TRANSFER_DST,
|
||||
TrackPermit::REPLACE,
|
||||
)
|
||||
.unwrap()
|
||||
.into_source()
|
||||
.map(|old| hal::memory::Barrier::Buffer {
|
||||
states: conv::map_buffer_state(old) ..
|
||||
hal::buffer::State::TRANSFER_WRITE,
|
||||
target: &buffer.raw,
|
||||
families: None,
|
||||
range: None .. None, //TODO: could be partial
|
||||
});
|
||||
|
||||
let mut comb = device.com_allocator.allocate(buffer.device_id.clone(), &device.raw);
|
||||
unsafe {
|
||||
let raw = comb.raw.last_mut().unwrap();
|
||||
raw.begin(
|
||||
hal::command::CommandBufferFlags::ONE_TIME_SUBMIT,
|
||||
hal::command::CommandBufferInheritanceInfo::default(),
|
||||
);
|
||||
raw.pipeline_barrier(
|
||||
hal::pso::PipelineStage::TOP_OF_PIPE .. hal::pso::PipelineStage::TRANSFER,
|
||||
hal::memory::Dependencies::empty(),
|
||||
barrier,
|
||||
);
|
||||
raw.update_buffer(
|
||||
&buffer.raw,
|
||||
start as hal::buffer::Offset,
|
||||
slice::from_raw_parts(data, count as usize),
|
||||
);
|
||||
raw.finish();
|
||||
|
||||
let submission = hal::queue::Submission {
|
||||
command_buffers: iter::once(&*raw),
|
||||
wait_semaphores: None,
|
||||
signal_semaphores: None,
|
||||
};
|
||||
device.queue_group.queues[0]
|
||||
.as_raw_mut()
|
||||
.submit::<_, _, <back::Backend as hal::Backend>::Semaphore, _, _>(submission, None);
|
||||
}
|
||||
|
||||
device.com_allocator.after_submit(comb);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use crate::{Stored, WeaklyStored,
|
||||
};
|
||||
use crate::{conv, resource};
|
||||
use crate::registry::{HUB, Items};
|
||||
use crate::track::{Tracktion, TrackPermit};
|
||||
use crate::track::{TrackPermit};
|
||||
|
||||
use hal;
|
||||
use hal::{Device as _Device, Swapchain as _Swapchain};
|
||||
@ -116,7 +116,7 @@ pub extern "C" fn wgpu_swap_chain_present(
|
||||
}
|
||||
|
||||
trace!("transit {:?} to present", frame.texture_id.value);
|
||||
let tracktion = device.texture_tracker
|
||||
let barrier = device.texture_tracker
|
||||
.lock()
|
||||
.transit(
|
||||
frame.texture_id.value,
|
||||
@ -124,20 +124,15 @@ pub extern "C" fn wgpu_swap_chain_present(
|
||||
resource::TextureUsageFlags::PRESENT,
|
||||
TrackPermit::REPLACE,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let barrier = match tracktion {
|
||||
Tracktion::Keep => None,
|
||||
Tracktion::Replace { old } => Some(hal::memory::Barrier::Image {
|
||||
.unwrap()
|
||||
.into_source()
|
||||
.map(|old| hal::memory::Barrier::Image {
|
||||
states: conv::map_texture_state(old, hal::format::Aspects::COLOR) ..
|
||||
(hal::image::Access::empty(), hal::image::Layout::Present),
|
||||
target: &texture.raw,
|
||||
families: None,
|
||||
range: texture.full_range.clone(),
|
||||
}),
|
||||
Tracktion::Init |
|
||||
Tracktion::Extend {..} => unreachable!(),
|
||||
};
|
||||
});
|
||||
|
||||
unsafe {
|
||||
frame.comb.begin(false);
|
||||
|
@ -20,6 +20,17 @@ pub enum Tracktion<T> {
|
||||
Replace { old: T },
|
||||
}
|
||||
|
||||
impl<T> Tracktion<T> {
|
||||
pub fn into_source(self) -> Option<T> {
|
||||
match self {
|
||||
Tracktion::Init |
|
||||
Tracktion::Keep => None,
|
||||
Tracktion::Extend { old } |
|
||||
Tracktion::Replace { old } => Some(old),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Query<T> {
|
||||
pub usage: T,
|
||||
|
@ -352,6 +352,12 @@ impl Device {
|
||||
}
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
pub fn set_sub_data(&self, offset: u32, data: &[u8]) {
|
||||
wgn::wgpu_buffer_set_sub_data(self.id, offset, data.len() as u32, data.as_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
impl Texture {
|
||||
pub fn create_texture_view(&self, desc: &TextureViewDescriptor) -> TextureView {
|
||||
TextureView {
|
||||
|
Loading…
Reference in New Issue
Block a user