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};
// TODO: bitflags
pub type ShaderStageFlags = u32;
#[allow(non_upper_case_globals)]
pub const ShaderStageFlags_NONE: u32 = 0;
#[allow(non_upper_case_globals)]
pub const ShaderStageFlags_VERTEX: u32 = 1;
#[allow(non_upper_case_globals)]
pub const ShaderStageFlags_FRAGMENT: u32 = 2;
#[allow(non_upper_case_globals)]
pub const ShaderStageFlags_COMPUTE: u32 = 4;
bitflags! {
#[repr(transparent)]
pub struct ShaderStageFlags: u32 {
const VERTEX = 1;
const FRAGMENT = 2;
const COMPUTE = 4;
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]

View File

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

View File

@ -34,20 +34,17 @@ pub enum BlendOperation {
Max = 4,
}
// TODO: bitflags
pub type ColorWriteFlags = u32;
#[allow(non_upper_case_globals)]
pub const ColorWriteFlags_NONE: u32 = 0;
#[allow(non_upper_case_globals)]
pub const ColorWriteFlags_RED: u32 = 1;
#[allow(non_upper_case_globals)]
pub const ColorWriteFlags_GREEN: u32 = 2;
#[allow(non_upper_case_globals)]
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;
bitflags! {
#[repr(transparent)]
pub struct ColorWriteFlags: u32 {
const RED = 1;
const GREEN = 2;
const BLUE = 4;
const ALPHA = 8;
const COLOR = 7;
const ALL = 15;
}
}
#[repr(C)]
pub struct BlendDescriptor {
@ -77,7 +74,7 @@ impl BlendStateDescriptor {
blend_enabled: false,
alpha: 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::{
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage,
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage, ShaderStageFlags,
BindGroupLayoutBinding, BindingType, TextureDimension, TextureDescriptor, TextureFormat,
TextureUsageFlags, TextureViewDescriptor,
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
Attachment, LoadOp, StoreOp,
ShaderStageFlags_NONE, ShaderStageFlags_VERTEX, ShaderStageFlags_FRAGMENT, ShaderStageFlags_COMPUTE
};