From ec112a35e27ea8e7b4f294616e897671447e6086 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 25 Aug 2025 17:04:36 -0400 Subject: [PATCH] nak: Add a nak_qmd_size_B() query Also add a #define NAK_QMD_ALIGN_B for alignments. The alignment is always 256B and there's no evidence of that changing. Reviewed-by: Mel Henning Backport-to: 25.2 Part-of: (cherry picked from commit 02ef6a51587b6a57039515c8b6dbc4f90cc94e2f) --- .pick_status.json | 2 +- src/nouveau/compiler/meson.build | 1 + src/nouveau/compiler/nak.h | 6 ++++++ src/nouveau/compiler/nak/qmd.rs | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index ff1d529b52d..c58c0df6952 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3954,7 +3954,7 @@ "description": "nak: Add a nak_qmd_size_B() query", "nominated": true, "nomination_type": 4, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/nouveau/compiler/meson.build b/src/nouveau/compiler/meson.build index 9d87a0d4aeb..0ca7dcd13e1 100644 --- a/src/nouveau/compiler/meson.build +++ b/src/nouveau/compiler/meson.build @@ -63,6 +63,7 @@ _nak_bindings_rs = rust.bindgen( '--allowlist-type', 'nak_.*', '--allowlist-type', 'nouveau_ws_.*', '--allowlist-var', 'DRM_.*', + '--allowlist-var', 'NAK_.*', '--allowlist-var', 'NVIDIA_VENDOR_ID', '--allowlist-function', 'drm.*', '--allowlist-function', 'nak_.*', diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h index aa2c8628791..b43b0026e80 100644 --- a/src/nouveau/compiler/nak.h +++ b/src/nouveau/compiler/nak.h @@ -251,6 +251,12 @@ struct nak_qmd_info { struct nak_qmd_cbuf cbufs[8]; }; +#define NAK_QMD_ALIGN_B 256 +#define NAK_MAX_QMD_SIZE_B 256 +#define NAK_MAX_QMD_DWORDS (NAK_MAX_QMD_SIZE_B / 4) + +uint32_t nak_qmd_size_B(const struct nv_device_info *dev); + void nak_fill_qmd(const struct nv_device_info *dev, const struct nak_shader_info *info, const struct nak_qmd_info *qmd_info, diff --git a/src/nouveau/compiler/nak/qmd.rs b/src/nouveau/compiler/nak/qmd.rs index d437c34da93..e97c0a4fd73 100644 --- a/src/nouveau/compiler/nak/qmd.rs +++ b/src/nouveau/compiler/nak/qmd.rs @@ -580,6 +580,27 @@ fn fill_qmd(info: &nak_shader_info, qmd_info: &nak_qmd_info) -> Q { qmd } +#[no_mangle] +pub extern "C" fn nak_qmd_size_B(dev: &nv_device_info) -> u32 { + let size_B = if dev.cls_compute >= clcdc0::BLACKWELL_COMPUTE_A { + size_of::().try_into().unwrap() + } else if dev.cls_compute >= clcbc0::HOPPER_COMPUTE_A { + size_of::().try_into().unwrap() + } else if dev.cls_compute >= clc6c0::AMPERE_COMPUTE_A { + size_of::().try_into().unwrap() + } else if dev.cls_compute >= clc3c0::VOLTA_COMPUTE_A { + size_of::().try_into().unwrap() + } else if dev.cls_compute >= clc0c0::PASCAL_COMPUTE_A { + size_of::().try_into().unwrap() + } else if dev.cls_compute >= cla0c0::KEPLER_COMPUTE_A { + size_of::().try_into().unwrap() + } else { + panic!("Unknown shader model"); + }; + assert!(size_B <= NAK_MAX_QMD_SIZE_B); + size_B +} + #[no_mangle] pub extern "C" fn nak_fill_qmd( dev: *const nv_device_info,