From 86a4e944ed1041597f3efcbeba642d15159c96a3 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 27 Apr 2020 21:26:34 -0400 Subject: [PATCH 01/12] Split serde feature into trace+replay --- .github/workflows/ci.yml | 9 +++ wgpu-core/Cargo.toml | 10 +-- wgpu-core/src/binding_model.rs | 41 ++++------ wgpu-core/src/id.rs | 9 +-- wgpu-core/src/instance.rs | 27 +++---- wgpu-types/Cargo.toml | 4 + wgpu-types/src/lib.rs | 141 ++++++++++++++++++++++----------- 7 files changed, 136 insertions(+), 105 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41363271a9..6ac9a72e12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,30 +27,37 @@ jobs: name: iOS Stable channel: stable build_command: rustup target add aarch64-apple-ios; cargo clippy --target aarch64-apple-ios + additional_core_features: - os: macos-10.15 name: MacOS Stable channel: stable build_command: cargo clippy + additional_core_features: trace - os: macos-10.15 name: MacOS Nightly channel: nightly build_command: cargo test + additional_core_features: - os: ubuntu-18.04 name: Ubuntu Stable channel: stable build_command: cargo clippy + additional_core_features: trace,replay - os: ubuntu-18.04 name: Ubuntu Nightly channel: nightly build_command: cargo test + additional_core_features: - os: windows-2019 name: Windows Stable channel: stable build_command: rustup default stable-msvc; cargo clippy + additional_core_features: replay - os: windows-2019 name: Windows Nightly channel: nightly build_command: rustup default nightly-msvc; cargo test + additional_core_features: steps: - uses: actions/checkout@v2 - if: matrix.channel == 'nightly' @@ -63,3 +70,5 @@ jobs: run: rustup component add clippy - name: cargo clippy/test run: ${{ matrix.build_command }} + - if: matrix.additional_core_features != '' + run: cargo check --manifest-path wgpu-core/Cargo.toml --features ${{ matrix.additional_core_features }} diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 0b1185bbd5..494c80ae30 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -16,8 +16,9 @@ license = "MPL-2.0" [features] default = [] +trace = ["serde", "wgt/trace"] +replay = ["serde", "wgt/replay"] metal-auto-capture = ["gfx-backend-metal/auto-capture"] -serde = ["wgt/serde", "serde_crate"] #NOTE: glutin feature is not stable, use at your own risk #glutin = ["gfx-backend-gl/glutin"] @@ -33,15 +34,10 @@ gfx-descriptor = "0.1" gfx-memory = "0.1" parking_lot = "0.10" peek-poke = "0.2" +serde = { version = "1.0", features = ["serde_derive"], optional = true } smallvec = "1" vec_map = "0.8" -[dependencies.serde_crate] -package = "serde" -version = "1.0" -features = ["serde_derive"] -optional = true - [dependencies.wgt] path = "../wgpu-types" package = "wgpu-types" diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index e8c20477e3..17cfff5cd1 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -12,17 +12,16 @@ use arrayvec::ArrayVec; use gfx_descriptor::{DescriptorCounts, DescriptorSet}; use wgt::{BufferAddress, TextureComponentType}; -#[cfg(feature = "serde")] -use serde_crate::{Deserialize, Serialize}; +#[cfg(feature = "replay")] +use serde::Deserialize; +#[cfg(feature = "trace")] +use serde::Serialize; use std::borrow::Borrow; #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum BindingType { UniformBuffer = 0, StorageBuffer = 1, @@ -36,11 +35,8 @@ pub enum BindingType { #[repr(C)] #[derive(Clone, Debug, Hash, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct BindGroupLayoutEntry { pub binding: u32, pub visibility: wgt::ShaderStage, @@ -86,11 +82,8 @@ pub struct PipelineLayout { #[repr(C)] #[derive(Debug)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct BufferBinding { pub buffer: BufferId, pub offset: BufferAddress, @@ -99,11 +92,8 @@ pub struct BufferBinding { #[repr(C)] #[derive(Debug)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum BindingResource { Buffer(BufferBinding), Sampler(SamplerId), @@ -112,11 +102,8 @@ pub enum BindingResource { #[repr(C)] #[derive(Debug)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct BindGroupEntry { pub binding: u32, pub resource: BindingResource, diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index f50477cbeb..e5bb1f1846 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -3,8 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::{Epoch, Index}; -#[cfg(feature = "serde")] -use serde_crate::{Deserialize, Serialize}; use std::{fmt, marker::PhantomData, mem, num::NonZeroU64}; use wgt::Backend; @@ -13,11 +11,8 @@ const EPOCH_MASK: u32 = (1 << (32 - BACKEND_BITS)) - 1; type Dummy = crate::backend::Empty; #[repr(transparent)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(serde::Serialize))] +#[cfg_attr(feature = "replay", derive(serde::Deserialize))] pub struct Id(NonZeroU64, PhantomData); // required for PeekPoke diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index c49e412695..edab05ea19 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -12,8 +12,10 @@ use crate::{ use wgt::{Backend, BackendBit, DeviceDescriptor, PowerPreference, BIND_BUFFER_ALIGNMENT}; -#[cfg(feature = "serde")] -use serde_crate::{Deserialize, Serialize}; +#[cfg(feature = "replay")] +use serde::Deserialize; +#[cfg(feature = "trace")] +use serde::Serialize; use hal::{ self, @@ -25,11 +27,8 @@ use hal::{ #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct RequestAdapterOptions { pub power_preference: PowerPreference, pub compatible_surface: Option, @@ -124,11 +123,8 @@ pub struct Adapter { /// Metadata about a backend adapter. #[derive(Clone, Debug, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct AdapterInfo { /// Adapter name pub name: String, @@ -163,11 +159,8 @@ impl AdapterInfo { /// Supported physical device types #[derive(Clone, Debug, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate") -)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum DeviceType { /// Other Other, diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index 616e7e5e03..79b2d1e933 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -14,6 +14,10 @@ license = "MPL-2.0" [lib] +[features] +trace = ["serde"] +replay = ["serde"] + [dependencies] bitflags = "1.0" serde = { version = "1.0", features = ["serde_derive"], optional = true } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 2f7c0a928f..afb44f6553 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -4,13 +4,16 @@ #[cfg(feature = "peek-poke")] use peek_poke::PeekPoke; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; +#[cfg(feature = "replay")] +use serde::Deserialize; +#[cfg(feature = "trace")] +use serde::Serialize; use std::{io, ptr, slice}; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum Backend { Empty = 0, Vulkan = 1, @@ -23,7 +26,8 @@ pub enum Backend { #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum PowerPreference { Default = 0, LowPower = 1, @@ -32,7 +36,8 @@ pub enum PowerPreference { bitflags::bitflags! { #[repr(transparent)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct BackendBit: u32 { const VULKAN = 1 << Backend::Vulkan as u32; const GL = 1 << Backend::Gl as u32; @@ -58,14 +63,16 @@ impl From for BackendBit { #[repr(C)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct Extensions { pub anisotropic_filtering: bool, } #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct Limits { pub max_bind_groups: u32, } @@ -82,7 +89,8 @@ impl Default for Limits { #[repr(C)] #[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct DeviceDescriptor { pub extensions: Extensions, pub limits: Limits, @@ -130,7 +138,8 @@ pub fn read_spirv(mut x: R) -> io::Result> { bitflags::bitflags! { #[repr(transparent)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct ShaderStage: u32 { const NONE = 0; const VERTEX = 1; @@ -141,7 +150,8 @@ bitflags::bitflags! { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum TextureViewDimension { D1, D2, @@ -155,7 +165,8 @@ pub type BufferAddress = u64; #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum BlendFactor { Zero = 0, One = 1, @@ -174,7 +185,8 @@ pub enum BlendFactor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum BlendOperation { Add = 0, Subtract = 1, @@ -191,7 +203,8 @@ impl Default for BlendOperation { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct BlendDescriptor { pub src_factor: BlendFactor, pub dst_factor: BlendFactor, @@ -224,7 +237,8 @@ impl Default for BlendDescriptor { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct ColorStateDescriptor { pub format: TextureFormat, pub alpha_blend: BlendDescriptor, @@ -234,7 +248,8 @@ pub struct ColorStateDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum PrimitiveTopology { PointList = 0, LineList = 1, @@ -245,7 +260,8 @@ pub enum PrimitiveTopology { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum FrontFace { Ccw = 0, Cw = 1, @@ -259,7 +275,8 @@ impl Default for FrontFace { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum CullMode { None = 0, Front = 1, @@ -274,7 +291,8 @@ impl Default for CullMode { #[repr(C)] #[derive(Clone, Debug, Default, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct RasterizationStateDescriptor { pub front_face: FrontFace, pub cull_mode: CullMode, @@ -285,7 +303,8 @@ pub struct RasterizationStateDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum TextureFormat { // Normal 8 bit formats R8Unorm = 0, @@ -342,7 +361,8 @@ pub enum TextureFormat { bitflags::bitflags! { #[repr(transparent)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct ColorWrite: u32 { const RED = 1; const GREEN = 2; @@ -361,7 +381,8 @@ impl Default for ColorWrite { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct DepthStencilStateDescriptor { pub format: TextureFormat, pub depth_write_enabled: bool, @@ -380,7 +401,8 @@ impl DepthStencilStateDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum IndexFormat { Uint16 = 0, Uint32 = 1, @@ -388,7 +410,8 @@ pub enum IndexFormat { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum StencilOperation { Keep = 0, Zero = 1, @@ -408,7 +431,8 @@ impl Default for StencilOperation { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct StencilStateFaceDescriptor { pub compare: CompareFunction, pub fail_op: StencilOperation, @@ -433,7 +457,8 @@ impl Default for StencilStateFaceDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum CompareFunction { Undefined = 0, Never = 1, @@ -459,7 +484,8 @@ pub type ShaderLocation = u32; #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum InputStepMode { Vertex = 0, Instance = 1, @@ -467,7 +493,8 @@ pub enum InputStepMode { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct VertexAttributeDescriptor { pub offset: BufferAddress, pub format: VertexFormat, @@ -476,7 +503,8 @@ pub struct VertexAttributeDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum VertexFormat { Uchar2 = 0, Uchar4 = 1, @@ -512,7 +540,8 @@ pub enum VertexFormat { bitflags::bitflags! { #[repr(transparent)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct BufferUsage: u32 { const MAP_READ = 1; const MAP_WRITE = 2; @@ -553,7 +582,8 @@ pub type DynamicOffset = u32; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum PresentMode { /// The presentation engine does **not** wait for a vertical blanking period and /// the request is presented immediately. This is a low-latency presentation mode, @@ -573,7 +603,8 @@ pub enum PresentMode { bitflags::bitflags! { #[repr(transparent)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct TextureUsage: u32 { const COPY_SRC = 1; const COPY_DST = 2; @@ -585,7 +616,8 @@ bitflags::bitflags! { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct SwapChainDescriptor { pub usage: TextureUsage, pub format: TextureFormat, @@ -596,7 +628,8 @@ pub struct SwapChainDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] #[cfg_attr(feature = "peek-poke", derive(PeekPoke))] pub enum LoadOp { Clear = 0, @@ -605,7 +638,8 @@ pub enum LoadOp { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] #[cfg_attr(feature = "peek-poke", derive(PeekPoke))] pub enum StoreOp { Clear = 0, @@ -614,7 +648,8 @@ pub enum StoreOp { #[repr(C)] #[derive(Clone, Debug)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] #[cfg_attr(feature = "peek-poke", derive(PeekPoke))] pub struct RenderPassColorAttachmentDescriptorBase { pub attachment: T, @@ -626,7 +661,8 @@ pub struct RenderPassColorAttachmentDescriptorBase { #[repr(C)] #[derive(Clone, Debug)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] #[cfg_attr(feature = "peek-poke", derive(PeekPoke))] pub struct RenderPassDepthStencilAttachmentDescriptorBase { pub attachment: T, @@ -640,7 +676,8 @@ pub struct RenderPassDepthStencilAttachmentDescriptorBase { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] #[cfg_attr(feature = "peek-poke", derive(PeekPoke))] pub struct Color { pub r: f64, @@ -690,7 +727,8 @@ impl Color { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum TextureDimension { D1, D2, @@ -699,7 +737,8 @@ pub enum TextureDimension { #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct Origin3d { pub x: u32, pub y: u32, @@ -718,7 +757,8 @@ impl Default for Origin3d { #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct Extent3d { pub width: u32, pub height: u32, @@ -739,7 +779,8 @@ pub struct TextureDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum TextureAspect { All, StencilOnly, @@ -754,7 +795,8 @@ impl Default for TextureAspect { #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct TextureViewDescriptor { pub format: TextureFormat, pub dimension: TextureViewDimension, @@ -767,7 +809,8 @@ pub struct TextureViewDescriptor { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum AddressMode { ClampToEdge = 0, Repeat = 1, @@ -782,7 +825,8 @@ impl Default for AddressMode { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum FilterMode { Nearest = 0, Linear = 1, @@ -796,7 +840,8 @@ impl Default for FilterMode { #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct SamplerDescriptor { pub address_mode_u: AddressMode, pub address_mode_v: AddressMode, @@ -811,14 +856,16 @@ pub struct SamplerDescriptor { #[repr(C)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct CommandBufferDescriptor { pub todo: u32, } #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum TextureComponentType { Float, Sint, From 42e101225b32bdba7f0635d6a81b21ee3ade17c4 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 27 Apr 2020 22:06:38 -0400 Subject: [PATCH 02/12] Split limits and private features, add tracing module --- wgpu-core/src/command/allocator.rs | 9 ++++--- wgpu-core/src/command/compute.rs | 2 +- wgpu-core/src/command/mod.rs | 5 ++-- wgpu-core/src/command/render.rs | 17 ++++++++++--- wgpu-core/src/command/transfer.rs | 4 +-- wgpu-core/src/conv.rs | 8 +++--- wgpu-core/src/device/mod.rs | 39 +++++++++++++++++++++--------- wgpu-core/src/device/trace.rs | 26 ++++++++++++++++++++ wgpu-core/src/instance.rs | 5 +++- wgpu-core/src/lib.rs | 3 +-- wgpu-core/src/swap_chain.rs | 13 ++++++---- 11 files changed, 95 insertions(+), 36 deletions(-) create mode 100644 wgpu-core/src/device/trace.rs diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index 436bb550ad..6eb18b1853 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -4,7 +4,8 @@ use super::CommandBuffer; use crate::{ - hub::GfxBackend, id::DeviceId, track::TrackerSet, Features, LifeGuard, Stored, SubmissionIndex, + hub::GfxBackend, id::DeviceId, track::TrackerSet, LifeGuard, PrivateFeatures, Stored, + SubmissionIndex, }; use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _}; @@ -76,7 +77,8 @@ impl CommandAllocator { &self, device_id: Stored, device: &B::Device, - features: Features, + limits: wgt::Limits, + private_features: PrivateFeatures, lowest_active_index: SubmissionIndex, ) -> CommandBuffer { //debug_assert_eq!(device_id.backend(), B::VARIANT); @@ -108,7 +110,8 @@ impl CommandAllocator { life_guard: LifeGuard::new(), trackers: TrackerSet::new(B::VARIANT), used_swap_chain: None, - features, + limits, + private_features, } } } diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index d74035cc3e..179190d4c1 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -79,7 +79,7 @@ impl Global { let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); let cmb = &mut cmb_guard[encoder_id]; let raw = cmb.raw.last_mut().unwrap(); - let mut binder = Binder::new(cmb.features.max_bind_groups); + let mut binder = Binder::new(cmb.limits.max_bind_groups); let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token); let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token); diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 9529afc0f8..8a57b2cf4c 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -19,7 +19,7 @@ use crate::{ id, resource::{Buffer, Texture}, track::TrackerSet, - Features, LifeGuard, Stored, + LifeGuard, PrivateFeatures, Stored, }; use peek_poke::PeekPoke; @@ -138,7 +138,8 @@ pub struct CommandBuffer { pub(crate) life_guard: LifeGuard, pub(crate) trackers: TrackerSet, pub(crate) used_swap_chain: Option<(Stored, B::Framebuffer)>, - pub(crate) features: Features, + limits: wgt::Limits, + private_features: PrivateFeatures, } impl CommandBuffer { diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index bb9c186493..97520ca968 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -431,7 +431,10 @@ impl Global { }; Some(hal::pass::Attachment { - format: Some(conv::map_texture_format(view.format, device.features)), + format: Some(conv::map_texture_format( + view.format, + device.private_features, + )), samples: view.samples, ops: conv::map_load_store_ops(at.depth_load_op, at.depth_store_op), stencil_ops: conv::map_load_store_ops( @@ -495,7 +498,10 @@ impl Global { }; colors.push(hal::pass::Attachment { - format: Some(conv::map_texture_format(view.format, device.features)), + format: Some(conv::map_texture_format( + view.format, + device.private_features, + )), samples: view.samples, ops: conv::map_load_store_ops(at.load_op, at.store_op), stencil_ops: hal::pass::AttachmentOps::DONT_CARE, @@ -541,7 +547,10 @@ impl Global { }; resolves.push(hal::pass::Attachment { - format: Some(conv::map_texture_format(view.format, device.features)), + format: Some(conv::map_texture_format( + view.format, + device.private_features, + )), samples: view.samples, ops: hal::pass::AttachmentOps::new( hal::pass::AttachmentLoadOp::DontCare, @@ -788,7 +797,7 @@ impl Global { }; let mut state = State { - binder: Binder::new(cmb.features.max_bind_groups), + binder: Binder::new(cmb.limits.max_bind_groups), blend_color: OptionalState::Unused, stencil_reference: OptionalState::Unused, pipeline: OptionalState::Required, diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 62fcb56f8b..e26d5a1865 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -153,7 +153,7 @@ impl Global { assert!(dst_texture.usage.contains(TextureUsage::COPY_DST)); let dst_barriers = dst_pending.map(|pending| pending.into_hal(dst_texture)); - let bytes_per_texel = conv::map_texture_format(dst_texture.format, cmb.features) + let bytes_per_texel = conv::map_texture_format(dst_texture.format, cmb.private_features) .surface_desc() .bits as u32 / BITS_PER_BYTE; @@ -217,7 +217,7 @@ impl Global { assert!(dst_buffer.usage.contains(BufferUsage::COPY_DST)); let dst_barrier = dst_barriers.map(|pending| pending.into_hal(dst_buffer)); - let bytes_per_texel = conv::map_texture_format(src_texture.format, cmb.features) + let bytes_per_texel = conv::map_texture_format(src_texture.format, cmb.private_features) .surface_desc() .bits as u32 / BITS_PER_BYTE; diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index 510ec6c568..5f239c933b 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -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/. */ -use crate::{binding_model, resource, Features}; +use crate::{binding_model, resource, PrivateFeatures}; pub fn map_buffer_usage(usage: wgt::BufferUsage) -> (hal::buffer::Usage, hal::memory::Properties) { use hal::buffer::Usage as U; @@ -321,7 +321,7 @@ fn map_stencil_operation(stencil_operation: wgt::StencilOperation) -> hal::pso:: pub(crate) fn map_texture_format( texture_format: wgt::TextureFormat, - features: Features, + private_features: PrivateFeatures, ) -> hal::format::Format { use hal::format::Format as H; use wgt::TextureFormat as Tf; @@ -376,14 +376,14 @@ pub(crate) fn map_texture_format( // Depth and stencil formats Tf::Depth32Float => H::D32Sfloat, Tf::Depth24Plus => { - if features.supports_texture_d24_s8 { + if private_features.supports_texture_d24_s8 { H::D24UnormS8Uint } else { H::D32Sfloat } } Tf::Depth24PlusStencil8 => { - if features.supports_texture_d24_s8 { + if private_features.supports_texture_d24_s8 { H::D24UnormS8Uint } else { H::D32SfloatS8Uint diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 999dbd7279..99beca510a 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -7,7 +7,7 @@ use crate::{ hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token}, id, pipeline, resource, swap_chain, track::{BufferState, TextureState, TrackerSet}, - FastHashMap, Features, LifeGuard, Stored, + FastHashMap, LifeGuard, PrivateFeatures, Stored, }; use arrayvec::ArrayVec; @@ -31,6 +31,8 @@ use std::{ }; mod life; +#[cfg(feature = "trace")] +mod trace; pub const MAX_COLOR_TARGETS: usize = 4; pub const MAX_MIP_LEVELS: usize = 16; @@ -193,7 +195,10 @@ pub struct Device { // Life tracker should be locked right after the device and before anything else. life_tracker: Mutex>, temp_suspected: life::SuspectedResources, - pub(crate) features: Features, + pub(crate) private_features: PrivateFeatures, + limits: wgt::Limits, + #[cfg(feature = "trace")] + trace: Option>, } impl Device { @@ -204,7 +209,8 @@ impl Device { mem_props: hal::adapter::MemoryProperties, non_coherent_atom_size: u64, supports_texture_d24_s8: bool, - max_bind_groups: u32, + limits: wgt::Limits, + #[cfg(feature = "trace")] trace_path: Option<&std::path::Path>, ) -> Self { // don't start submission index at zero let life_guard = LifeGuard::new(); @@ -238,10 +244,18 @@ impl Device { framebuffers: Mutex::new(FastHashMap::default()), life_tracker: Mutex::new(life::LifetimeTracker::new()), temp_suspected: life::SuspectedResources::default(), - features: Features { - max_bind_groups, + private_features: PrivateFeatures { supports_texture_d24_s8, }, + limits, + #[cfg(feature = "trace")] + trace: trace_path.and_then(|path| match trace::Trace::new(path) { + Ok(trace) => Some(Mutex::new(trace)), + Err(e) => { + log::warn!("Unable to start a trace in '{:?}': {:?}", path, e); + None + } + }), } } @@ -359,7 +373,7 @@ impl Device { } let kind = conv::map_texture_dimension_size(desc.dimension, desc.size, desc.sample_count); - let format = conv::map_texture_format(desc.format, self.features); + let format = conv::map_texture_format(desc.format, self.private_features); let aspects = format.surface_desc().aspects; let usage = conv::map_texture_usage(desc.usage, aspects); @@ -747,7 +761,7 @@ impl Global { .create_image_view( &texture.raw, view_kind, - conv::map_texture_format(format, device.features), + conv::map_texture_format(format, device.private_features), hal::format::Swizzle::NO, range.clone(), ) @@ -975,7 +989,7 @@ impl Global { slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length) }; - assert!(desc.bind_group_layouts_length <= (device.features.max_bind_groups as usize), + assert!(desc.bind_group_layouts_length <= (device.limits.max_bind_groups as usize), "Cannot set a bind group which is beyond the `max_bind_groups` limit requested on device creation"); // TODO: push constants @@ -1329,7 +1343,8 @@ impl Global { let mut command_buffer = device.com_allocator.allocate( dev_stored, &device.raw, - device.features, + device.limits.clone(), + device.private_features, lowest_active_index, ); unsafe { @@ -1697,7 +1712,7 @@ impl Global { colors: color_states .iter() .map(|at| hal::pass::Attachment { - format: Some(conv::map_texture_format(at.format, device.features)), + format: Some(conv::map_texture_format(at.format, device.private_features)), samples: sc, ops: hal::pass::AttachmentOps::PRESERVE, stencil_ops: hal::pass::AttachmentOps::DONT_CARE, @@ -1710,7 +1725,7 @@ impl Global { // or depth/stencil resolve modes but satisfy the other compatibility conditions. resolves: ArrayVec::new(), depth_stencil: depth_stencil_state.map(|at| hal::pass::Attachment { - format: Some(conv::map_texture_format(at.format, device.features)), + format: Some(conv::map_texture_format(at.format, device.private_features)), samples: sc, ops: hal::pass::AttachmentOps::PRESERVE, stencil_ops: hal::pass::AttachmentOps::PRESERVE, @@ -2023,7 +2038,7 @@ impl Global { .max(*caps.image_count.start()) .min(*caps.image_count.end()); let mut config = - swap_chain::swap_chain_descriptor_to_hal(&desc, num_frames, device.features); + swap_chain::swap_chain_descriptor_to_hal(&desc, num_frames, device.private_features); if let Some(formats) = formats { assert!( formats.contains(&config.format), diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs new file mode 100644 index 0000000000..3365cf3c7b --- /dev/null +++ b/wgpu-core/src/device/trace.rs @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +#[derive(Debug)] +pub struct Trace { + path: std::path::PathBuf, + file: std::fs::File, +} + +impl Trace { + pub fn new(path: &std::path::Path) -> Result { + let mut file = std::fs::File::create(path.join("trace.ron"))?; + std::io::Write::write(&mut file, b"[\n")?; + Ok(Trace { + path: path.to_path_buf(), + file, + }) + } +} + +impl Drop for Trace { + fn drop(&mut self) { + let _ = std::io::Write::write(&mut self.file, b"]"); + } +} diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index edab05ea19..8346472ce1 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -502,6 +502,7 @@ impl Global { &self, adapter_id: AdapterId, desc: &DeviceDescriptor, + #[cfg(feature = "trace")] trace_path: Option<&std::path::Path>, id_in: Input, ) -> DeviceId { let hub = B::hub(self); @@ -567,7 +568,9 @@ impl Global { mem_props, limits.non_coherent_atom_size as u64, supports_texture_d24_s8, - desc.limits.max_bind_groups, + desc.limits.clone(), + #[cfg(feature = "trace")] + trace_path, ) }; diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 99d7892df8..f6c3373780 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -122,8 +122,7 @@ pub struct U32Array { } #[derive(Clone, Copy, Debug)] -pub(crate) struct Features { - pub max_bind_groups: u32, +struct PrivateFeatures { pub supports_texture_d24_s8: bool, } diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index c7ae49a949..19e2c7dca3 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -36,7 +36,7 @@ use crate::{ conv, hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token}, id::{DeviceId, SwapChainId, TextureViewId}, - resource, Features, LifeGuard, Stored, + resource, LifeGuard, PrivateFeatures, Stored, }; use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _}; @@ -59,12 +59,12 @@ pub struct SwapChain { pub(crate) fn swap_chain_descriptor_to_hal( desc: &SwapChainDescriptor, num_frames: u32, - features: Features, + private_features: PrivateFeatures, ) -> hal::window::SwapchainConfig { let mut config = hal::window::SwapchainConfig::new( desc.width, desc.height, - conv::map_texture_format(desc.format, features), + conv::map_texture_format(desc.format, private_features), num_frames, ); //TODO: check for supported @@ -114,8 +114,11 @@ impl Global { } Err(e) => { log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e); - let desc = - swap_chain_descriptor_to_hal(&sc.desc, sc.num_frames, device.features); + let desc = swap_chain_descriptor_to_hal( + &sc.desc, + sc.num_frames, + device.private_features, + ); unsafe { suf.configure_swapchain(&device.raw, desc).unwrap(); suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000).unwrap() From 00751ab017eca01763dab067447a121418a2bb1b Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 27 Apr 2020 22:41:43 -0400 Subject: [PATCH 03/12] trace: hook up RON output --- wgpu-core/Cargo.toml | 3 ++- wgpu-core/src/device/mod.rs | 21 ++++++++++++++------- wgpu-core/src/device/trace.rs | 25 +++++++++++++++++++++++-- wgpu-core/src/hub.rs | 14 +++++--------- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 494c80ae30..c6ad0c8321 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -16,7 +16,7 @@ license = "MPL-2.0" [features] default = [] -trace = ["serde", "wgt/trace"] +trace = ["ron", "serde", "wgt/trace"] replay = ["serde", "wgt/replay"] metal-auto-capture = ["gfx-backend-metal/auto-capture"] #NOTE: glutin feature is not stable, use at your own risk @@ -34,6 +34,7 @@ gfx-descriptor = "0.1" gfx-memory = "0.1" parking_lot = "0.10" peek-poke = "0.2" +ron = { version = "0.5", optional = true } serde = { version = "1.0", features = ["serde_derive"], optional = true } smallvec = "1" vec_map = "0.8" diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 99beca510a..f220877ac5 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -33,6 +33,8 @@ use std::{ mod life; #[cfg(feature = "trace")] mod trace; +#[cfg(feature = "trace")] +use trace::{Action, Trace}; pub const MAX_COLOR_TARGETS: usize = 4; pub const MAX_MIP_LEVELS: usize = 16; @@ -198,7 +200,7 @@ pub struct Device { pub(crate) private_features: PrivateFeatures, limits: wgt::Limits, #[cfg(feature = "trace")] - trace: Option>, + trace: Option>, } impl Device { @@ -244,18 +246,23 @@ impl Device { framebuffers: Mutex::new(FastHashMap::default()), life_tracker: Mutex::new(life::LifetimeTracker::new()), temp_suspected: life::SuspectedResources::default(), - private_features: PrivateFeatures { - supports_texture_d24_s8, - }, - limits, #[cfg(feature = "trace")] - trace: trace_path.and_then(|path| match trace::Trace::new(path) { - Ok(trace) => Some(Mutex::new(trace)), + trace: trace_path.and_then(|path| match Trace::new(path) { + Ok(mut trace) => { + trace.add(Action::Init { + limits: limits.clone(), + }); + Some(Mutex::new(trace)) + } Err(e) => { log::warn!("Unable to start a trace in '{:?}': {:?}", path, e); None } }), + private_features: PrivateFeatures { + supports_texture_d24_s8, + }, + limits, } } diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 3365cf3c7b..1a8ad07663 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -2,25 +2,46 @@ * 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/. */ +use std::io::Write as _; + +#[derive(serde::Serialize)] +pub enum Action { + Init { limits: wgt::Limits }, +} + #[derive(Debug)] pub struct Trace { path: std::path::PathBuf, file: std::fs::File, + config: ron::ser::PrettyConfig, } impl Trace { pub fn new(path: &std::path::Path) -> Result { + log::info!("Tracing into '{:?}'", path); let mut file = std::fs::File::create(path.join("trace.ron"))?; - std::io::Write::write(&mut file, b"[\n")?; + file.write(b"[\n")?; Ok(Trace { path: path.to_path_buf(), file, + config: ron::ser::PrettyConfig::default(), }) } + + pub fn add(&mut self, action: Action) { + match ron::ser::to_string_pretty(&action, self.config.clone()) { + Ok(string) => { + let _ = write!(self.file, "{},\n", string); + } + Err(e) => { + log::warn!("RON serialization failure: {:?}", e); + } + } + } } impl Drop for Trace { fn drop(&mut self) { - let _ = std::io::Write::write(&mut self.file, b"]"); + let _ = self.file.write(b"]"); } } diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 3e0f759cb8..2d1ef24a59 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -545,17 +545,13 @@ impl Global { hubs: Hubs::new(&factory), } } +} - pub fn delete(self) { - let Global { - mut instance, - surfaces, - hubs, - } = self; - drop(hubs); +impl Drop for Global { + fn drop(&mut self) { // destroy surfaces - for (_, (surface, _)) in surfaces.data.write().map.drain() { - instance.destroy_surface(surface); + for (_, (surface, _)) in self.surfaces.data.write().map.drain() { + self.instance.destroy_surface(surface); } } } From 6ade9fed83682656af5c3c64809d3b1075af3086 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 28 Apr 2020 13:54:57 -0400 Subject: [PATCH 04/12] Make descriptors generic over Label --- wgpu-core/src/device/mod.rs | 66 +++++++++++++++++++++++++----- wgpu-core/src/device/trace.rs | 30 +++++++++++++- wgpu-core/src/swap_chain.rs | 19 +++++++++ wgpu-types/src/lib.rs | 76 +++++++++++++++++++++++++++++++---- 4 files changed, 174 insertions(+), 17 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index f220877ac5..5b24a82a84 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -32,10 +32,22 @@ use std::{ mod life; #[cfg(feature = "trace")] -mod trace; +pub(crate) mod trace; #[cfg(feature = "trace")] use trace::{Action, Trace}; +pub type Label = *const std::os::raw::c_char; +#[cfg(feature = "trace")] +fn own_label(label: &Label) -> String { + if label.is_null() { + String::new() + } else { + unsafe { ffi::CStr::from_ptr(*label) } + .to_string_lossy() + .to_string() + } +} + pub const MAX_COLOR_TARGETS: usize = 4; pub const MAX_MIP_LEVELS: usize = 16; pub const MAX_VERTEX_BUFFERS: usize = 16; @@ -200,7 +212,7 @@ pub struct Device { pub(crate) private_features: PrivateFeatures, limits: wgt::Limits, #[cfg(feature = "trace")] - trace: Option>, + pub(crate) trace: Option>, } impl Device { @@ -293,7 +305,7 @@ impl Device { fn create_buffer( &self, self_id: id::DeviceId, - desc: &wgt::BufferDescriptor, + desc: &wgt::BufferDescriptor