nil: Use GOBType::choose() to pick gob kinds for modifiers

The gob kind and sector layout should map directly to a unique GOBType.
We can now also advertise zero modifiers for GOB types that don't
support modifiers.  Currently this is redundant with the earlier return
for depth/stencil images but it should help protect us in the future
when adding new GOB types.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35660>
This commit is contained in:
Faith Ekstrand
2025-06-20 17:04:57 -04:00
committed by Marge Bot
parent 52b8072040
commit d8c43ff46a
+36 -21
View File
@@ -6,7 +6,6 @@ use crate::image::Image;
use crate::tiling::{GOBType, Tiling};
use bitview::*;
use nvidia_headers::classes::{cl9097, clc597};
pub const MAX_DRM_FORMAT_MODS: usize = 7;
@@ -31,18 +30,6 @@ impl TryFrom<u64> for GOBKindVersion {
}
}
impl GOBKindVersion {
pub fn for_dev(dev: &nil_rs_bindings::nv_device_info) -> GOBKindVersion {
if dev.cls_eng3d >= clc597::TURING_A {
GOBKindVersion::Turing
} else if dev.cls_eng3d >= cl9097::FERMI_A {
GOBKindVersion::Fermi
} else {
GOBKindVersion::G80
}
}
}
#[repr(u8)]
#[derive(Clone, Copy, Eq, PartialEq)]
pub enum SectorLayout {
@@ -62,9 +49,29 @@ impl TryFrom<u64> for SectorLayout {
}
}
impl SectorLayout {
impl GOBType {
fn supports_modifiers(&self) -> bool {
matches!(
self,
GOBType::Linear | GOBType::Fermi | GOBType::TuringColor2D
)
}
fn kind_version(&self) -> GOBKindVersion {
match self {
GOBType::Linear => {
panic!("Linear modifierss are handled elsewhere");
}
GOBType::Fermi => GOBKindVersion::Fermi,
GOBType::TuringZS => {
panic!("Modifiers are not supported for Z/S images");
}
GOBType::TuringColor2D => GOBKindVersion::Turing,
}
}
// For now, this always returns desktop, but will be different for Tegra
pub fn for_dev(_dev: &nil_rs_bindings::nv_device_info) -> SectorLayout {
fn sector_layout(&self) -> SectorLayout {
SectorLayout::Desktop
}
}
@@ -224,8 +231,11 @@ pub fn drm_format_mods_for_format(
}
let compression_type = CompressionType::None;
let sector_layout = SectorLayout::for_dev(dev);
let gob_kind_version = GOBKindVersion::for_dev(dev);
let gob_type = GOBType::choose(dev, format);
if !gob_type.supports_modifiers() {
return;
}
let pte_kind = Image::choose_pte_kind(dev, format, 1, false);
// We assume bigger tiling is better
@@ -234,8 +244,8 @@ pub fn drm_format_mods_for_format(
let bl_mod = BlockLinearModifier::block_linear_2d(
compression_type,
sector_layout,
gob_kind_version,
gob_type.sector_layout(),
gob_type.kind_version(),
pte_kind,
height_log2,
);
@@ -267,11 +277,16 @@ pub fn drm_format_mod_is_supported(
return false;
}
if bl_mod.gob_kind_version() != GOBKindVersion::for_dev(dev) {
let gob_type = GOBType::choose(dev, format);
if !gob_type.supports_modifiers() {
return false;
}
if bl_mod.sector_layout() != SectorLayout::for_dev(dev) {
if bl_mod.gob_kind_version() != gob_type.kind_version() {
return false;
}
if bl_mod.sector_layout() != gob_type.sector_layout() {
return false;
}