From c7445820526bab3aae222a7d689b2766ae2c4235 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 15 Apr 2021 11:25:04 -0400 Subject: [PATCH] Update blending API names --- wgpu-core/src/command/bundle.rs | 22 +++++++++++++++------- wgpu-core/src/command/draw.rs | 8 +++++--- wgpu-core/src/command/render.rs | 23 +++++++++++++---------- wgpu-core/src/conv.rs | 12 ++++++------ wgpu-core/src/device/mod.rs | 11 ++++------- wgpu-core/src/pipeline.rs | 2 +- wgpu-core/src/resource.rs | 4 +++- wgpu-types/src/lib.rs | 30 +++++++++++++++--------------- 8 files changed, 62 insertions(+), 50 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 84b55308c..bba9dc7a7 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -478,7 +478,7 @@ impl RenderBundleEncoder { | RenderCommand::BeginPipelineStatisticsQuery { .. } | RenderCommand::EndPipelineStatisticsQuery => unimplemented!(), RenderCommand::ExecuteBundle(_) - | RenderCommand::SetBlendColor(_) + | RenderCommand::SetBlendConstant(_) | RenderCommand::SetStencilReference(_) | RenderCommand::SetViewport { .. } | RenderCommand::SetScissor(_) => unreachable!("not supported by a render bundle"), @@ -533,6 +533,8 @@ pub enum CreateRenderBundleError { pub enum ExecutionError { #[error("buffer {0:?} is destroyed")] DestroyedBuffer(id::BufferId), + #[error("using {0} in a render bundle is not implemented")] + Unimplemented(&'static str), } pub type RenderBundleDescriptor<'a> = wgt::RenderBundleDescriptor>; @@ -733,15 +735,21 @@ impl RenderBundle { cmd_buf.draw_indexed_indirect(buffer, offset, 1, 0); } RenderCommand::MultiDrawIndirect { .. } - | RenderCommand::MultiDrawIndirectCount { .. } => unimplemented!(), - RenderCommand::PushDebugGroup { color: _, len: _ } => unimplemented!(), - RenderCommand::InsertDebugMarker { color: _, len: _ } => unimplemented!(), - RenderCommand::PopDebugGroup => unimplemented!(), + | RenderCommand::MultiDrawIndirectCount { .. } => { + return Err(ExecutionError::Unimplemented("multi-draw-indirect")) + } + RenderCommand::PushDebugGroup { .. } + | RenderCommand::InsertDebugMarker { .. } + | RenderCommand::PopDebugGroup => { + return Err(ExecutionError::Unimplemented("debug-markers")) + } RenderCommand::WriteTimestamp { .. } | RenderCommand::BeginPipelineStatisticsQuery { .. } - | RenderCommand::EndPipelineStatisticsQuery => unimplemented!(), + | RenderCommand::EndPipelineStatisticsQuery => { + return Err(ExecutionError::Unimplemented("queries")) + } RenderCommand::ExecuteBundle(_) - | RenderCommand::SetBlendColor(_) + | RenderCommand::SetBlendConstant(_) | RenderCommand::SetStencilReference(_) | RenderCommand::SetViewport { .. } | RenderCommand::SetScissor(_) => unreachable!(), diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 1df50a83c..7c40603df 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -22,8 +22,8 @@ pub type BufferError = UseExtendError; /// Error validating a draw call. #[derive(Clone, Debug, Error, PartialEq)] pub enum DrawError { - #[error("blend color needs to be set")] - MissingBlendColor, + #[error("blend constant needs to be set")] + MissingBlendConstant, #[error("render pipeline must be set")] MissingPipeline, #[error("vertex buffer {index} must be set")] @@ -95,6 +95,8 @@ pub enum RenderCommandError { InvalidViewport, #[error("Invalid ScissorRect parameters")] InvalidScissorRect, + #[error("Support for {0} is not implemented yet")] + Unimplemented(&'static str), } #[derive(Clone, Copy, Debug, Default)] @@ -142,7 +144,7 @@ pub enum RenderCommand { offset: BufferAddress, size: Option, }, - SetBlendColor(Color), + SetBlendConstant(Color), SetStencilReference(u32), SetViewport { rect: Rect, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index c0dc45ad0..af5aee3c4 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -326,7 +326,7 @@ impl VertexState { struct State { pipeline_flags: PipelineFlags, binder: Binder, - blend_color: OptionalState, + blend_constant: OptionalState, stencil_reference: u32, pipeline: StateChange, index: IndexState, @@ -355,8 +355,8 @@ impl State { if self.pipeline.is_unset() { return Err(DrawError::MissingPipeline); } - if self.blend_color == OptionalState::Required { - return Err(DrawError::MissingBlendColor); + if self.blend_constant == OptionalState::Required { + return Err(DrawError::MissingBlendConstant); } if indexed { // Pipeline expects an index buffer @@ -1068,7 +1068,7 @@ impl Global { let mut state = State { pipeline_flags: PipelineFlags::empty(), binder: Binder::new(), - blend_color: OptionalState::Unused, + blend_constant: OptionalState::Unused, stencil_reference: 0, pipeline: StateChange::new(), index: IndexState::default(), @@ -1188,8 +1188,8 @@ impl Global { } state - .blend_color - .require(pipeline.flags.contains(PipelineFlags::BLEND_COLOR)); + .blend_constant + .require(pipeline.flags.contains(PipelineFlags::BLEND_CONSTANT)); unsafe { raw.bind_graphics_pipeline(&pipeline.raw); @@ -1377,8 +1377,8 @@ impl Global { } state.vertex.update_limits(); } - RenderCommand::SetBlendColor(ref color) => { - state.blend_color = OptionalState::Set; + RenderCommand::SetBlendConstant(ref color) => { + state.blend_constant = OptionalState::Set; unsafe { raw.set_blend_constants(conv::map_color_f32(color)); } @@ -1911,6 +1911,9 @@ impl Global { ExecutionError::DestroyedBuffer(id) => { RenderCommandError::DestroyedBuffer(id) } + ExecutionError::Unimplemented(what) => { + RenderCommandError::Unimplemented(what) + } }) .map_pass_err(scope)?; @@ -2036,10 +2039,10 @@ pub mod render_ffi { } #[no_mangle] - pub extern "C" fn wgpu_render_pass_set_blend_color(pass: &mut RenderPass, color: &Color) { + pub extern "C" fn wgpu_render_pass_set_blend_constant(pass: &mut RenderPass, color: &Color) { pass.base .commands - .push(RenderCommand::SetBlendColor(*color)); + .push(RenderCommand::SetBlendConstant(*color)); } #[no_mangle] diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index d670cbde0..2d24df800 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -255,17 +255,17 @@ fn map_blend_factor(blend_factor: wgt::BlendFactor) -> hal::pso::Factor { match blend_factor { Bf::Zero => H::Zero, Bf::One => H::One, - Bf::SrcColor => H::SrcColor, - Bf::OneMinusSrcColor => H::OneMinusSrcColor, + Bf::Src => H::SrcColor, + Bf::OneMinusSrc => H::OneMinusSrcColor, Bf::SrcAlpha => H::SrcAlpha, Bf::OneMinusSrcAlpha => H::OneMinusSrcAlpha, - Bf::DstColor => H::DstColor, - Bf::OneMinusDstColor => H::OneMinusDstColor, + Bf::Dst => H::DstColor, + Bf::OneMinusDst => H::OneMinusDstColor, Bf::DstAlpha => H::DstAlpha, Bf::OneMinusDstAlpha => H::OneMinusDstAlpha, Bf::SrcAlphaSaturated => H::SrcAlphaSaturate, - Bf::BlendColor => H::ConstColor, - Bf::OneMinusBlendColor => H::OneMinusConstColor, + Bf::Constant => H::ConstColor, + Bf::OneMinusConstant => H::OneMinusConstColor, } } diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 3d951dfad..638431ec2 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -27,8 +27,7 @@ use hal::{ use parking_lot::{Mutex, MutexGuard}; use thiserror::Error; use wgt::{ - BufferAddress, BufferSize, InputStepMode, TextureDimension, - TextureFormat, TextureViewDimension + BufferAddress, BufferSize, InputStepMode, TextureDimension, TextureFormat, TextureViewDimension, }; use std::{ @@ -2433,8 +2432,8 @@ impl Device { let mut flags = pipeline::PipelineFlags::empty(); for state in color_states.iter() { if let Some(ref bs) = state.blend { - if bs.color.uses_color() | bs.alpha.uses_color() { - flags |= pipeline::PipelineFlags::BLEND_COLOR; + if bs.color.uses_constant() | bs.alpha.uses_constant() { + flags |= pipeline::PipelineFlags::BLEND_CONSTANT; } } } @@ -4526,9 +4525,7 @@ impl Global { HostMap::Write => (wgt::BufferUsage::MAP_WRITE, resource::BufferUse::MAP_WRITE), }; - if range.start % wgt::MAP_ALIGNMENT != 0 - || range.end % wgt::COPY_BUFFER_ALIGNMENT != 0 - { + if range.start % wgt::MAP_ALIGNMENT != 0 || range.end % wgt::COPY_BUFFER_ALIGNMENT != 0 { return Err(resource::BufferAccessError::UnalignedRange); } diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index e96e1510c..3928ef5f8 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -251,7 +251,7 @@ pub enum CreateRenderPipelineError { bitflags::bitflags! { #[repr(transparent)] pub struct PipelineFlags: u32 { - const BLEND_COLOR = 1; + const BLEND_CONSTANT = 1; const STENCIL_REFERENCE = 2; const WRITES_DEPTH_STENCIL = 4; } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index aa42169bc..6c71eea75 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -142,7 +142,9 @@ pub enum BufferAccessError { MissingBufferUsage(#[from] MissingBufferUsageError), #[error("buffer is not mapped")] NotMapped, - #[error("buffer map range must start aligned to `MAP_ALIGNMENT` and end to `COPY_BUFFER_ALIGNMENT`")] + #[error( + "buffer map range must start aligned to `MAP_ALIGNMENT` and end to `COPY_BUFFER_ALIGNMENT`" + )] UnalignedRange, #[error("buffer offset invalid: offset {offset} must be multiple of 8")] UnalignedOffset { offset: wgt::BufferAddress }, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 286195e2a..a1f2762ec 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -757,18 +757,18 @@ pub enum BlendFactor { Zero = 0, /// 1.0 One = 1, - /// S.color - SrcColor = 2, - /// 1.0 - S.color - OneMinusSrcColor = 3, + /// S.component + Src = 2, + /// 1.0 - S.component + OneMinusSrc = 3, /// S.alpha SrcAlpha = 4, /// 1.0 - S.alpha OneMinusSrcAlpha = 5, - /// D.color - DstColor = 6, - /// 1.0 - D.color - OneMinusDstColor = 7, + /// D.component + Dst = 6, + /// 1.0 - D.component + OneMinusDst = 7, /// D.alpha DstAlpha = 8, /// 1.0 - D.alpha @@ -776,9 +776,9 @@ pub enum BlendFactor { /// min(S.alpha, 1.0 - D.alpha) SrcAlphaSaturated = 10, /// Constant - BlendColor = 11, + Constant = 11, /// 1.0 - Constant - OneMinusBlendColor = 12, + OneMinusConstant = 12, } /// Alpha blend operation. @@ -839,12 +839,12 @@ impl BlendComponent { /// Returns true if the state relies on the constant color, which is /// set independently on a render command encoder. - pub fn uses_color(&self) -> bool { + pub fn uses_constant(&self) -> bool { match (self.src_factor, self.dst_factor) { - (BlendFactor::BlendColor, _) - | (BlendFactor::OneMinusBlendColor, _) - | (_, BlendFactor::BlendColor) - | (_, BlendFactor::OneMinusBlendColor) => true, + (BlendFactor::Constant, _) + | (BlendFactor::OneMinusConstant, _) + | (_, BlendFactor::Constant) + | (_, BlendFactor::OneMinusConstant) => true, (_, _) => false, } }