| 1 |
#[cfg(dx12)] |
| 2 |
pub(super) mod dxgi; |
| 3 |
|
| 4 |
#[cfg(all(native, feature = "renderdoc"))] |
| 5 |
pub(super) mod renderdoc; |
| 6 |
|
| 7 |
pub mod db { |
| 8 |
pub mod amd { |
| 9 |
/// cbindgen:ignore |
| 10 |
pub const VENDOR: u32 = 0x1002; |
| 11 |
} |
| 12 |
pub mod apple { |
| 13 |
/// cbindgen:ignore |
| 14 |
pub const VENDOR: u32 = 0x106B; |
| 15 |
} |
| 16 |
pub mod arm { |
| 17 |
/// cbindgen:ignore |
| 18 |
pub const VENDOR: u32 = 0x13B5; |
| 19 |
} |
| 20 |
pub mod broadcom { |
| 21 |
/// cbindgen:ignore |
| 22 |
pub const VENDOR: u32 = 0x14E4; |
| 23 |
} |
| 24 |
pub mod imgtec { |
| 25 |
/// cbindgen:ignore |
| 26 |
pub const VENDOR: u32 = 0x1010; |
| 27 |
} |
| 28 |
pub mod intel { |
| 29 |
/// cbindgen:ignore |
| 30 |
pub const VENDOR: u32 = 0x8086; |
| 31 |
pub const DEVICE_KABY_LAKE_MASK: u32 = 0x5900; |
| 32 |
pub const DEVICE_SKY_LAKE_MASK: u32 = 0x1900; |
| 33 |
} |
| 34 |
pub mod mesa { |
| 35 |
// Mesa does not actually have a PCI vendor id. |
| 36 |
// |
| 37 |
// To match Vulkan, we use the VkVendorId for Mesa in the gles backend so that lavapipe (Vulkan) and |
| 38 |
// llvmpipe (OpenGL) have the same vendor id. |
| 39 |
/// cbindgen:ignore |
| 40 |
pub const VENDOR: u32 = 0x10005; |
| 41 |
} |
| 42 |
pub mod nvidia { |
| 43 |
/// cbindgen:ignore |
| 44 |
pub const VENDOR: u32 = 0x10DE; |
| 45 |
} |
| 46 |
pub mod qualcomm { |
| 47 |
/// cbindgen:ignore |
| 48 |
pub const VENDOR: u32 = 0x5143; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/// Maximum binding size for the shaders that only support `i32` indexing. |
| 53 |
/// Interestingly, the index itself can't reach that high, because the minimum |
| 54 |
/// element size is 4 bytes, but the compiler toolchain still computes the |
| 55 |
/// offset at some intermediate point, internally, as i32. |
| 56 |
pub const MAX_I32_BINDING_SIZE: u32 = (1 << 31) - 1; |
| 57 |
|
| 58 |
pub fn map_naga_stage(stage: naga::ShaderStage) -> wgt::ShaderStages { |
| 59 |
match stage { |
| 60 |
naga::ShaderStage::Vertex => wgt::ShaderStages::VERTEX, |
| 61 |
naga::ShaderStage::Fragment => wgt::ShaderStages::FRAGMENT, |
| 62 |
naga::ShaderStage::Compute => wgt::ShaderStages::COMPUTE, |
| 63 |
naga::ShaderStage::Task => wgt::ShaderStages::TASK, |
| 64 |
naga::ShaderStage::Mesh => wgt::ShaderStages::MESH, |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
impl crate::CopyExtent { |
| 69 |
pub fn map_extent_to_copy_size(extent: &wgt::Extent3d, dim: wgt::TextureDimension) -> Self { |
| 70 |
Self { |
| 71 |
width: extent.width, |
| 72 |
height: extent.height, |
| 73 |
depth: match dim { |
| 74 |
wgt::TextureDimension::D1 | wgt::TextureDimension::D2 => 1, |
| 75 |
wgt::TextureDimension::D3 => extent.depth_or_array_layers, |
| 76 |
}, |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
pub fn min(&self, other: &Self) -> Self { |
| 81 |
Self { |
| 82 |
width: self.width.min(other.width), |
| 83 |
height: self.height.min(other.height), |
| 84 |
depth: self.depth.min(other.depth), |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
// Get the copy size at a specific mipmap level. This doesn't make most sense, |
| 89 |
// since the copy extents are provided *for* a mipmap level to start with. |
| 90 |
// But backends use `CopyExtent` more sparingly, and this piece is shared. |
| 91 |
pub fn at_mip_level(&self, level: u32) -> Self { |
| 92 |
Self { |
| 93 |
width: (self.width >> level).max(1), |
| 94 |
height: (self.height >> level).max(1), |
| 95 |
depth: (self.depth >> level).max(1), |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
impl crate::TextureCopyBase { |
| 101 |
pub fn max_copy_size(&self, full_size: &crate::CopyExtent) -> crate::CopyExtent { |
| 102 |
let mip = full_size.at_mip_level(self.mip_level); |
| 103 |
crate::CopyExtent { |
| 104 |
width: mip.width - self.origin.x, |
| 105 |
height: mip.height - self.origin.y, |
| 106 |
depth: mip.depth - self.origin.z, |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
impl crate::BufferTextureCopy { |
| 112 |
pub fn clamp_size_to_virtual(&mut self, full_size: &crate::CopyExtent) { |
| 113 |
let max_size = self.texture_base.max_copy_size(full_size); |
| 114 |
self.size = self.size.min(&max_size); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
impl crate::TextureCopy { |
| 119 |
pub fn clamp_size_to_virtual( |
| 120 |
&mut self, |
| 121 |
full_src_size: &crate::CopyExtent, |
| 122 |
full_dst_size: &crate::CopyExtent, |
| 123 |
) { |
| 124 |
let max_src_size = self.src_base.max_copy_size(full_src_size); |
| 125 |
let max_dst_size = self.dst_base.max_copy_size(full_dst_size); |
| 126 |
self.size = self.size.min(&max_src_size).min(&max_dst_size); |
| 127 |
} |
| 128 |
} |