fix(gpu): read single-sample framebuffers without multisampled storage images, refusing only multisampled framebuffer reads and tile pipelines and making no multisampled texture storage there, and leave a Metal device still in no Apple GPU family unused as AMD's GFX8 is, where ANV, which has no multisampled storage images on any Intel GPU, put the Metal device in no Apple GPU family, Core Animation drew no desktop (a black screen under the cursor) and WindowServer ended at its first InPlaceSover pipeline
This commit is contained in:
1 parent
335f4ea6d6
commit
8ee5d90192
10 files changed
+570
-15
No files matched your search
@@ -1412,7 +1412,8 @@ pub(super) fn served_index(index: usize) -> bool {
|
||||
static FILES_KEPT: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// Whether the bound GPU at `index` keeps a file of a Metal service that
|
||||
/// did not open: its driver's reset during the first submission held it.
|
||||
/// did not open: its driver's reset during the first submission held it,
|
||||
/// or the service opened in no Apple GPU family and was left unused.
|
||||
pub(super) fn file_kept(index: usize) -> bool {
|
||||
index >= 64 || FILES_KEPT.load(Ordering::Relaxed) & (1 << index) != 0
|
||||
}
|
||||
@@ -1587,6 +1588,20 @@ fn open_gpu(gpu: &Installed, index: usize, bound: &Bound) -> Result<Arc<Shared>,
|
||||
bound.name
|
||||
));
|
||||
}
|
||||
// On a Metal device in no Apple GPU family Core Animation draws
|
||||
// no desktop, a black screen under the cursor, and the window
|
||||
// server ends at its first framebuffer read: the device is left
|
||||
// unused, as AMD's GFX8 is (`amd_metal::NO_APPLE_FAMILY`), and
|
||||
// macOS draws with the CPU. The service is kept unreleased with
|
||||
// its driver's file open ([`file_kept`]), as after a reset.
|
||||
if let Some(refusal) = service.no_apple_family() {
|
||||
output::arguments(format_args!("GPU {}: {refusal}\n", bound.name));
|
||||
core::mem::forget(service);
|
||||
if index < 64 {
|
||||
FILES_KEPT.fetch_or(1 << index, Ordering::Relaxed);
|
||||
}
|
||||
return Err(refusal);
|
||||
}
|
||||
// Without a second stack, every compilation stays in its turn.
|
||||
service.set_wait_bound(gpu.tsc_hz / 1000 * WAIT_BOUND_MILLIS);
|
||||
service.set_look_budget(gpu.tsc_hz / 1_000_000 * LOOK_MICROS);
|
||||
|
||||
@@ -28,6 +28,8 @@ use super::{
|
||||
use alloc::{boxed::Box, string::String, vec::Vec};
|
||||
|
||||
pub mod block;
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests;
|
||||
|
||||
option_set! {
|
||||
/// Shader constructs the AIR → NIR → vendor compiler path lowers with
|
||||
@@ -342,6 +344,14 @@ pub struct Capabilities {
|
||||
/// read and write the attachment as storage in a fragment shader
|
||||
/// interlock section.
|
||||
pub framebuffer_reads: bool,
|
||||
/// Storage images are single-sample alone: the driver has no
|
||||
/// multisampled ones (`shaderStorageImageMultisample`, which ANV reports
|
||||
/// on no Intel GPU). Multisampled textures then have no storage views,
|
||||
/// and framebuffer reads, which read and write an attachment's samples
|
||||
/// through them, reach single-sample attachments alone: a pipeline that
|
||||
/// would access a multisampled attachment as storage, and a multisampled
|
||||
/// tile pipeline, are refused ([`Capabilities::framebuffer_reads_at`]).
|
||||
pub single_sample_storage: bool,
|
||||
/// Fragment functions can run the fragment tests themselves, on copies
|
||||
/// of the pass's depth and stencil attachments in their interlock
|
||||
/// section: those that write the stencil reference on a device without
|
||||
@@ -381,6 +391,20 @@ const METAL3_NEEDS: [&str; 5] = [
|
||||
"MetalFX upscaling",
|
||||
];
|
||||
const APPLE7_NEEDS: [&str; 2] = ["simdgroup matrices", "barycentric coordinates"];
|
||||
/// The gap of a device whose framebuffer reads reach single-sample
|
||||
/// attachments alone ([`Capabilities::single_sample_storage`]).
|
||||
const MULTISAMPLED_FRAMEBUFFER_READS: &str = "multisampled framebuffer reads";
|
||||
/// What Apple3 needs, by its gaps' names: Mac2, with the Common families
|
||||
/// it contains, and framebuffer reads in draw order, which take raster
|
||||
/// order groups.
|
||||
const APPLE3_NEEDS: [&str; 6] = [
|
||||
"GPU family Common1",
|
||||
"GPU family Common2",
|
||||
"GPU family Common3",
|
||||
"GPU family Mac2",
|
||||
"raster order groups",
|
||||
"framebuffer reads",
|
||||
];
|
||||
|
||||
impl Capabilities {
|
||||
pub fn derive(
|
||||
@@ -453,6 +477,43 @@ impl Capabilities {
|
||||
Some(line)
|
||||
}
|
||||
|
||||
/// Why the boot leaves a device in no Apple GPU family unused, in one
|
||||
/// line naming what of Apple3 it lacks; `None` for a device in Apple3,
|
||||
/// which every other Apple family here contains. Core Animation maps
|
||||
/// the window server's two-plane framebuffers to a Metal format only on
|
||||
/// an Apple3 device: on any other, the window server's Metal device
|
||||
/// draws no desktop, a black screen under the cursor, and the first
|
||||
/// pipeline reading the framebuffer is refused, which ends the window
|
||||
/// server. Without the device macOS draws with the CPU.
|
||||
pub fn no_apple_family(&self) -> Option<String> {
|
||||
if self.supports_family(GpuFamily::Apple3) {
|
||||
return None;
|
||||
}
|
||||
let missing: Vec<&str> = APPLE3_NEEDS
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|need| self.gaps.iter().any(|gap| gap.capability == *need))
|
||||
.collect();
|
||||
let missing = if missing.is_empty() {
|
||||
String::from("GPU family Apple3")
|
||||
} else {
|
||||
missing.join(", ")
|
||||
};
|
||||
Some(alloc::format!(
|
||||
"{}: Metal device in no Apple GPU family (no {missing}); macOS draws its window \
|
||||
server's framebuffers with Metal only on an Apple3 device, so this GPU's Metal \
|
||||
device is not used and macOS draws without it",
|
||||
self.name
|
||||
))
|
||||
}
|
||||
|
||||
/// Whether framebuffer reads reach attachments of `samples` samples
|
||||
/// per pixel: every count on a device with multisampled storage
|
||||
/// images, one alone without them.
|
||||
pub fn framebuffer_reads_at(&self, samples: u64) -> bool {
|
||||
self.framebuffer_reads && (samples <= 1 || !self.single_sample_storage)
|
||||
}
|
||||
|
||||
pub fn supports_family(&self, family: GpuFamily) -> bool {
|
||||
self.families.contains(&family)
|
||||
}
|
||||
@@ -834,12 +895,20 @@ impl Derivation<'_> {
|
||||
features.fragment_shader_pixel_interlock,
|
||||
ShaderFeatures::RASTER_ORDER_GROUPS,
|
||||
));
|
||||
// A single-sample attachment is read and written through a 2D
|
||||
// storage view, a multisampled one through a multisampled view,
|
||||
// which only multisampled storage images give: without them the
|
||||
// reads reach single-sample attachments alone.
|
||||
let framebuffer_reads = raster_order_groups
|
||||
&& self.check(api(
|
||||
"framebuffer reads",
|
||||
features.dynamic_rendering_local_read && features.shader_storage_image_multisample,
|
||||
features.dynamic_rendering_local_read,
|
||||
ApiFeatures::EMPTY,
|
||||
));
|
||||
let single_sample_storage = !features.shader_storage_image_multisample;
|
||||
if framebuffer_reads && single_sample_storage {
|
||||
self.gap(MULTISAMPLED_FRAMEBUFFER_READS, Cause::Driver);
|
||||
}
|
||||
// A stencil output without stencil export, or storage attachments
|
||||
// whose pipeline cannot test fragments first: the function tests
|
||||
// fragments on storage copies of the attachments, which image copies
|
||||
@@ -1134,6 +1203,7 @@ impl Derivation<'_> {
|
||||
statistic_counters: statistics,
|
||||
memoryless_render_targets: true,
|
||||
framebuffer_reads,
|
||||
single_sample_storage,
|
||||
fragment_tests,
|
||||
stencil_export: limits.stencil_export,
|
||||
stencil_follows_depth,
|
||||
@@ -1200,13 +1270,13 @@ impl Derivation<'_> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether fragment functions may write attachments as storage in their
|
||||
/// interlock section: framebuffer reads' requirements, unrecorded.
|
||||
/// Whether fragment functions may write single-sample attachments as
|
||||
/// storage in their interlock section: framebuffer reads' requirements,
|
||||
/// unrecorded. Multisampled ones take multisampled storage images too.
|
||||
fn storage_attachments(&self) -> bool {
|
||||
let features = &self.device.features;
|
||||
features.fragment_shader_pixel_interlock
|
||||
&& features.dynamic_rendering_local_read
|
||||
&& features.shader_storage_image_multisample
|
||||
&& self.shaders.contains(ShaderFeatures::RASTER_ORDER_GROUPS)
|
||||
}
|
||||
|
||||
@@ -1335,8 +1405,10 @@ impl Derivation<'_> {
|
||||
.map(|raw| self.device.formats.get(raw))
|
||||
.filter(|raw| raw.optimal.contains(F::COLOR_ATTACHMENT | F::STORAGE_IMAGE));
|
||||
let raw_render = raw_support.is_some();
|
||||
let raw_multisample =
|
||||
raw_support.is_some_and(|raw| raw.sample_counts.contains(SampleCounts::C4));
|
||||
// Multisampled raw texels are written through multisampled storage
|
||||
// views.
|
||||
let raw_multisample = features.shader_storage_image_multisample
|
||||
&& raw_support.is_some_and(|raw| raw.sample_counts.contains(SampleCounts::C4));
|
||||
let depth_stencil = !color
|
||||
&& !description.view_only
|
||||
&& raster
|
||||
@@ -1706,6 +1778,8 @@ impl Derivation<'_> {
|
||||
]
|
||||
.into_iter()
|
||||
.all(|packed| format(packed, render | FormatCapabilities::FILTER));
|
||||
// Framebuffer reads of single-sample attachments suffice: Core
|
||||
// Animation's are of the window server's framebuffers, which are.
|
||||
let apple3 = mac2 && capabilities.framebuffer_reads;
|
||||
let apple1 = apple3
|
||||
&& self.check_all(
|
||||
@@ -1733,6 +1807,12 @@ impl Derivation<'_> {
|
||||
ShaderFeatures::IMAGEBLOCKS,
|
||||
),
|
||||
driver("raster order groups", capabilities.raster_order_groups),
|
||||
// Tile functions access the imageblock of a
|
||||
// multisampled pass as multisampled storage.
|
||||
driver(
|
||||
MULTISAMPLED_FRAMEBUFFER_READS,
|
||||
!capabilities.single_sample_storage,
|
||||
),
|
||||
],
|
||||
);
|
||||
// Apple5's RG11B10 and RGB9E5 vertex formats are single words, which
|
||||
|
||||
@@ -87,6 +87,9 @@ option_set! {
|
||||
const STENCIL_EXPORT = 1 << 38;
|
||||
/// Lines rasterize as Apple GPUs' (`Capabilities::line_modes`).
|
||||
const LINE_MODES = 1 << 39;
|
||||
/// Framebuffer reads reach single-sample attachments alone
|
||||
/// (`Capabilities::single_sample_storage`).
|
||||
const SINGLE_SAMPLE_STORAGE = 1 << 40;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,6 +378,7 @@ impl Block {
|
||||
statistic_counters: has(Flags::STATISTIC_COUNTERS),
|
||||
memoryless_render_targets: has(Flags::MEMORYLESS_RENDER_TARGETS),
|
||||
framebuffer_reads: has(Flags::FRAMEBUFFER_READS),
|
||||
single_sample_storage: has(Flags::SINGLE_SAMPLE_STORAGE),
|
||||
fragment_tests: has(Flags::FRAGMENT_TESTS),
|
||||
stencil_export: has(Flags::STENCIL_EXPORT),
|
||||
stencil_follows_depth: has(Flags::STENCIL_FOLLOWS_DEPTH),
|
||||
@@ -632,6 +636,7 @@ impl Capabilities {
|
||||
self.memoryless_render_targets,
|
||||
)
|
||||
.with(Flags::FRAMEBUFFER_READS, self.framebuffer_reads)
|
||||
.with(Flags::SINGLE_SAMPLE_STORAGE, self.single_sample_storage)
|
||||
.with(Flags::FRAGMENT_TESTS, self.fragment_tests)
|
||||
.with(Flags::STENCIL_EXPORT, self.stencil_export)
|
||||
.with(Flags::STENCIL_FOLLOWS_DEPTH, self.stencil_follows_depth)
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
//! Framebuffer reads and the Apple families on drivers with and without
|
||||
//! multisampled storage images: NVK and RADV report them, ANV on no Intel
|
||||
//! GPU (`shaderStorageImageMultisample` in `anv_physical_device.c`).
|
||||
use super::{ApiFeatures, Capabilities, Cause, ShaderFeatures};
|
||||
use crate::metal::{
|
||||
abi::GpuFamily,
|
||||
nvidia::{CHIPS, Chip, fixture::nvk},
|
||||
open::{Attachment, PcieLink},
|
||||
service::wire,
|
||||
vulkan::{
|
||||
DriverId, PhysicalDeviceType, SampleCounts,
|
||||
physical::{Identity, PhysicalDevice},
|
||||
},
|
||||
};
|
||||
use alloc::{string::String, vec::Vec};
|
||||
|
||||
fn attachment() -> Attachment {
|
||||
Attachment {
|
||||
link: PcieLink {
|
||||
speed: 4,
|
||||
width: 16,
|
||||
},
|
||||
external: false,
|
||||
location_number: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn gb203() -> &'static Chip {
|
||||
Chip::find(0x1b3).unwrap()
|
||||
}
|
||||
|
||||
fn derive(
|
||||
device: &PhysicalDevice,
|
||||
chip: &Chip,
|
||||
shaders: ShaderFeatures,
|
||||
api: ApiFeatures,
|
||||
) -> Capabilities {
|
||||
Capabilities::derive(device, &chip.platform(attachment()), shaders, api)
|
||||
}
|
||||
|
||||
/// The features and limits ANV gives a Gen12.0 GPU (Tiger Lake to Raptor
|
||||
/// Lake's Iris Xe) where they differ from NVK's, in
|
||||
/// `anv_physical_device.c`, over the NVK fixture's simplified format
|
||||
/// table: no multisampled storage images, mesh shaders (Gen12.5 on) or
|
||||
/// barycentric coordinates (Xe2 on), 16384-texel images, single-sample
|
||||
/// storage images and the stencil export NVK lacks.
|
||||
fn anv_gen12_device() -> PhysicalDevice {
|
||||
let mut device = nvk(gb203(), 4 << 30);
|
||||
device.identity = Identity {
|
||||
driver_id: DriverId::IntelOpenSourceMesa,
|
||||
vendor_id: 0x8086,
|
||||
device_id: 0xa7a0,
|
||||
device_type: PhysicalDeviceType::IntegratedGpu,
|
||||
device_name: String::from("Intel(R) Iris(R) Xe Graphics (RPL-P)"),
|
||||
pci_bus: None,
|
||||
..device.identity
|
||||
};
|
||||
let features = &mut device.features;
|
||||
features.shader_storage_image_multisample = false;
|
||||
features.mesh_shader = false;
|
||||
features.task_shader = false;
|
||||
features.fragment_shader_barycentric = false;
|
||||
features.cooperative_matrix = false;
|
||||
// ANV's own values of what the families need, as NVK's.
|
||||
assert!(features.fragment_shader_pixel_interlock && features.dynamic_rendering_local_read);
|
||||
assert!(features.maintenance8 && features.shader_storage_image_read_without_format);
|
||||
let limits = &mut device.limits;
|
||||
limits.max_image_dimension_1d = 1 << 14;
|
||||
limits.max_image_dimension_2d = 1 << 14;
|
||||
limits.max_image_dimension_cube = 1 << 14;
|
||||
limits.max_image_dimension_3d = 1 << 11;
|
||||
limits.max_framebuffer_width = 1 << 14;
|
||||
limits.max_framebuffer_height = 1 << 14;
|
||||
limits.storage_image_sample_counts = SampleCounts::C1;
|
||||
limits.mesh = None;
|
||||
limits.stencil_export = true;
|
||||
device
|
||||
}
|
||||
|
||||
/// [`anv_gen12_device`]'s capabilities, which the pipeline and resource
|
||||
/// tests take for an Intel GPU's.
|
||||
pub(crate) fn anv_gen12() -> Capabilities {
|
||||
derive(
|
||||
&anv_gen12_device(),
|
||||
gb203(),
|
||||
ShaderFeatures::KNOWN,
|
||||
ApiFeatures::IMPLEMENTED,
|
||||
)
|
||||
}
|
||||
|
||||
fn cause(capabilities: &Capabilities, name: &str) -> Option<Cause> {
|
||||
capabilities
|
||||
.gaps()
|
||||
.iter()
|
||||
.find(|gap| gap.capability == name)
|
||||
.map(|gap| gap.cause)
|
||||
}
|
||||
|
||||
const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
|
||||
/// FNV-1a over `capabilities`' block, what the guest reads of the device:
|
||||
/// every capability, family, format and gap.
|
||||
fn digest(hash: u64, capabilities: &Capabilities) -> u64 {
|
||||
wire::bytes(&*capabilities.block().unwrap())
|
||||
.iter()
|
||||
.fold(hash, |hash, byte| {
|
||||
(hash ^ u64::from(*byte)).wrapping_mul(0x0000_0100_0000_01b3)
|
||||
})
|
||||
}
|
||||
|
||||
/// Devices that report multisampled storage images, as NVK on every
|
||||
/// NVIDIA GPU and RADV on every AMD one do, modeled over the NVK fixture,
|
||||
/// with each block's digest from before framebuffer reads stopped
|
||||
/// requiring them (335f4ea6d).
|
||||
fn with_multisampled_storage() -> Vec<(&'static str, u64, u64)> {
|
||||
let complete = |device: &PhysicalDevice, chip: &Chip| {
|
||||
derive(
|
||||
device,
|
||||
chip,
|
||||
ShaderFeatures::KNOWN,
|
||||
ApiFeatures::IMPLEMENTED,
|
||||
)
|
||||
};
|
||||
let every_chip = CHIPS.iter().fold(FNV_OFFSET, |hash, chip| {
|
||||
digest(hash, &complete(&nvk(chip, 16 << 30), chip))
|
||||
});
|
||||
let chip = gb203();
|
||||
let every_api = derive(
|
||||
&nvk(chip, 16 << 30),
|
||||
chip,
|
||||
ShaderFeatures::KNOWN,
|
||||
ApiFeatures::KNOWN,
|
||||
);
|
||||
let no_raster_order_groups = derive(
|
||||
&nvk(chip, 16 << 30),
|
||||
chip,
|
||||
ShaderFeatures::KNOWN.difference(ShaderFeatures::RASTER_ORDER_GROUPS),
|
||||
ApiFeatures::IMPLEMENTED,
|
||||
);
|
||||
// RADV on GFX9 and GFX10.1: no mesh shaders or barycentric
|
||||
// coordinates; on GFX8 no fragment shader interlock either.
|
||||
let turing = Chip::find(0x172).unwrap();
|
||||
let mut gfx9 = nvk(turing, 16 << 30);
|
||||
gfx9.features.mesh_shader = false;
|
||||
gfx9.features.task_shader = false;
|
||||
gfx9.features.fragment_shader_barycentric = false;
|
||||
let mut gfx8 = gfx9.clone();
|
||||
gfx8.features.fragment_shader_pixel_interlock = false;
|
||||
let mut no_local_read = nvk(chip, 16 << 30);
|
||||
no_local_read.features.dynamic_rendering_local_read = false;
|
||||
let one = |capabilities: &Capabilities| digest(FNV_OFFSET, capabilities);
|
||||
alloc::vec![
|
||||
("every NVIDIA chip", every_chip, 0x51c6_eb72_26e5_3488),
|
||||
(
|
||||
"GB203, every API path",
|
||||
one(&every_api),
|
||||
0x6b81_5f3f_512e_8dcd
|
||||
),
|
||||
(
|
||||
"GB203, no raster order groups in the compiler",
|
||||
one(&no_raster_order_groups),
|
||||
0xd618_22ff_0bc1_a246,
|
||||
),
|
||||
(
|
||||
"RADV GFX9 and GFX10.1 model",
|
||||
one(&complete(&gfx9, turing)),
|
||||
0xeb78_cc20_7f3f_ae91,
|
||||
),
|
||||
(
|
||||
"RADV GFX8 model",
|
||||
one(&complete(&gfx8, turing)),
|
||||
0xf8c3_3d92_c92b_3cf0,
|
||||
),
|
||||
(
|
||||
"GB203, no local reads",
|
||||
one(&complete(&no_local_read, chip)),
|
||||
0x7dbd_09c1_ca87_3298,
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn devices_with_multisampled_storage_images_derive_what_they_did() {
|
||||
for (device, digest, before) in with_multisampled_storage() {
|
||||
assert_eq!(digest, before, "{device}");
|
||||
}
|
||||
let capabilities = crate::metal::nvidia::fixture::capabilities();
|
||||
assert!(capabilities.framebuffer_reads && !capabilities.single_sample_storage);
|
||||
assert!(capabilities.framebuffer_reads_at(4));
|
||||
assert_eq!(cause(&capabilities, "multisampled framebuffer reads"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn anv_reads_single_sample_framebuffers_in_apple3() {
|
||||
let capabilities = anv_gen12();
|
||||
assert!(capabilities.framebuffer_reads);
|
||||
assert!(capabilities.single_sample_storage);
|
||||
assert!(capabilities.framebuffer_reads_at(1));
|
||||
assert!(!capabilities.framebuffer_reads_at(2));
|
||||
assert!(!capabilities.framebuffer_reads_at(4));
|
||||
assert_eq!(
|
||||
cause(&capabilities, "multisampled framebuffer reads"),
|
||||
Some(Cause::Driver)
|
||||
);
|
||||
assert_eq!(cause(&capabilities, "framebuffer reads"), None);
|
||||
assert_eq!(cause(&capabilities, "raster order groups"), None);
|
||||
for family in [
|
||||
GpuFamily::Common1,
|
||||
GpuFamily::Common2,
|
||||
GpuFamily::Common3,
|
||||
GpuFamily::Mac2,
|
||||
GpuFamily::Apple3,
|
||||
] {
|
||||
assert!(capabilities.supports_family(family), "{family:?}");
|
||||
}
|
||||
// Apple4's tile functions of multisampled passes and Apple5's stencil
|
||||
// resolve after a depth resolve take multisampled storage images.
|
||||
assert!(!capabilities.supports_family(GpuFamily::Apple4));
|
||||
assert!(!capabilities.supports_family(GpuFamily::Apple5));
|
||||
assert!(!capabilities.stencil_follows_depth && !capabilities.fragment_tests);
|
||||
assert!(!capabilities.supports_family(GpuFamily::Metal3));
|
||||
assert_eq!(capabilities.no_apple_family(), None);
|
||||
assert!(
|
||||
capabilities
|
||||
.family_shortfall()
|
||||
.unwrap()
|
||||
.starts_with("Intel(R) Iris(R) Xe Graphics (RPL-P): Metal device in Apple3 at most")
|
||||
);
|
||||
// The flag crosses the block.
|
||||
let block = capabilities.block().unwrap();
|
||||
assert_eq!(block.capabilities().unwrap(), capabilities);
|
||||
}
|
||||
|
||||
/// What ANV derived before: framebuffer reads took multisampled storage
|
||||
/// images, so the device was in no Apple family, which the boot now
|
||||
/// refuses to draw macOS on.
|
||||
#[test]
|
||||
fn a_device_in_no_apple_family_says_why_it_is_not_used() {
|
||||
let mut device = anv_gen12_device();
|
||||
device.features.fragment_shader_pixel_interlock = false;
|
||||
let capabilities = derive(
|
||||
&device,
|
||||
gb203(),
|
||||
ShaderFeatures::KNOWN,
|
||||
ApiFeatures::IMPLEMENTED,
|
||||
);
|
||||
assert!(capabilities.supports_family(GpuFamily::Mac2));
|
||||
assert!(!capabilities.supports_family(GpuFamily::Apple3));
|
||||
assert!(
|
||||
capabilities
|
||||
.families()
|
||||
.iter()
|
||||
.all(|family| !alloc::format!("{family:?}").starts_with("Apple"))
|
||||
);
|
||||
assert_eq!(
|
||||
capabilities.no_apple_family().unwrap(),
|
||||
"Intel(R) Iris(R) Xe Graphics (RPL-P): Metal device in no Apple GPU family (no raster \
|
||||
order groups); macOS draws its window server's framebuffers with Metal only on an \
|
||||
Apple3 device, so this GPU's Metal device is not used and macOS draws without it"
|
||||
);
|
||||
|
||||
let mut device = anv_gen12_device();
|
||||
device.features.dynamic_rendering_local_read = false;
|
||||
let capabilities = derive(
|
||||
&device,
|
||||
gb203(),
|
||||
ShaderFeatures::KNOWN,
|
||||
ApiFeatures::IMPLEMENTED,
|
||||
);
|
||||
assert!(
|
||||
capabilities
|
||||
.no_apple_family()
|
||||
.unwrap()
|
||||
.contains("(no framebuffer reads)")
|
||||
);
|
||||
|
||||
// Below Mac2 the first family it lacks is named.
|
||||
let mut device = anv_gen12_device();
|
||||
device.limits.max_viewports = 1;
|
||||
let capabilities = derive(
|
||||
&device,
|
||||
gb203(),
|
||||
ShaderFeatures::KNOWN,
|
||||
ApiFeatures::IMPLEMENTED,
|
||||
);
|
||||
assert!(
|
||||
capabilities
|
||||
.no_apple_family()
|
||||
.unwrap()
|
||||
.contains("(no GPU family Mac2)")
|
||||
);
|
||||
|
||||
// A compute-only compiler is in no family at all.
|
||||
let capabilities = derive(
|
||||
&nvk(gb203(), 16 << 30),
|
||||
gb203(),
|
||||
ShaderFeatures::COMPUTE,
|
||||
ApiFeatures::IMPLEMENTED,
|
||||
);
|
||||
assert!(
|
||||
capabilities
|
||||
.no_apple_family()
|
||||
.unwrap()
|
||||
.contains("(no GPU family Common1, ")
|
||||
);
|
||||
}
|
||||
@@ -714,6 +714,14 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// A multisampled attachment has no storage views where the
|
||||
// reads reach single-sample attachments alone, and no
|
||||
// pipeline of the pass reads it.
|
||||
if texture.texture_type.is_multisample()
|
||||
&& !self.capabilities.framebuffer_reads_at(texture.sample_count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let view = AttachmentView {
|
||||
texture: (),
|
||||
view_type: color.view.view_type,
|
||||
|
||||
@@ -710,6 +710,13 @@ pub fn storage_attachments(
|
||||
if fragment.attachment_reads != 0 {
|
||||
require(capabilities.framebuffer_reads, "framebuffer reads")?;
|
||||
}
|
||||
// A multisampled attachment is accessed through multisampled storage
|
||||
// views, which a device whose reads reach single-sample attachments
|
||||
// alone does not have.
|
||||
require(
|
||||
targets.raster_sample_count <= 1 || !capabilities.single_sample_storage,
|
||||
"framebuffer reads of multisampled attachments",
|
||||
)?;
|
||||
require(
|
||||
tests_first(fragment, targets) || capabilities.fragment_tests,
|
||||
"attachments accessed as storage by a function that writes depth, stencil or coverage",
|
||||
@@ -747,13 +754,17 @@ pub fn storage_attachments(
|
||||
/// code within the codes' range, as Apple GPUs do, where the blend unit
|
||||
/// would keep values past them. A device without framebuffer reads, or a
|
||||
/// function that cannot let the pipeline test fragments first, leaves
|
||||
/// them to the blend unit, a known hardware precision difference.
|
||||
/// them to the blend unit, a known hardware precision difference; so does
|
||||
/// a multisampled pipeline on a device whose reads reach single-sample
|
||||
/// attachments alone.
|
||||
fn blended_extended_range(
|
||||
capabilities: &Capabilities,
|
||||
fragment: &Interface,
|
||||
targets: &RenderTargets,
|
||||
) -> u32 {
|
||||
if !capabilities.framebuffer_reads || !tests_first(fragment, targets) {
|
||||
if !capabilities.framebuffer_reads_at(targets.raster_sample_count)
|
||||
|| !tests_first(fragment, targets)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
targets
|
||||
@@ -1257,6 +1268,11 @@ pub fn tile_target(
|
||||
) -> Result<TileTarget> {
|
||||
require(capabilities.framebuffer_reads, "tile functions")?;
|
||||
let samples = samples.max(1);
|
||||
// A multisampled pass's imageblock is multisampled storage.
|
||||
require(
|
||||
capabilities.framebuffer_reads_at(samples),
|
||||
"tile functions of multisampled passes",
|
||||
)?;
|
||||
require(
|
||||
capabilities.supports_texture_sample_count(samples),
|
||||
"tile pipeline sample count",
|
||||
|
||||
@@ -728,3 +728,47 @@ fn varyings_link_by_identifier_and_type() {
|
||||
assert!(link_varyings(&vertex, Some(&fragment)).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
/// ANV has no multisampled storage images: its framebuffer reads reach
|
||||
/// single-sample attachments, and a multisampled pipeline that would
|
||||
/// access an attachment as storage, or tile pipeline, is refused, where
|
||||
/// NVK's runs.
|
||||
#[test]
|
||||
fn framebuffer_reads_of_multisampled_attachments_take_multisampled_storage() {
|
||||
let anv = crate::metal::capabilities::tests::anv_gen12();
|
||||
let nvk = capabilities();
|
||||
let mut fragment = interface(Stage::Fragment);
|
||||
fragment.attachment_reads = 1;
|
||||
let mut targets = RenderTargets::default();
|
||||
targets.color_attachments[0] = color(PixelFormat::Bgra8Unorm);
|
||||
let attachments = storage_attachments(&anv, &fragment, &targets).unwrap();
|
||||
assert!(attachments[0].is_some());
|
||||
|
||||
targets.raster_sample_count = 4;
|
||||
assert_eq!(
|
||||
storage_attachments(&anv, &fragment, &targets).unwrap_err(),
|
||||
Error::Unsupported("framebuffer reads of multisampled attachments")
|
||||
);
|
||||
assert!(storage_attachments(&nvk, &fragment, &targets).unwrap()[0].is_some());
|
||||
|
||||
// A multisampled extended-range blend falls back to the blend unit.
|
||||
let fragment = interface(Stage::Fragment);
|
||||
targets.color_attachments[0] = ColorAttachmentDescriptor {
|
||||
blending_enabled: true,
|
||||
..color(PixelFormat::Bgra10Xr)
|
||||
};
|
||||
let attachments = storage_attachments(&anv, &fragment, &targets).unwrap();
|
||||
assert!(attachments.iter().all(Option::is_none));
|
||||
assert!(storage_attachments(&nvk, &fragment, &targets).unwrap()[0].is_some());
|
||||
targets.raster_sample_count = 1;
|
||||
assert!(storage_attachments(&anv, &fragment, &targets).unwrap()[0].is_some());
|
||||
|
||||
let mut formats = [None; MAX_COLOR_ATTACHMENTS];
|
||||
formats[0] = Some(PixelFormat::Bgra8Unorm);
|
||||
assert!(tile_target(&anv, &formats, 1, false).is_ok());
|
||||
assert_eq!(
|
||||
tile_target(&anv, &formats, 4, false).unwrap_err(),
|
||||
Error::Unsupported("tile functions of multisampled passes")
|
||||
);
|
||||
assert!(tile_target(&nvk, &formats, 4, false).is_ok());
|
||||
}
|
||||
@@ -556,12 +556,29 @@ fn effective_usage(
|
||||
// A fragment function may read what it renders to, and on Apple GPUs a
|
||||
// kernel keeps its writes to a texture made without shader writes, as
|
||||
// Core Animation's compute passes write their render targets.
|
||||
Ok(usage
|
||||
let usage = usage
|
||||
.with(
|
||||
TextureUsage::SHADER_READ,
|
||||
usage.contains(TextureUsage::RENDER_TARGET) && format.contains(C::READ),
|
||||
)
|
||||
.with(TextureUsage::SHADER_WRITE, format.contains(C::WRITE)))
|
||||
.with(TextureUsage::SHADER_WRITE, format.contains(C::WRITE));
|
||||
// No shader writes a multisampled texture, which the shading language
|
||||
// reads alone; a driver without multisampled storage images makes no
|
||||
// such image storage.
|
||||
Ok(if storage_samples(capabilities, descriptor) {
|
||||
usage
|
||||
} else {
|
||||
usage.difference(TextureUsage::SHADER_WRITE | TextureUsage::SHADER_ATOMIC)
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether `descriptor`'s texture may be a storage image: a single-sample
|
||||
/// one, or a multisampled one on a device with multisampled storage
|
||||
/// images.
|
||||
fn storage_samples(capabilities: &Capabilities, descriptor: &TextureDescriptor) -> bool {
|
||||
!descriptor.texture_type.is_multisample()
|
||||
|| descriptor.sample_count <= 1
|
||||
|| !capabilities.single_sample_storage
|
||||
}
|
||||
|
||||
/// The format of a color attachment's raw texel view, which a fragment
|
||||
@@ -619,7 +636,9 @@ pub fn has_texel_storage(texture_type: TextureType) -> bool {
|
||||
/// Lets a color texture be viewed by its raw texels as storage: a render
|
||||
/// target, which framebuffer reads access, and a texture whose image stores
|
||||
/// another encoding than its format's bytes, which the texel kernels convert
|
||||
/// buffer copies through. Its typed shader views are unchanged.
|
||||
/// buffer copies through. Its typed shader views are unchanged. A
|
||||
/// multisampled render target has storage views only where framebuffer
|
||||
/// reads reach multisampled attachments.
|
||||
fn attachment_storage(
|
||||
capabilities: &Capabilities,
|
||||
descriptor: &TextureDescriptor,
|
||||
@@ -627,7 +646,13 @@ fn attachment_storage(
|
||||
image: &mut ImageInfo,
|
||||
) {
|
||||
let format = descriptor.pixel_format;
|
||||
let attachment = capabilities.framebuffer_reads && usage.contains(TextureUsage::RENDER_TARGET);
|
||||
let samples = if descriptor.texture_type.is_multisample() {
|
||||
descriptor.sample_count
|
||||
} else {
|
||||
1
|
||||
};
|
||||
let attachment =
|
||||
capabilities.framebuffer_reads_at(samples) && usage.contains(TextureUsage::RENDER_TARGET);
|
||||
let converted =
|
||||
!format.describe().encoding().is_exact() && has_texel_storage(descriptor.texture_type);
|
||||
let Some(raw) = raw_texel_format(format).filter(|_| attachment || converted) else {
|
||||
@@ -923,10 +948,13 @@ pub fn texture_view(
|
||||
view_format.contains(C::READ) && parent_format.contains(C::READ),
|
||||
);
|
||||
}
|
||||
// Its parent is writable wherever its format is (`effective_usage`).
|
||||
// Its parent is writable wherever its format is and its samples may be
|
||||
// storage (`effective_usage`).
|
||||
usage = usage.with(
|
||||
ImageUsage::STORAGE,
|
||||
view_format.contains(C::WRITE) && parent_format.contains(C::WRITE),
|
||||
view_format.contains(C::WRITE)
|
||||
&& parent_format.contains(C::WRITE)
|
||||
&& storage_samples(capabilities, parent),
|
||||
);
|
||||
let range = SubresourceRange {
|
||||
aspects: shader_aspects(description),
|
||||
|
||||
@@ -767,3 +767,47 @@ fn texture_buffers_are_bounded_texel_views() {
|
||||
Err(Error::Unsupported("texture buffers of this pixel format"))
|
||||
);
|
||||
}
|
||||
|
||||
/// A render target is storage, for framebuffer reads and kernels' writes,
|
||||
/// and so are its views; a multisampled one only on a device with
|
||||
/// multisampled storage images, which ANV is not, where Vulkan refuses a
|
||||
/// multisampled storage image.
|
||||
#[test]
|
||||
fn multisampled_textures_are_storage_only_with_multisampled_storage() {
|
||||
use crate::metal::vulkan::ImageUsage;
|
||||
let anv = crate::metal::capabilities::tests::anv_gen12();
|
||||
let nvk = capabilities();
|
||||
let target = |texture_type, sample_count| TextureDescriptor {
|
||||
sample_count,
|
||||
usage: TextureUsage::RENDER_TARGET,
|
||||
..descriptor(texture_type, PixelFormat::Bgra8Unorm)
|
||||
};
|
||||
let storage = |capabilities: &Capabilities, descriptor: TextureDescriptor| {
|
||||
texture(capabilities, &descriptor)
|
||||
.unwrap()
|
||||
.image
|
||||
.usage
|
||||
.contains(ImageUsage::STORAGE)
|
||||
};
|
||||
assert!(storage(&anv, target(TextureType::D2, 1)));
|
||||
assert!(!storage(&anv, target(TextureType::D2Multisample, 4)));
|
||||
assert!(storage(&nvk, target(TextureType::D2, 1)));
|
||||
assert!(storage(&nvk, target(TextureType::D2Multisample, 4)));
|
||||
let view = |capabilities: &Capabilities, parent: TextureDescriptor| {
|
||||
let view = TextureViewDescriptor {
|
||||
pixel_format: parent.pixel_format,
|
||||
texture_type: parent.texture_type,
|
||||
levels: 0..1,
|
||||
slices: 0..1,
|
||||
swizzle: SwizzleChannels::IDENTITY,
|
||||
min_lod: 0.0,
|
||||
};
|
||||
texture_view(capabilities, &parent, &view)
|
||||
.unwrap()
|
||||
.storage
|
||||
.is_some()
|
||||
};
|
||||
assert!(view(&anv, target(TextureType::D2, 1)));
|
||||
assert!(!view(&anv, target(TextureType::D2Multisample, 4)));
|
||||
assert!(view(&nvk, target(TextureType::D2Multisample, 4)));
|
||||
}
|
||||
@@ -1704,6 +1704,15 @@ impl<B: Backend, C: Compiler + 'static> SharedService<B, C> {
|
||||
.and_then(|mut turn| turn.device().capabilities().family_shortfall())
|
||||
}
|
||||
|
||||
/// Why the boot leaves the device unused, in no Apple GPU family
|
||||
/// ([`crate::metal::capabilities::Capabilities::no_apple_family`]);
|
||||
/// `None` for a device in Apple3, or while a call holds the service,
|
||||
/// which no call does as the boot opens it.
|
||||
pub fn no_apple_family(&self) -> Option<alloc::string::String> {
|
||||
self.try_turn()
|
||||
.and_then(|mut turn| turn.device().capabilities().no_apple_family())
|
||||
}
|
||||
|
||||
/// Where retired command buffers' time went since the last call, unless
|
||||
/// a call holds the service now; it is then counted for the next.
|
||||
pub fn gpu_times(&self) -> Option<crate::metal::device::gpu_times::GpuTimes> {
|
||||
|
||||
Reference in new issue
Block a user