Skip to content

Commit

Permalink
Merge #2336
Browse files Browse the repository at this point in the history
2336: [mtl] Fix A2BGR10 format mapping r=kvark a=kvark

Fixes Dota2 after #2116 
PR checklist:
- [ ] `make` succeeds (on *nix)
- [ ] `make reftests` succeeds
- [ ] tested examples with the following backends:
- [ ] `rustfmt` run on changed code


Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
  • Loading branch information
bors[bot] and kvark committed Aug 24, 2018
2 parents 174a4ff + 588384b commit 184273d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 37 deletions.
49 changes: 32 additions & 17 deletions src/backend/metal/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3343,11 +3343,16 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
retained_textures.last().unwrap()
};

let commands = regions.into_iter().map(|region| {
soft::BlitCommand::CopyImage {
src: AsNative::from(new_src),
dst: AsNative::from(dst.raw.as_ref()),
region: region.borrow().clone(),
let commands = regions.into_iter().filter_map(|region| {
let r = region.borrow();
if r.extent.is_empty() {
None
} else {
Some(soft::BlitCommand::CopyImage {
src: AsNative::from(new_src),
dst: AsNative::from(dst.raw.as_ref()),
region: r.clone(),
})
}
});
sink.as_mut()
Expand All @@ -3366,12 +3371,17 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
T::Item: Borrow<com::BufferImageCopy>,
{
// FIXME: layout
let commands = regions.into_iter().map(|region| {
soft::BlitCommand::CopyBufferToImage {
src: AsNative::from(src.raw.as_ref()),
dst: AsNative::from(dst.raw.as_ref()),
dst_desc: dst.format_desc,
region: region.borrow().clone(),
let commands = regions.into_iter().filter_map(|region| {
let r = region.borrow();
if r.image_extent.is_empty() {
None
} else {
Some(soft::BlitCommand::CopyBufferToImage {
src: AsNative::from(src.raw.as_ref()),
dst: AsNative::from(dst.raw.as_ref()),
dst_desc: dst.format_desc,
region: r.clone(),
})
}
});
self.inner
Expand All @@ -3391,12 +3401,17 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
T::Item: Borrow<com::BufferImageCopy>,
{
// FIXME: layout
let commands = regions.into_iter().map(|region| {
soft::BlitCommand::CopyImageToBuffer {
src: AsNative::from(src.raw.as_ref()),
src_desc: src.format_desc,
dst: AsNative::from(dst.raw.as_ref()),
region: region.borrow().clone(),
let commands = regions.into_iter().filter_map(|region| {
let r = region.borrow();
if r.image_extent.is_empty() {
None
} else {
Some(soft::BlitCommand::CopyImageToBuffer {
src: AsNative::from(src.raw.as_ref()),
src_desc: src.format_desc,
dst: AsNative::from(dst.raw.as_ref()),
region: r.clone(),
})
}
});
self.inner
Expand Down
36 changes: 17 additions & 19 deletions src/backend/metal/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl PrivateCapabilities {
f::Rgba8Srgb if self.format_min_srgb_channels <= 4 => RGBA8Unorm_sRGB,
f::Bgra8Srgb if self.format_min_srgb_channels <= 4 => BGRA8Unorm_sRGB,
f::D24UnormS8Uint if self.format_depth24_stencil8 => Depth24Unorm_Stencil8,
f::D32FloatS8Uint if self.format_depth32_stencil8_filter || self.format_depth32_stencil8_none => Depth32Float_Stencil8,
f::D32FloatS8Uint if self.format_depth32_stencil8_filter => Depth32Float_Stencil8,
f::R8Unorm => R8Unorm,
f::R8Inorm => R8Snorm,
f::R8Uint => R8Uint,
Expand Down Expand Up @@ -46,8 +46,8 @@ impl PrivateCapabilities {
f::Rgba16Uint => RGBA16Uint,
f::Rgba16Int => RGBA16Sint,
f::Rgba16Float => RGBA16Float,
f::A2r10g10b10Unorm => RGB10A2Unorm,
f::A2r10g10b10Uint => RGB10A2Uint,
f::A2r10g10b10Unorm => BGR10A2Unorm,
f::A2b10g10r10Unorm => RGB10A2Unorm,
f::B10g11r11Ufloat => RG11B10Float,
f::E5b9g9r9Ufloat => RGB9E5Float,
f::R32Uint => R32Uint,
Expand Down Expand Up @@ -885,12 +885,14 @@ impl PrivateCapabilities {
..defaults
},
Depth16Unorm if self.format_depth16unorm => Properties {
optimal_tiling: defaults.optimal_tiling
optimal_tiling: defaults.optimal_tiling
| If::DEPTH_STENCIL_ATTACHMENT
| If::SAMPLED_LINEAR,
..defaults
},
Depth32Float if self.format_depth32float_filter => Properties {
optimal_tiling: defaults.optimal_tiling
optimal_tiling: defaults.optimal_tiling
| If::DEPTH_STENCIL_ATTACHMENT
| If::SAMPLED_LINEAR,
..defaults
},
Expand All @@ -903,12 +905,13 @@ impl PrivateCapabilities {
..defaults
},
Depth24Unorm_Stencil8 if self.format_depth24_stencil8 => Properties {
optimal_tiling: defaults.optimal_tiling
| If::SAMPLED_LINEAR,
optimal_tiling: defaults.optimal_tiling
| If::DEPTH_STENCIL_ATTACHMENT,
..defaults
},
Depth32Float_Stencil8 if self.format_depth32_stencil8_filter => Properties {
optimal_tiling: defaults.optimal_tiling
optimal_tiling: defaults.optimal_tiling
| If::DEPTH_STENCIL_ATTACHMENT
| If::SAMPLED_LINEAR,
..defaults
},
Expand Down Expand Up @@ -1106,17 +1109,12 @@ pub fn map_texture_usage(usage: image::Usage, tiling: image::Tiling) -> MTLTextu
texture_usage |= MTLTextureUsage::ShaderRead | MTLTextureUsage::ShaderWrite;
}

match tiling {
image::Tiling::Optimal => {
// Note: for blitting, we do actual rendering, so we add more flags for TRANSFER_* usage
if usage.contains(U::TRANSFER_DST) {
texture_usage |= MTLTextureUsage::RenderTarget;
}
if usage.contains(U::TRANSFER_SRC) {
texture_usage |= MTLTextureUsage::ShaderRead;
}
}
image::Tiling::Linear => {}
// Note: for blitting, we do actual rendering, so we add more flags for TRANSFER_* usage
if usage.contains(U::TRANSFER_DST) && tiling == image::Tiling::Optimal {
texture_usage |= MTLTextureUsage::RenderTarget;
}
if usage.contains(U::TRANSFER_SRC) {
texture_usage |= MTLTextureUsage::ShaderRead;
}

texture_usage
Expand Down
1 change: 1 addition & 0 deletions src/backend/metal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,7 @@ impl hal::Device<Backend> for Device {
descriptor.set_pixel_format(mtl_format);
descriptor.set_resource_options(buffer.res_options);
descriptor.set_storage_mode(buffer.raw.storage_mode());
descriptor.set_usage(metal::MTLTextureUsage::ShaderRead);

let size = block_count * (format_desc.bits as u64 / 8);
let stride = (size + STRIDE_MASK) & !STRIDE_MASK;
Expand Down
3 changes: 2 additions & 1 deletion src/backend/metal/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ impl hal::Surface<Backend> for Surface {
current_extent,
extents: Extent2D { width: 4, height: 4} .. Extent2D { width: 4096, height: 4096 },
max_image_layers: 1,
usage: image::Usage::COLOR_ATTACHMENT | image::Usage::TRANSFER_SRC,
usage: image::Usage::COLOR_ATTACHMENT | image::Usage::SAMPLED |
image::Usage::TRANSFER_SRC | image::Usage::TRANSFER_DST,
};

let formats = vec![
Expand Down
4 changes: 4 additions & 0 deletions src/hal/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct Extent {
}

impl Extent {
/// Return true if one of the dimensions is zero.
pub fn is_empty(&self) -> bool {
self.width == 0 || self.height == 0 || self.depth == 0
}
/// Get the extent at a particular mipmap level.
pub fn at_level(&self, level: Level) -> Self {
Extent {
Expand Down

0 comments on commit 184273d

Please sign in to comment.