| 1 |
use windows::Win32::Graphics::{Direct3D, Direct3D12, Dxgi}; |
| 2 |
|
| 3 |
pub fn map_buffer_usage_to_resource_flags( |
| 4 |
usage: wgt::BufferUses, |
| 5 |
) -> Direct3D12::D3D12_RESOURCE_FLAGS { |
| 6 |
let mut flags = Direct3D12::D3D12_RESOURCE_FLAG_NONE; |
| 7 |
if usage.contains(wgt::BufferUses::STORAGE_READ_WRITE) |
| 8 |
|| usage.contains(wgt::BufferUses::ACCELERATION_STRUCTURE_QUERY) |
| 9 |
{ |
| 10 |
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; |
| 11 |
} |
| 12 |
flags |
| 13 |
} |
| 14 |
|
| 15 |
pub fn map_buffer_descriptor( |
| 16 |
desc: &crate::BufferDescriptor<'_>, |
| 17 |
) -> Direct3D12::D3D12_RESOURCE_DESC { |
| 18 |
Direct3D12::D3D12_RESOURCE_DESC { |
| 19 |
Dimension: Direct3D12::D3D12_RESOURCE_DIMENSION_BUFFER, |
| 20 |
Alignment: 0, |
| 21 |
Width: desc.size, |
| 22 |
Height: 1, |
| 23 |
DepthOrArraySize: 1, |
| 24 |
MipLevels: 1, |
| 25 |
Format: Dxgi::Common::DXGI_FORMAT_UNKNOWN, |
| 26 |
SampleDesc: Dxgi::Common::DXGI_SAMPLE_DESC { |
| 27 |
Count: 1, |
| 28 |
Quality: 0, |
| 29 |
}, |
| 30 |
Layout: Direct3D12::D3D12_TEXTURE_LAYOUT_ROW_MAJOR, |
| 31 |
Flags: map_buffer_usage_to_resource_flags(desc.usage), |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
pub fn map_texture_dimension(dim: wgt::TextureDimension) -> Direct3D12::D3D12_RESOURCE_DIMENSION { |
| 36 |
match dim { |
| 37 |
wgt::TextureDimension::D1 => Direct3D12::D3D12_RESOURCE_DIMENSION_TEXTURE1D, |
| 38 |
wgt::TextureDimension::D2 => Direct3D12::D3D12_RESOURCE_DIMENSION_TEXTURE2D, |
| 39 |
wgt::TextureDimension::D3 => Direct3D12::D3D12_RESOURCE_DIMENSION_TEXTURE3D, |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
pub fn map_texture_usage_to_resource_flags( |
| 44 |
usage: wgt::TextureUses, |
| 45 |
) -> Direct3D12::D3D12_RESOURCE_FLAGS { |
| 46 |
let mut flags = Direct3D12::D3D12_RESOURCE_FLAG_NONE; |
| 47 |
|
| 48 |
if usage.contains(wgt::TextureUses::COLOR_TARGET) { |
| 49 |
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; |
| 50 |
} |
| 51 |
if usage |
| 52 |
.intersects(wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE) |
| 53 |
{ |
| 54 |
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; |
| 55 |
if !usage.contains(wgt::TextureUses::RESOURCE) { |
| 56 |
flags |= Direct3D12::D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE; |
| 57 |
} |
| 58 |
} |
| 59 |
if usage.intersects( |
| 60 |
wgt::TextureUses::STORAGE_READ_ONLY |
| 61 |
| wgt::TextureUses::STORAGE_WRITE_ONLY |
| 62 |
| wgt::TextureUses::STORAGE_READ_WRITE, |
| 63 |
) { |
| 64 |
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; |
| 65 |
} |
| 66 |
|
| 67 |
flags |
| 68 |
} |
| 69 |
|
| 70 |
pub fn map_address_mode(mode: wgt::AddressMode) -> Direct3D12::D3D12_TEXTURE_ADDRESS_MODE { |
| 71 |
use wgt::AddressMode as Am; |
| 72 |
match mode { |
| 73 |
Am::Repeat => Direct3D12::D3D12_TEXTURE_ADDRESS_MODE_WRAP, |
| 74 |
Am::MirrorRepeat => Direct3D12::D3D12_TEXTURE_ADDRESS_MODE_MIRROR, |
| 75 |
Am::ClampToEdge => Direct3D12::D3D12_TEXTURE_ADDRESS_MODE_CLAMP, |
| 76 |
Am::ClampToBorder => Direct3D12::D3D12_TEXTURE_ADDRESS_MODE_BORDER, |
| 77 |
//Am::MirrorClamp => Direct3D12::D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE, |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
pub fn map_filter_mode(mode: wgt::FilterMode) -> Direct3D12::D3D12_FILTER_TYPE { |
| 82 |
match mode { |
| 83 |
wgt::FilterMode::Nearest => Direct3D12::D3D12_FILTER_TYPE_POINT, |
| 84 |
wgt::FilterMode::Linear => Direct3D12::D3D12_FILTER_TYPE_LINEAR, |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
pub fn map_comparison(func: wgt::CompareFunction) -> Direct3D12::D3D12_COMPARISON_FUNC { |
| 89 |
use wgt::CompareFunction as Cf; |
| 90 |
match func { |
| 91 |
Cf::Never => Direct3D12::D3D12_COMPARISON_FUNC_NEVER, |
| 92 |
Cf::Less => Direct3D12::D3D12_COMPARISON_FUNC_LESS, |
| 93 |
Cf::LessEqual => Direct3D12::D3D12_COMPARISON_FUNC_LESS_EQUAL, |
| 94 |
Cf::Equal => Direct3D12::D3D12_COMPARISON_FUNC_EQUAL, |
| 95 |
Cf::GreaterEqual => Direct3D12::D3D12_COMPARISON_FUNC_GREATER_EQUAL, |
| 96 |
Cf::Greater => Direct3D12::D3D12_COMPARISON_FUNC_GREATER, |
| 97 |
Cf::NotEqual => Direct3D12::D3D12_COMPARISON_FUNC_NOT_EQUAL, |
| 98 |
Cf::Always => Direct3D12::D3D12_COMPARISON_FUNC_ALWAYS, |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
pub fn map_border_color(border_color: Option<wgt::SamplerBorderColor>) -> [f32; 4] { |
| 103 |
use wgt::SamplerBorderColor as Sbc; |
| 104 |
match border_color { |
| 105 |
Some(Sbc::TransparentBlack) | Some(Sbc::Zero) | None => [0.0; 4], |
| 106 |
Some(Sbc::OpaqueBlack) => [0.0, 0.0, 0.0, 1.0], |
| 107 |
Some(Sbc::OpaqueWhite) => [1.0; 4], |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
pub fn map_visibility(visibility: wgt::ShaderStages) -> Direct3D12::D3D12_SHADER_VISIBILITY { |
| 112 |
match visibility { |
| 113 |
wgt::ShaderStages::VERTEX => Direct3D12::D3D12_SHADER_VISIBILITY_VERTEX, |
| 114 |
wgt::ShaderStages::FRAGMENT => Direct3D12::D3D12_SHADER_VISIBILITY_PIXEL, |
| 115 |
_ => Direct3D12::D3D12_SHADER_VISIBILITY_ALL, |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
pub fn map_binding_type(ty: &wgt::BindingType) -> Direct3D12::D3D12_DESCRIPTOR_RANGE_TYPE { |
| 120 |
use wgt::BindingType as Bt; |
| 121 |
match *ty { |
| 122 |
Bt::Sampler { .. } => Direct3D12::D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, |
| 123 |
Bt::Buffer { |
| 124 |
ty: wgt::BufferBindingType::Uniform, |
| 125 |
.. |
| 126 |
} => Direct3D12::D3D12_DESCRIPTOR_RANGE_TYPE_CBV, |
| 127 |
Bt::Buffer { |
| 128 |
ty: wgt::BufferBindingType::Storage { read_only: true }, |
| 129 |
.. |
| 130 |
} |
| 131 |
| Bt::Texture { .. } => Direct3D12::D3D12_DESCRIPTOR_RANGE_TYPE_SRV, |
| 132 |
Bt::Buffer { |
| 133 |
ty: wgt::BufferBindingType::Storage { read_only: false }, |
| 134 |
.. |
| 135 |
} |
| 136 |
| Bt::StorageTexture { .. } => Direct3D12::D3D12_DESCRIPTOR_RANGE_TYPE_UAV, |
| 137 |
Bt::AccelerationStructure { .. } => Direct3D12::D3D12_DESCRIPTOR_RANGE_TYPE_SRV, |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
pub fn map_buffer_usage_to_state(usage: wgt::BufferUses) -> Direct3D12::D3D12_RESOURCE_STATES { |
| 142 |
use wgt::BufferUses as Bu; |
| 143 |
let mut state = Direct3D12::D3D12_RESOURCE_STATE_COMMON; |
| 144 |
|
| 145 |
if usage.intersects(Bu::COPY_SRC) { |
| 146 |
state |= Direct3D12::D3D12_RESOURCE_STATE_COPY_SOURCE; |
| 147 |
} |
| 148 |
if usage.intersects(Bu::COPY_DST) { |
| 149 |
state |= Direct3D12::D3D12_RESOURCE_STATE_COPY_DEST; |
| 150 |
} |
| 151 |
if usage.intersects(Bu::INDEX) { |
| 152 |
state |= Direct3D12::D3D12_RESOURCE_STATE_INDEX_BUFFER; |
| 153 |
} |
| 154 |
if usage.intersects(Bu::VERTEX | Bu::UNIFORM) { |
| 155 |
state |= Direct3D12::D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER; |
| 156 |
} |
| 157 |
if usage.intersects(Bu::STORAGE_READ_WRITE) { |
| 158 |
state |= Direct3D12::D3D12_RESOURCE_STATE_UNORDERED_ACCESS; |
| 159 |
} else if usage.intersects(Bu::STORAGE_READ_ONLY) { |
| 160 |
state |= Direct3D12::D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE |
| 161 |
| Direct3D12::D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; |
| 162 |
} |
| 163 |
if usage.intersects(Bu::INDIRECT) { |
| 164 |
state |= Direct3D12::D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT; |
| 165 |
} |
| 166 |
if usage.intersects(Bu::ACCELERATION_STRUCTURE_QUERY) { |
| 167 |
state |= Direct3D12::D3D12_RESOURCE_STATE_UNORDERED_ACCESS; |
| 168 |
} |
| 169 |
state |
| 170 |
} |
| 171 |
|
| 172 |
pub fn map_texture_usage_to_state(usage: wgt::TextureUses) -> Direct3D12::D3D12_RESOURCE_STATES { |
| 173 |
use wgt::TextureUses as Tu; |
| 174 |
let mut state = Direct3D12::D3D12_RESOURCE_STATE_COMMON; |
| 175 |
//Note: `RESOLVE_SOURCE` and `RESOLVE_DEST` are not used here |
| 176 |
//Note: `PRESENT` is the same as `COMMON` |
| 177 |
if usage == wgt::TextureUses::UNINITIALIZED { |
| 178 |
return state; |
| 179 |
} |
| 180 |
|
| 181 |
if usage.intersects(Tu::COPY_SRC) { |
| 182 |
state |= Direct3D12::D3D12_RESOURCE_STATE_COPY_SOURCE; |
| 183 |
} |
| 184 |
if usage.intersects(Tu::COPY_DST) { |
| 185 |
state |= Direct3D12::D3D12_RESOURCE_STATE_COPY_DEST; |
| 186 |
} |
| 187 |
if usage.intersects(Tu::RESOURCE) { |
| 188 |
state |= Direct3D12::D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE |
| 189 |
| Direct3D12::D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; |
| 190 |
} |
| 191 |
if usage.intersects(Tu::COLOR_TARGET) { |
| 192 |
state |= Direct3D12::D3D12_RESOURCE_STATE_RENDER_TARGET; |
| 193 |
} |
| 194 |
if usage.intersects(Tu::DEPTH_STENCIL_READ) { |
| 195 |
state |= Direct3D12::D3D12_RESOURCE_STATE_DEPTH_READ; |
| 196 |
} |
| 197 |
if usage.intersects(Tu::DEPTH_STENCIL_WRITE) { |
| 198 |
state |= Direct3D12::D3D12_RESOURCE_STATE_DEPTH_WRITE; |
| 199 |
} |
| 200 |
if usage.intersects(Tu::STORAGE_READ_ONLY | Tu::STORAGE_WRITE_ONLY | Tu::STORAGE_READ_WRITE) { |
| 201 |
state |= Direct3D12::D3D12_RESOURCE_STATE_UNORDERED_ACCESS; |
| 202 |
} |
| 203 |
state |
| 204 |
} |
| 205 |
|
| 206 |
pub fn map_topology( |
| 207 |
topology: wgt::PrimitiveTopology, |
| 208 |
) -> ( |
| 209 |
Direct3D12::D3D12_PRIMITIVE_TOPOLOGY_TYPE, |
| 210 |
Direct3D::D3D_PRIMITIVE_TOPOLOGY, |
| 211 |
) { |
| 212 |
match topology { |
| 213 |
wgt::PrimitiveTopology::PointList => ( |
| 214 |
Direct3D12::D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT, |
| 215 |
Direct3D::D3D_PRIMITIVE_TOPOLOGY_POINTLIST, |
| 216 |
), |
| 217 |
wgt::PrimitiveTopology::LineList => ( |
| 218 |
Direct3D12::D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE, |
| 219 |
Direct3D::D3D_PRIMITIVE_TOPOLOGY_LINELIST, |
| 220 |
), |
| 221 |
wgt::PrimitiveTopology::LineStrip => ( |
| 222 |
Direct3D12::D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE, |
| 223 |
Direct3D::D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, |
| 224 |
), |
| 225 |
wgt::PrimitiveTopology::TriangleList => ( |
| 226 |
Direct3D12::D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, |
| 227 |
Direct3D::D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, |
| 228 |
), |
| 229 |
wgt::PrimitiveTopology::TriangleStrip => ( |
| 230 |
Direct3D12::D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, |
| 231 |
Direct3D::D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, |
| 232 |
), |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
pub fn map_polygon_mode(mode: wgt::PolygonMode) -> Direct3D12::D3D12_FILL_MODE { |
| 237 |
match mode { |
| 238 |
wgt::PolygonMode::Fill => Direct3D12::D3D12_FILL_MODE_SOLID, |
| 239 |
wgt::PolygonMode::Line => Direct3D12::D3D12_FILL_MODE_WIREFRAME, |
| 240 |
wgt::PolygonMode::Point => panic!( |
| 241 |
"{:?} is not enabled for this backend", |
| 242 |
wgt::Features::POLYGON_MODE_POINT |
| 243 |
), |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
/// D3D12 doesn't support passing factors ending in `_COLOR` for alpha blending |
| 248 |
/// (see <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_render_target_blend_desc>). |
| 249 |
/// Therefore this function takes an additional `is_alpha` argument |
| 250 |
/// which if set will return an equivalent `_ALPHA` factor. |
| 251 |
fn map_blend_factor(factor: wgt::BlendFactor, is_alpha: bool) -> Direct3D12::D3D12_BLEND { |
| 252 |
use wgt::BlendFactor as Bf; |
| 253 |
match factor { |
| 254 |
Bf::Zero => Direct3D12::D3D12_BLEND_ZERO, |
| 255 |
Bf::One => Direct3D12::D3D12_BLEND_ONE, |
| 256 |
Bf::Src if is_alpha => Direct3D12::D3D12_BLEND_SRC_ALPHA, |
| 257 |
Bf::Src => Direct3D12::D3D12_BLEND_SRC_COLOR, |
| 258 |
Bf::OneMinusSrc if is_alpha => Direct3D12::D3D12_BLEND_INV_SRC_ALPHA, |
| 259 |
Bf::OneMinusSrc => Direct3D12::D3D12_BLEND_INV_SRC_COLOR, |
| 260 |
Bf::Dst if is_alpha => Direct3D12::D3D12_BLEND_DEST_ALPHA, |
| 261 |
Bf::Dst => Direct3D12::D3D12_BLEND_DEST_COLOR, |
| 262 |
Bf::OneMinusDst if is_alpha => Direct3D12::D3D12_BLEND_INV_DEST_ALPHA, |
| 263 |
Bf::OneMinusDst => Direct3D12::D3D12_BLEND_INV_DEST_COLOR, |
| 264 |
Bf::SrcAlpha => Direct3D12::D3D12_BLEND_SRC_ALPHA, |
| 265 |
Bf::OneMinusSrcAlpha => Direct3D12::D3D12_BLEND_INV_SRC_ALPHA, |
| 266 |
Bf::DstAlpha => Direct3D12::D3D12_BLEND_DEST_ALPHA, |
| 267 |
Bf::OneMinusDstAlpha => Direct3D12::D3D12_BLEND_INV_DEST_ALPHA, |
| 268 |
Bf::Constant => Direct3D12::D3D12_BLEND_BLEND_FACTOR, |
| 269 |
Bf::OneMinusConstant => Direct3D12::D3D12_BLEND_INV_BLEND_FACTOR, |
| 270 |
Bf::SrcAlphaSaturated => Direct3D12::D3D12_BLEND_SRC_ALPHA_SAT, |
| 271 |
Bf::Src1 if is_alpha => Direct3D12::D3D12_BLEND_SRC1_ALPHA, |
| 272 |
Bf::Src1 => Direct3D12::D3D12_BLEND_SRC1_COLOR, |
| 273 |
Bf::OneMinusSrc1 if is_alpha => Direct3D12::D3D12_BLEND_INV_SRC1_ALPHA, |
| 274 |
Bf::OneMinusSrc1 => Direct3D12::D3D12_BLEND_INV_SRC1_COLOR, |
| 275 |
Bf::Src1Alpha => Direct3D12::D3D12_BLEND_SRC1_ALPHA, |
| 276 |
Bf::OneMinusSrc1Alpha => Direct3D12::D3D12_BLEND_INV_SRC1_ALPHA, |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
fn map_blend_component( |
| 281 |
component: &wgt::BlendComponent, |
| 282 |
is_alpha: bool, |
| 283 |
) -> ( |
| 284 |
Direct3D12::D3D12_BLEND_OP, |
| 285 |
Direct3D12::D3D12_BLEND, |
| 286 |
Direct3D12::D3D12_BLEND, |
| 287 |
) { |
| 288 |
let raw_op = match component.operation { |
| 289 |
wgt::BlendOperation::Add => Direct3D12::D3D12_BLEND_OP_ADD, |
| 290 |
wgt::BlendOperation::Subtract => Direct3D12::D3D12_BLEND_OP_SUBTRACT, |
| 291 |
wgt::BlendOperation::ReverseSubtract => Direct3D12::D3D12_BLEND_OP_REV_SUBTRACT, |
| 292 |
wgt::BlendOperation::Min => Direct3D12::D3D12_BLEND_OP_MIN, |
| 293 |
wgt::BlendOperation::Max => Direct3D12::D3D12_BLEND_OP_MAX, |
| 294 |
}; |
| 295 |
let raw_src = map_blend_factor(component.src_factor, is_alpha); |
| 296 |
let raw_dst = map_blend_factor(component.dst_factor, is_alpha); |
| 297 |
(raw_op, raw_src, raw_dst) |
| 298 |
} |
| 299 |
|
| 300 |
pub fn map_render_targets( |
| 301 |
color_targets: &[Option<wgt::ColorTargetState>], |
| 302 |
) -> [Direct3D12::D3D12_RENDER_TARGET_BLEND_DESC; |
| 303 |
Direct3D12::D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT as usize] { |
| 304 |
let dummy_target = Direct3D12::D3D12_RENDER_TARGET_BLEND_DESC { |
| 305 |
BlendEnable: false.into(), |
| 306 |
LogicOpEnable: false.into(), |
| 307 |
SrcBlend: Direct3D12::D3D12_BLEND_ZERO, |
| 308 |
DestBlend: Direct3D12::D3D12_BLEND_ZERO, |
| 309 |
BlendOp: Direct3D12::D3D12_BLEND_OP_ADD, |
| 310 |
SrcBlendAlpha: Direct3D12::D3D12_BLEND_ZERO, |
| 311 |
DestBlendAlpha: Direct3D12::D3D12_BLEND_ZERO, |
| 312 |
BlendOpAlpha: Direct3D12::D3D12_BLEND_OP_ADD, |
| 313 |
LogicOp: Direct3D12::D3D12_LOGIC_OP_CLEAR, |
| 314 |
RenderTargetWriteMask: 0, |
| 315 |
}; |
| 316 |
let mut raw_targets = |
| 317 |
[dummy_target; Direct3D12::D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT as usize]; |
| 318 |
|
| 319 |
for (raw, ct) in raw_targets.iter_mut().zip(color_targets.iter()) { |
| 320 |
if let Some(ct) = ct.as_ref() { |
| 321 |
raw.RenderTargetWriteMask = ct.write_mask.bits() as u8; |
| 322 |
if let Some(ref blend) = ct.blend { |
| 323 |
let (color_op, color_src, color_dst) = map_blend_component(&blend.color, false); |
| 324 |
let (alpha_op, alpha_src, alpha_dst) = map_blend_component(&blend.alpha, true); |
| 325 |
raw.BlendEnable = true.into(); |
| 326 |
raw.BlendOp = color_op; |
| 327 |
raw.SrcBlend = color_src; |
| 328 |
raw.DestBlend = color_dst; |
| 329 |
raw.BlendOpAlpha = alpha_op; |
| 330 |
raw.SrcBlendAlpha = alpha_src; |
| 331 |
raw.DestBlendAlpha = alpha_dst; |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
raw_targets |
| 337 |
} |
| 338 |
|
| 339 |
fn map_stencil_op(op: wgt::StencilOperation) -> Direct3D12::D3D12_STENCIL_OP { |
| 340 |
use wgt::StencilOperation as So; |
| 341 |
match op { |
| 342 |
So::Keep => Direct3D12::D3D12_STENCIL_OP_KEEP, |
| 343 |
So::Zero => Direct3D12::D3D12_STENCIL_OP_ZERO, |
| 344 |
So::Replace => Direct3D12::D3D12_STENCIL_OP_REPLACE, |
| 345 |
So::IncrementClamp => Direct3D12::D3D12_STENCIL_OP_INCR_SAT, |
| 346 |
So::IncrementWrap => Direct3D12::D3D12_STENCIL_OP_INCR, |
| 347 |
So::DecrementClamp => Direct3D12::D3D12_STENCIL_OP_DECR_SAT, |
| 348 |
So::DecrementWrap => Direct3D12::D3D12_STENCIL_OP_DECR, |
| 349 |
So::Invert => Direct3D12::D3D12_STENCIL_OP_INVERT, |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
fn map_stencil_face(face: &wgt::StencilFaceState) -> Direct3D12::D3D12_DEPTH_STENCILOP_DESC { |
| 354 |
Direct3D12::D3D12_DEPTH_STENCILOP_DESC { |
| 355 |
StencilFailOp: map_stencil_op(face.fail_op), |
| 356 |
StencilDepthFailOp: map_stencil_op(face.depth_fail_op), |
| 357 |
StencilPassOp: map_stencil_op(face.pass_op), |
| 358 |
StencilFunc: map_comparison(face.compare), |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
pub fn map_depth_stencil(ds: &wgt::DepthStencilState) -> Direct3D12::D3D12_DEPTH_STENCIL_DESC { |
| 363 |
Direct3D12::D3D12_DEPTH_STENCIL_DESC { |
| 364 |
DepthEnable: ds.is_depth_enabled().into(), |
| 365 |
DepthWriteMask: if ds.depth_write_enabled { |
| 366 |
Direct3D12::D3D12_DEPTH_WRITE_MASK_ALL |
| 367 |
} else { |
| 368 |
Direct3D12::D3D12_DEPTH_WRITE_MASK_ZERO |
| 369 |
}, |
| 370 |
DepthFunc: map_comparison(ds.depth_compare), |
| 371 |
StencilEnable: ds.stencil.is_enabled().into(), |
| 372 |
StencilReadMask: ds.stencil.read_mask as u8, |
| 373 |
StencilWriteMask: ds.stencil.write_mask as u8, |
| 374 |
FrontFace: map_stencil_face(&ds.stencil.front), |
| 375 |
BackFace: map_stencil_face(&ds.stencil.back), |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
pub(crate) fn map_acceleration_structure_build_flags( |
| 380 |
flags: wgt::AccelerationStructureFlags, |
| 381 |
mode: Option<crate::AccelerationStructureBuildMode>, |
| 382 |
) -> Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS { |
| 383 |
let mut d3d_flags = Default::default(); |
| 384 |
if flags.contains(wgt::AccelerationStructureFlags::ALLOW_COMPACTION) { |
| 385 |
d3d_flags |= |
| 386 |
Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_ALLOW_COMPACTION; |
| 387 |
} |
| 388 |
|
| 389 |
if flags.contains(wgt::AccelerationStructureFlags::ALLOW_UPDATE) { |
| 390 |
d3d_flags |= Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_ALLOW_UPDATE; |
| 391 |
} |
| 392 |
|
| 393 |
if flags.contains(wgt::AccelerationStructureFlags::LOW_MEMORY) { |
| 394 |
d3d_flags |= Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_MINIMIZE_MEMORY; |
| 395 |
} |
| 396 |
|
| 397 |
if flags.contains(wgt::AccelerationStructureFlags::PREFER_FAST_BUILD) { |
| 398 |
d3d_flags |= |
| 399 |
Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_BUILD; |
| 400 |
} |
| 401 |
|
| 402 |
if flags.contains(wgt::AccelerationStructureFlags::PREFER_FAST_TRACE) { |
| 403 |
d3d_flags |= |
| 404 |
Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_TRACE; |
| 405 |
} |
| 406 |
|
| 407 |
if let Some(crate::AccelerationStructureBuildMode::Update) = mode { |
| 408 |
d3d_flags |= Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PERFORM_UPDATE |
| 409 |
} |
| 410 |
|
| 411 |
d3d_flags |
| 412 |
} |
| 413 |
|
| 414 |
pub(crate) fn map_acceleration_structure_geometry_flags( |
| 415 |
flags: wgt::AccelerationStructureGeometryFlags, |
| 416 |
) -> Direct3D12::D3D12_RAYTRACING_GEOMETRY_FLAGS { |
| 417 |
let mut d3d_flags = Default::default(); |
| 418 |
if flags.contains(wgt::AccelerationStructureGeometryFlags::OPAQUE) { |
| 419 |
d3d_flags |= Direct3D12::D3D12_RAYTRACING_GEOMETRY_FLAG_OPAQUE; |
| 420 |
} |
| 421 |
if flags.contains(wgt::AccelerationStructureGeometryFlags::NO_DUPLICATE_ANY_HIT_INVOCATION) { |
| 422 |
d3d_flags |= Direct3D12::D3D12_RAYTRACING_GEOMETRY_FLAG_NO_DUPLICATE_ANYHIT_INVOCATION; |
| 423 |
} |
| 424 |
d3d_flags |
| 425 |
} |
| 426 |
|
| 427 |
pub(crate) fn map_acceleration_structure_copy_mode( |
| 428 |
mode: wgt::AccelerationStructureCopy, |
| 429 |
) -> Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE { |
| 430 |
match mode { |
| 431 |
wgt::AccelerationStructureCopy::Clone => { |
| 432 |
Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_CLONE |
| 433 |
} |
| 434 |
wgt::AccelerationStructureCopy::Compact => { |
| 435 |
Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_COMPACT |
| 436 |
} |
| 437 |
} |
| 438 |
} |