Update blending API names

This commit is contained in:
Dzmitry Malyshau 2021-04-15 11:25:04 -04:00
parent c0478c707d
commit c744582052
8 changed files with 62 additions and 50 deletions

View File

@ -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<Label<'a>>;
@ -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!(),

View File

@ -22,8 +22,8 @@ pub type BufferError = UseExtendError<BufferUse>;
/// 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<BufferSize>,
},
SetBlendColor(Color),
SetBlendConstant(Color),
SetStencilReference(u32),
SetViewport {
rect: Rect<f32>,

View File

@ -326,7 +326,7 @@ impl VertexState {
struct State {
pipeline_flags: PipelineFlags,
binder: Binder,
blend_color: OptionalState,
blend_constant: OptionalState,
stencil_reference: u32,
pipeline: StateChange<id::RenderPipelineId>,
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<G: GlobalIdentityHandlerFactory> Global<G> {
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<G: GlobalIdentityHandlerFactory> Global<G> {
}
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<G: GlobalIdentityHandlerFactory> Global<G> {
}
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<G: GlobalIdentityHandlerFactory> Global<G> {
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]

View File

@ -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,
}
}

View File

@ -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<B: GfxBackend> Device<B> {
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<G: GlobalIdentityHandlerFactory> Global<G> {
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);
}

View File

@ -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;
}

View File

@ -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 },

View File

@ -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,
}
}