Skip to content

Commit

Permalink
Merge gfx-rs#555
Browse files Browse the repository at this point in the history
555: Use crates.io release of peek-poke r=kvark a=kvark

Closes gfx-rs#549 

Co-authored-by: Rukai <rubickent@gmail.com>
  • Loading branch information
bors[bot] and rukai committed Apr 6, 2020
2 parents d6d3169 + 99161cb commit 384606f
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 37 deletions.
30 changes: 22 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Generated with cbindgen:0.13.2 */
/* Generated with cbindgen:0.14.0 */

/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
* To generate this file:
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gfx-backend-empty = "0.5"
gfx-descriptor = "0.1"
gfx-memory = "0.1"
parking_lot = "0.10"
peek-poke = { git = "https://github.com/kvark/peek-poke", rev = "969bd7fe2be1a83f87916dc8b388c63cfd457075" }
peek-poke = "0.2"
smallvec = "1"
vec_map = "0.8"

Expand Down
14 changes: 10 additions & 4 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{

use wgt::{BufferAddress, BufferUsage, DynamicOffset, BIND_BUFFER_ALIGNMENT};
use hal::command::CommandBuffer as _;
use peek_poke::{Peek, PeekCopy, Poke};
use peek_poke::{Peek, PeekPoke, Poke};

use std::iter;

Expand All @@ -25,7 +25,7 @@ enum PipelineState {
Set,
}

#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
#[derive(Clone, Copy, Debug, PeekPoke)]
enum ComputeCommand {
SetBindGroup {
index: u8,
Expand All @@ -42,6 +42,12 @@ enum ComputeCommand {
End,
}

impl Default for ComputeCommand {
fn default() -> Self {
ComputeCommand::End
}
}

impl super::RawPass {
pub unsafe fn new_compute(parent: id::CommandEncoderId) -> Self {
Self::from_vec(Vec::<ComputeCommand>::with_capacity(1), parent)
Expand Down Expand Up @@ -90,7 +96,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut command = ComputeCommand::Dispatch([0; 3]); // dummy
loop {
assert!(unsafe { peeker.add(ComputeCommand::max_size()) } <= raw_data_end);
peeker = unsafe { command.peek_from(peeker) };
peeker = unsafe { ComputeCommand::peek_from(peeker, &mut command) };
match command {
ComputeCommand::SetBindGroup { index, num_dynamic_offsets, bind_group_id, phantom_offsets } => {
let (new_peeker, offsets) = unsafe {
Expand Down Expand Up @@ -256,7 +262,7 @@ use wgt::{BufferAddress, DynamicOffset};
index: index.try_into().unwrap(),
num_dynamic_offsets: offset_length.try_into().unwrap(),
bind_group_id,
phantom_offsets: PhantomSlice::new(),
phantom_offsets: PhantomSlice::default(),
});
pass.encode_slice(
slice::from_raw_parts(offsets, offset_length),
Expand Down
29 changes: 22 additions & 7 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use crate::{
Stored,
};

use peek_poke::PeekPoke;

use std::{
marker::PhantomData,
mem,
Expand All @@ -37,14 +39,16 @@ use std::{
};


#[derive(Clone, Copy, Debug, peek_poke::PeekCopy, peek_poke::Poke)]
#[derive(Clone, Copy, Debug, PeekPoke)]
struct PhantomSlice<T>(PhantomData<T>);

impl<T> PhantomSlice<T> {
fn new() -> Self {
impl<T> Default for PhantomSlice<T> {
fn default() -> Self {
PhantomSlice(PhantomData)
}
}

impl<T> PhantomSlice<T> {
unsafe fn decode_unaligned<'a>(
self, pointer: *const u8, count: usize, bound: *const u8
) -> (*const u8, &'a [T]) {
Expand Down Expand Up @@ -197,31 +201,42 @@ impl<B: GfxBackend> CommandBuffer<B> {
}

#[repr(C)]
#[derive(peek_poke::PeekCopy, peek_poke::Poke)]
#[derive(PeekPoke)]
struct PassComponent<T> {
load_op: wgt::LoadOp,
store_op: wgt::StoreOp,
clear_value: T,
}

// required for PeekPoke
impl<T: Default> Default for PassComponent<T> {
fn default() -> Self {
PassComponent {
load_op: wgt::LoadOp::Clear,
store_op: wgt::StoreOp::Clear,
clear_value: T::default(),
}
}
}

#[repr(C)]
#[derive(peek_poke::PeekCopy, peek_poke::Poke)]
#[derive(Default, PeekPoke)]
struct RawRenderPassColorAttachmentDescriptor {
attachment: u64,
resolve_target: u64,
component: PassComponent<wgt::Color>,
}

#[repr(C)]
#[derive(peek_poke::PeekCopy, peek_poke::Poke)]
#[derive(Default, PeekPoke)]
struct RawRenderPassDepthStencilAttachmentDescriptor {
attachment: u64,
depth: PassComponent<f32>,
stencil: PassComponent<u32>,
}

#[repr(C)]
#[derive(peek_poke::PeekCopy, peek_poke::Poke)]
#[derive(Default, PeekPoke)]
struct RawRenderTargets {
colors: [RawRenderPassColorAttachmentDescriptor; MAX_COLOR_TARGETS],
depth_stencil: RawRenderPassDepthStencilAttachmentDescriptor,
Expand Down
19 changes: 13 additions & 6 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use wgt::{
};
use arrayvec::ArrayVec;
use hal::command::CommandBuffer as _;
use peek_poke::{Peek, PeekCopy, Poke};
use peek_poke::{Peek, PeekPoke, Poke};

use std::{
borrow::Borrow,
Expand All @@ -67,15 +67,15 @@ pub struct RenderPassDescriptor<'a> {
pub depth_stencil_attachment: Option<&'a RenderPassDepthStencilAttachmentDescriptor>,
}

#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
#[derive(Clone, Copy, Debug, Default, PeekPoke)]
pub struct Rect<T> {
pub x: T,
pub y: T,
pub w: T,
pub h: T,
}

#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
#[derive(Clone, Copy, Debug, PeekPoke)]
enum RenderCommand {
SetBindGroup {
index: u8,
Expand Down Expand Up @@ -128,6 +128,13 @@ enum RenderCommand {
End,
}

// required for PeekPoke
impl Default for RenderCommand {
fn default() -> Self {
RenderCommand::End
}
}

impl super::RawPass {
pub unsafe fn new_render(parent_id: id::CommandEncoderId, desc: &RenderPassDescriptor) -> Self {
let mut pass = Self::from_vec(Vec::<RenderCommand>::with_capacity(1), parent_id);
Expand Down Expand Up @@ -334,7 +341,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let mut targets: RawRenderTargets = unsafe { mem::zeroed() };
assert!(unsafe { peeker.add(RawRenderTargets::max_size()) <= raw_data_end });
peeker = unsafe { targets.peek_from(peeker) };
peeker = unsafe { RawRenderTargets::peek_from(peeker, &mut targets) };

let color_attachments = targets.colors
.iter()
Expand Down Expand Up @@ -829,7 +836,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
loop {
assert!(unsafe { peeker.add(RenderCommand::max_size()) } <= raw_data_end);
peeker = unsafe { command.peek_from(peeker) };
peeker = unsafe { RenderCommand::peek_from(peeker, &mut command) };
match command {
RenderCommand::SetBindGroup { index, num_dynamic_offsets, bind_group_id, phantom_offsets } => {
let (new_peeker, offsets) = unsafe {
Expand Down Expand Up @@ -1190,7 +1197,7 @@ pub mod render_ffi {
index: index.try_into().unwrap(),
num_dynamic_offsets: offset_length.try_into().unwrap(),
bind_group_id,
phantom_offsets: PhantomSlice::new(),
phantom_offsets: PhantomSlice::default(),
});
pass.encode_slice(
slice::from_raw_parts(offsets, offset_length),
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let hub = B::hub(self);
let mut token = Token::root();

log::info!("Buffer {:?} is dropped", buffer_id);
let device_id = {
let (mut buffer_guard, _) = hub.buffers.write(&mut token);
let buffer = &mut buffer_guard[buffer_id];
Expand Down
13 changes: 10 additions & 3 deletions wgpu-core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ type Dummy = crate::backend::Empty;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub struct Id<T>(NonZeroU64, PhantomData<T>);

// required for PeekPoke
impl<T> Default for Id<T> {
fn default() -> Self {
Id(unsafe { NonZeroU64::new_unchecked(!0) }, PhantomData)
}
}

impl<T> Id<T> {
pub fn backend(self) -> Backend {
match self.0.get() >> (64 - BACKEND_BITS) as u8 {
Expand Down Expand Up @@ -76,10 +83,10 @@ unsafe impl<T> peek_poke::Poke for Id<T> {
}

impl<T> peek_poke::Peek for Id<T> {
unsafe fn peek_from(&mut self, mut data: *const u8) -> *const u8 {
unsafe fn peek_from(mut data: *const u8, this: *mut Self) -> *const u8 {
let mut v = 0u64;
data = v.peek_from(data);
self.0 = NonZeroU64::new(v).unwrap();
data = u64::peek_from(data, &mut v);
(*this).0 = NonZeroU64::new(v).unwrap();
data
}
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ license = "MPL-2.0"
[dependencies]
bitflags = "1.0"
serde = { version = "1.0", features = ["serde_derive"], optional = true }
peek-poke = { git = "https://github.com/kvark/peek-poke", rev = "969bd7fe2be1a83f87916dc8b388c63cfd457075", optional = true }
peek-poke = { version = "0.2", optional = true }
13 changes: 7 additions & 6 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{io, slice, ptr};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
#[cfg(feature = "peek-poke")]
use peek_poke::{PeekCopy, Poke};
use peek_poke::{PeekPoke};

#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -621,7 +621,7 @@ pub struct SwapChainDescriptor {
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
#[cfg_attr(feature = "peek-poke", derive(PeekPoke))]
pub enum LoadOp {
Clear = 0,
Load = 1,
Expand All @@ -630,7 +630,7 @@ pub enum LoadOp {
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
#[cfg_attr(feature = "peek-poke", derive(PeekPoke))]
pub enum StoreOp {
Clear = 0,
Store = 1,
Expand All @@ -639,6 +639,7 @@ pub enum StoreOp {
#[repr(C)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "peek-poke", derive(PeekPoke))]
pub struct RenderPassColorAttachmentDescriptorBase<T> {
pub attachment: T,
pub resolve_target: Option<T>,
Expand All @@ -650,7 +651,7 @@ pub struct RenderPassColorAttachmentDescriptorBase<T> {
#[repr(C)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
#[cfg_attr(feature = "peek-poke", derive(PeekPoke))]
pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
pub attachment: T,
pub depth_load_op: LoadOp,
Expand All @@ -662,9 +663,9 @@ pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
#[cfg_attr(feature = "peek-poke", derive(PeekPoke))]
pub struct Color {
pub r: f64,
pub g: f64,
Expand Down

0 comments on commit 384606f

Please sign in to comment.