Fully adopt bitflags for ShaderStageFlags and ColorWriteFlags

This commit is contained in:
Dzmitry Malyshau 2018-10-30 21:51:16 -04:00
parent 4f07ce8248
commit 6b9be3c08e
4 changed files with 34 additions and 41 deletions

View File

@ -2,16 +2,15 @@ use hal;
use {BindGroupLayoutId, BufferId, SamplerId, TextureViewId}; use {BindGroupLayoutId, BufferId, SamplerId, TextureViewId};
// TODO: bitflags
pub type ShaderStageFlags = u32; bitflags! {
#[allow(non_upper_case_globals)] #[repr(transparent)]
pub const ShaderStageFlags_NONE: u32 = 0; pub struct ShaderStageFlags: u32 {
#[allow(non_upper_case_globals)] const VERTEX = 1;
pub const ShaderStageFlags_VERTEX: u32 = 1; const FRAGMENT = 2;
#[allow(non_upper_case_globals)] const COMPUTE = 4;
pub const ShaderStageFlags_FRAGMENT: u32 = 2; }
#[allow(non_upper_case_globals)] }
pub const ShaderStageFlags_COMPUTE: u32 = 4;
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]

View File

@ -88,18 +88,17 @@ pub fn map_binding_type(
pub fn map_shader_stage_flags( pub fn map_shader_stage_flags(
shader_stage_flags: binding_model::ShaderStageFlags, shader_stage_flags: binding_model::ShaderStageFlags,
) -> hal::pso::ShaderStageFlags { ) -> hal::pso::ShaderStageFlags {
use binding_model::{ use binding_model::ShaderStageFlags as F;
ShaderStageFlags_COMPUTE, ShaderStageFlags_FRAGMENT, ShaderStageFlags_VERTEX,
};
use hal::pso::ShaderStageFlags as H; use hal::pso::ShaderStageFlags as H;
let mut value = H::empty(); let mut value = H::empty();
if 0 != shader_stage_flags & ShaderStageFlags_VERTEX { if shader_stage_flags.contains(F::VERTEX) {
value |= H::VERTEX; value |= H::VERTEX;
} }
if 0 != shader_stage_flags & ShaderStageFlags_FRAGMENT { if shader_stage_flags.contains(F::FRAGMENT) {
value |= H::FRAGMENT; value |= H::FRAGMENT;
} }
if 0 != shader_stage_flags & ShaderStageFlags_COMPUTE { if shader_stage_flags.contains(F::COMPUTE) {
value |= H::COMPUTE; value |= H::COMPUTE;
} }
value value
@ -134,22 +133,21 @@ pub fn map_blend_state_descriptor(
hal::pso::ColorBlendDesc(map_color_write_flags(color_mask), blend_state) hal::pso::ColorBlendDesc(map_color_write_flags(color_mask), blend_state)
} }
fn map_color_write_flags(flags: u32) -> hal::pso::ColorMask { fn map_color_write_flags(flags: pipeline::ColorWriteFlags) -> hal::pso::ColorMask {
use pipeline::ColorWriteFlags as F;
use hal::pso::ColorMask as H; use hal::pso::ColorMask as H;
use pipeline::{
ColorWriteFlags_ALPHA, ColorWriteFlags_BLUE, ColorWriteFlags_GREEN, ColorWriteFlags_RED,
};
let mut value = H::empty(); let mut value = H::empty();
if 0 != flags & ColorWriteFlags_RED { if flags.contains(F::RED) {
value |= H::RED; value |= H::RED;
} }
if 0 != flags & ColorWriteFlags_GREEN { if flags.contains(F::GREEN) {
value |= H::GREEN; value |= H::GREEN;
} }
if 0 != flags & ColorWriteFlags_BLUE { if flags.contains(F::BLUE) {
value |= H::BLUE; value |= H::BLUE;
} }
if 0 != flags & ColorWriteFlags_ALPHA { if flags.contains(F::ALPHA) {
value |= H::ALPHA; value |= H::ALPHA;
} }
value value

View File

@ -34,20 +34,17 @@ pub enum BlendOperation {
Max = 4, Max = 4,
} }
// TODO: bitflags bitflags! {
pub type ColorWriteFlags = u32; #[repr(transparent)]
#[allow(non_upper_case_globals)] pub struct ColorWriteFlags: u32 {
pub const ColorWriteFlags_NONE: u32 = 0; const RED = 1;
#[allow(non_upper_case_globals)] const GREEN = 2;
pub const ColorWriteFlags_RED: u32 = 1; const BLUE = 4;
#[allow(non_upper_case_globals)] const ALPHA = 8;
pub const ColorWriteFlags_GREEN: u32 = 2; const COLOR = 7;
#[allow(non_upper_case_globals)] const ALL = 15;
pub const ColorWriteFlags_BLUE: u32 = 4; }
#[allow(non_upper_case_globals)] }
pub const ColorWriteFlags_ALPHA: u32 = 8;
#[allow(non_upper_case_globals)]
pub const ColorWriteFlags_ALL: u32 = 15;
#[repr(C)] #[repr(C)]
pub struct BlendDescriptor { pub struct BlendDescriptor {
@ -77,7 +74,7 @@ impl BlendStateDescriptor {
blend_enabled: false, blend_enabled: false,
alpha: BlendDescriptor::REPLACE, alpha: BlendDescriptor::REPLACE,
color: BlendDescriptor::REPLACE, color: BlendDescriptor::REPLACE,
write_mask: ColorWriteFlags_ALL, write_mask: ColorWriteFlags::ALL,
}; };
} }

View File

@ -8,13 +8,12 @@ use std::ptr;
pub use wgn::{ pub use wgn::{
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d, AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage, Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage, ShaderStageFlags,
BindGroupLayoutBinding, BindingType, TextureDimension, TextureDescriptor, TextureFormat, BindGroupLayoutBinding, BindingType, TextureDimension, TextureDescriptor, TextureFormat,
TextureUsageFlags, TextureViewDescriptor, TextureUsageFlags, TextureViewDescriptor,
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor, PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor, RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
Attachment, LoadOp, StoreOp, Attachment, LoadOp, StoreOp,
ShaderStageFlags_NONE, ShaderStageFlags_VERTEX, ShaderStageFlags_FRAGMENT, ShaderStageFlags_COMPUTE
}; };