Skip to content

Commit

Permalink
Merge #2037
Browse files Browse the repository at this point in the history
2037: Format packing semantics, dx12 handling r=msiglreith a=kvark

Fixes all of the image related copy/blit CTS tests (>11K passes!). There are 0 failures in this category now and ~5 crashes due to #1945.

PR checklist:
- [ ] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [ ] tested examples with the following backends:


Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
  • Loading branch information
bors[bot] and kvark committed May 17, 2018
2 parents f4c9f53 + 9c15cc9 commit 8d2b93a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
27 changes: 19 additions & 8 deletions src/backend/dx12/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ use hal::format::{Format, ImageFeature, SurfaceType};
use hal::{buffer, image, pso, Primitive};
use hal::pso::DescriptorSetLayoutBinding;


pub fn map_format(format: Format) -> Option<DXGI_FORMAT> {
use hal::format::Format::*;

// TODO: list may be incomplete or partially wrong..
// Handling packed formats according to the platform endianness.
let reverse = unsafe { 1 == *(&1u32 as *const _ as *const u8) };
let format = match format {
Bgra4Unorm => DXGI_FORMAT_B4G4R4A4_UNORM,
R5g6b5Unorm => DXGI_FORMAT_B5G6R5_UNORM,
R5g5b5a1Unorm => DXGI_FORMAT_B5G5R5A1_UNORM,
Bgra4Unorm if !reverse => DXGI_FORMAT_B4G4R4A4_UNORM,
R5g6b5Unorm if reverse => DXGI_FORMAT_B5G6R5_UNORM,
B5g6r5Unorm if !reverse => DXGI_FORMAT_B5G6R5_UNORM,
B5g5r5a1Unorm if !reverse => DXGI_FORMAT_B5G5R5A1_UNORM,
A1r5g5b5Unorm if reverse => DXGI_FORMAT_B5G5R5A1_UNORM,
R8Unorm => DXGI_FORMAT_R8_UNORM,
R8Inorm => DXGI_FORMAT_R8_SNORM,
R8Uint => DXGI_FORMAT_R8_UINT,
Expand All @@ -34,8 +38,13 @@ pub fn map_format(format: Format) -> Option<DXGI_FORMAT> {
Rgba8Srgb => DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
Bgra8Unorm => DXGI_FORMAT_B8G8R8A8_UNORM,
Bgra8Srgb => DXGI_FORMAT_B8G8R8A8_UNORM_SRGB,
A2b10g10r10Unorm => DXGI_FORMAT_R10G10B10A2_UNORM,
A2b10g10r10Uint => DXGI_FORMAT_R10G10B10A2_UINT,
Abgr8Unorm if reverse => DXGI_FORMAT_R8G8B8A8_UNORM,
Abgr8Inorm if reverse => DXGI_FORMAT_R8G8B8A8_SNORM,
Abgr8Uint if reverse => DXGI_FORMAT_R8G8B8A8_UINT,
Abgr8Int if reverse => DXGI_FORMAT_R8G8B8A8_SINT,
Abgr8Srgb if reverse => DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
A2b10g10r10Unorm if reverse => DXGI_FORMAT_R10G10B10A2_UNORM,
A2b10g10r10Uint if reverse => DXGI_FORMAT_R10G10B10A2_UINT,
R16Unorm => DXGI_FORMAT_R16_UNORM,
R16Inorm => DXGI_FORMAT_R16_SNORM,
R16Uint => DXGI_FORMAT_R16_UINT,
Expand Down Expand Up @@ -63,9 +72,11 @@ pub fn map_format(format: Format) -> Option<DXGI_FORMAT> {
Rgba32Uint => DXGI_FORMAT_R32G32B32A32_UINT,
Rgba32Int => DXGI_FORMAT_R32G32B32A32_SINT,
Rgba32Float => DXGI_FORMAT_R32G32B32A32_FLOAT,
B10g11r11Ufloat => DXGI_FORMAT_R11G11B10_FLOAT,
E5b9g9r9Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
B10g11r11Ufloat if reverse => DXGI_FORMAT_R11G11B10_FLOAT,
E5b9g9r9Ufloat if reverse => DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
D16Unorm => DXGI_FORMAT_D16_UNORM,
D24UnormS8Uint => DXGI_FORMAT_D24_UNORM_S8_UINT,
X8D24Unorm if reverse => DXGI_FORMAT_D24_UNORM_S8_UINT,
D32Float => DXGI_FORMAT_D32_FLOAT,
D32FloatS8Uint => DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
Bc1RgbUnorm => DXGI_FORMAT_BC1_UNORM,
Expand Down
12 changes: 8 additions & 4 deletions src/backend/dx12/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(crate) fn shader_bytecode(shader: *mut d3dcommon::ID3DBlob) -> d3d12::D3D12_
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct ViewInfo {
pub(crate) resource: *mut d3d12::ID3D12Resource,
pub(crate) kind: image::Kind,
Expand Down Expand Up @@ -1734,6 +1734,10 @@ impl d::Device<B> for Device {
// on descriptor updates.
size = (size + 255) & !255;
}
if usage.contains(buffer::Usage::TRANSFER_DST) {
// minimum of 1 word for the clear UAV
size = size.max(4);
}

let type_mask_shift = if self.private_caps.heterogeneous_resource_heaps {
MEM_TYPE_UNIVERSAL_SHIFT
Expand Down Expand Up @@ -1803,13 +1807,13 @@ impl d::Device<B> for Device {

let clear_uav = if buffer.usage.contains(buffer::Usage::TRANSFER_DST) {
let handles = self.uav_pool.lock().unwrap().alloc_handles(1);
let mut desc = d3d12::D3D12_UNORDERED_ACCESS_VIEW_DESC {
let mut view_desc = d3d12::D3D12_UNORDERED_ACCESS_VIEW_DESC {
Format: dxgiformat::DXGI_FORMAT_R32_TYPELESS,
ViewDimension: d3d12::D3D12_UAV_DIMENSION_BUFFER,
u: unsafe { mem::zeroed() },
};

*unsafe { desc.u.Buffer_mut() } = d3d12::D3D12_BUFFER_UAV {
*unsafe { view_desc.u.Buffer_mut() } = d3d12::D3D12_BUFFER_UAV {
FirstElement: 0,
NumElements: (buffer.requirements.size / 4) as _,
StructureByteStride: 0,
Expand All @@ -1821,7 +1825,7 @@ impl d::Device<B> for Device {
self.raw.clone().CreateUnorderedAccessView(
resource as *mut _,
ptr::null_mut(),
&desc,
&view_desc,
handles.cpu,
);
}
Expand Down
41 changes: 24 additions & 17 deletions src/hal/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub struct FormatDesc {
pub bits: u16,
/// Dimensions (width, height) of the texel blocks.
pub dim: (u8, u8),
/// The format representation depends on the endianness of the platform.
///
/// * On little-endian systems, the actual oreder of components is reverse of what
/// a surface type specifies.
pub packed: bool,
/// Format aspects
pub aspects: Aspects,
}
Expand Down Expand Up @@ -229,13 +234,14 @@ macro_rules! surface_types {
}
}

///
/// Return the format descriptor.
pub fn desc(&self) -> FormatDesc {
match *self {
$( SurfaceType::$name => FormatDesc {
bits: $total,
aspects: $(Aspects::$aspect)|*,
bits: $total.min(!$total),
dim: $dim,
packed: $total > 0x1000,
aspects: $(Aspects::$aspect)|*,
}, )*
}
}
Expand All @@ -244,24 +250,25 @@ macro_rules! surface_types {
}

// ident { num_bits, aspects, dim, (color, alpha, ..) }
// if the number of bits is given with exclamation (e.g. `!16`), the format is considered packed
surface_types! {
R4_G4 { 8, COLOR, (1, 1), color: 8 },
R4_G4_B4_A4 { 16, COLOR, (1, 1), color: 12, alpha: 4 },
B4_G4_R4_A4 { 16, COLOR, (1, 1), color: 12, alpha: 4 },
R5_G6_B5 { 16, COLOR, (1, 1), color: 16 },
B5_G6_R5 { 16, COLOR, (1, 1), color: 16 },
R5_G5_B5_A1 { 16, COLOR, (1, 1), color: 15, alpha: 1 },
B5_G5_R5_A1 { 16, COLOR, (1, 1), color: 15, alpha: 1 },
A1_R5_G5_B5 { 16, COLOR, (1, 1), color: 15, alpha: 1 },
R4_G4 { !8, COLOR, (1, 1), color: 8 },
R4_G4_B4_A4 { !16, COLOR, (1, 1), color: 12, alpha: 4 },
B4_G4_R4_A4 { !16, COLOR, (1, 1), color: 12, alpha: 4 },
R5_G6_B5 { !16, COLOR, (1, 1), color: 16 },
B5_G6_R5 { !16, COLOR, (1, 1), color: 16 },
R5_G5_B5_A1 { !16, COLOR, (1, 1), color: 15, alpha: 1 },
B5_G5_R5_A1 { !16, COLOR, (1, 1), color: 15, alpha: 1 },
A1_R5_G5_B5 { !16, COLOR, (1, 1), color: 15, alpha: 1 },
R8 { 8, COLOR, (1, 1), color: 8 },
R8_G8 { 16, COLOR, (1, 1), color: 16 },
R8_G8_B8 { 24, COLOR, (1, 1), color: 24 },
B8_G8_R8 { 24, COLOR, (1, 1), color: 24 },
R8_G8_B8_A8 { 32, COLOR, (1, 1), color: 24, alpha: 8 },
B8_G8_R8_A8 { 32, COLOR, (1, 1), color: 24, alpha: 8 },
A8_B8_G8_R8 { 32, COLOR, (1, 1), color: 24, alpha: 8 },
A2_R10_G10_B10 { 32, COLOR, (1, 1), color: 30, alpha: 2 },
A2_B10_G10_R10 { 32, COLOR, (1, 1), color: 30, alpha: 2 },
A8_B8_G8_R8 { !32, COLOR, (1, 1), color: 24, alpha: 8 },
A2_R10_G10_B10 { !32, COLOR, (1, 1), color: 30, alpha: 2 },
A2_B10_G10_R10 { !32, COLOR, (1, 1), color: 30, alpha: 2 },
R16 { 16, COLOR, (1, 1), color: 16 },
R16_G16 { 32, COLOR, (1, 1), color: 32 },
R16_G16_B16 { 48, COLOR, (1, 1), color: 48 },
Expand All @@ -274,10 +281,10 @@ surface_types! {
R64_G64 { 128, COLOR, (1, 1), color: 128 },
R64_G64_B64 { 192, COLOR, (1, 1), color: 192 },
R64_G64_B64_A64 { 256, COLOR, (1, 1), color: 192, alpha: 64 },
B10_G11_R11 { 32, COLOR, (1, 1), color: 32 },
E5_B9_G9_R9 { 32, COLOR, (1, 1), color: 27 }, // 32-bit packed format
B10_G11_R11 { !32, COLOR, (1, 1), color: 32 },
E5_B9_G9_R9 { !32, COLOR, (1, 1), color: 27 },
D16 { 16, DEPTH, (1, 1), depth: 16 },
X8D24 { 32, DEPTH, (1, 1), depth: 24 },
X8D24 { !32, DEPTH, (1, 1), depth: 24 },
D32 { 32, DEPTH, (1, 1), depth: 32 },
S8 { 8, STENCIL, (1, 1), stencil: 8 },
D16_S8 { 24, DEPTH | STENCIL, (1, 1), depth: 16, stencil: 8 },
Expand Down

0 comments on commit 8d2b93a

Please sign in to comment.