nak: Plumb through the call/return stack size

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30402>
This commit is contained in:
Faith Ekstrand
2024-07-26 12:50:33 -05:00
committed by Marge Bot
parent 3e935df2b0
commit b78f7d208b
9 changed files with 45 additions and 0 deletions
+3
View File
@@ -115,6 +115,9 @@ struct nak_shader_info {
/** Size of shader local (scratch) memory */
uint32_t slm_size;
/** Size of call/return stack in bytes/warp */
uint32_t crs_size;
union {
struct {
/* Local workgroup size */
+1
View File
@@ -238,6 +238,7 @@ impl ShaderBin {
_pad0: Default::default(),
num_instrs: info.num_instrs,
slm_size: info.slm_size,
crs_size: sm.crs_size(info.max_crs_depth),
__bindgen_anon_1: match &info.stage {
ShaderStageInfo::Compute(cs_info) => {
nak_shader_info__bindgen_ty_1 {
+1
View File
@@ -24,6 +24,7 @@ fn init_info_from_nir(nir: &nir_shader) -> ShaderInfo {
num_instrs: 0,
num_control_barriers: 0,
slm_size: nir.scratch_size,
max_crs_depth: 0,
uses_global_mem: false,
writes_global_mem: false,
// TODO: handle this.
+1
View File
@@ -222,6 +222,7 @@ impl<'a> TestShaderBuilder<'a> {
num_control_barriers: 0,
num_instrs: 0,
slm_size: 0,
max_crs_depth: 0,
uses_global_mem: true,
writes_global_mem: true,
uses_fp64: false,
+2
View File
@@ -7096,6 +7096,7 @@ pub struct ShaderInfo {
pub num_control_barriers: u8,
pub num_instrs: u32,
pub slm_size: u32,
pub max_crs_depth: u32,
pub uses_global_mem: bool,
pub writes_global_mem: bool,
pub uses_fp64: bool,
@@ -7106,6 +7107,7 @@ pub struct ShaderInfo {
pub trait ShaderModel {
fn sm(&self) -> u8;
fn num_regs(&self, file: RegFile) -> u32;
fn crs_size(&self, max_crs_depth: u32) -> u32;
fn op_can_be_uniform(&self, op: &Op) -> bool;
+10
View File
@@ -38,6 +38,16 @@ impl ShaderModel for ShaderModel50 {
}
}
fn crs_size(&self, max_crs_depth: u32) -> u32 {
if max_crs_depth <= 16 {
0
} else if max_crs_depth <= 32 {
1024
} else {
((max_crs_depth + 32) * 16).next_multiple_of(512)
}
}
fn op_can_be_uniform(&self, _op: &Op) -> bool {
false
}
+5
View File
@@ -60,6 +60,11 @@ impl ShaderModel for ShaderModel70 {
}
}
fn crs_size(&self, max_crs_depth: u32) -> u32 {
assert!(max_crs_depth == 0);
0
}
fn op_can_be_uniform(&self, op: &Op) -> bool {
if !self.has_uniform_alu() {
return false;
+2
View File
@@ -480,6 +480,8 @@ pub fn encode_header(
let slm_size = shader_info.slm_size.next_multiple_of(16);
sph.set_shader_local_memory_size(slm_size.into());
let crs_size = sm.crs_size(shader_info.max_crs_depth);
sph.set_shader_local_memory_crs_size(crs_size);
match &shader_info.io {
ShaderIoInfo::Vtg(io) => {
+20
View File
@@ -23,6 +23,7 @@ trait QMD {
fn set_local_size(&mut self, width: u16, height: u16, depth: u16);
fn set_prog_addr(&mut self, addr: u64);
fn set_register_count(&mut self, register_count: u8);
fn set_crs_size(&mut self, crs_size: u32);
fn set_slm_size(&mut self, slm_size: u32);
fn set_smem_size(&mut self, smem_size: u32, smem_max: u32);
}
@@ -94,6 +95,16 @@ macro_rules! qmd_impl_common {
};
}
macro_rules! qmd_impl_set_crs_size {
($c:ident, $s:ident) => {
fn set_crs_size(&mut self, crs_size: u32) {
let mut bv = QMDBitView::new(&mut self.qmd);
let crs_size = crs_size.next_multiple_of(0x200);
set_field!(bv, $c, $s, SHADER_LOCAL_MEMORY_CRS_SIZE, crs_size);
}
};
}
const SIZE_SHIFT: u8 = 0;
const SIZE_SHIFTED4_SHIFT: u8 = 4;
@@ -170,6 +181,7 @@ mod qmd_0_6 {
}
qmd_impl_common!(cla0c0, QMDV00_06);
qmd_impl_set_crs_size!(cla0c0, QMDV00_06);
qmd_impl_set_cbuf!(cla0c0, QMDV00_06, SIZE);
qmd_impl_set_prog_addr_32!(cla0c0, QMDV00_06);
qmd_impl_set_register_count!(cla0c0, QMDV00_06, REGISTER_COUNT);
@@ -214,6 +226,7 @@ mod qmd_2_1 {
}
qmd_impl_common!(clc0c0, QMDV02_01);
qmd_impl_set_crs_size!(clc0c0, QMDV02_01);
qmd_impl_set_cbuf!(clc0c0, QMDV02_01, SIZE_SHIFTED4);
qmd_impl_set_prog_addr_32!(clc0c0, QMDV02_01);
qmd_impl_set_register_count!(clc0c0, QMDV02_01, REGISTER_COUNT);
@@ -281,6 +294,7 @@ mod qmd_2_2 {
}
qmd_impl_common!(clc3c0, QMDV02_02);
qmd_impl_set_crs_size!(clc3c0, QMDV02_02);
qmd_impl_set_cbuf!(clc3c0, QMDV02_02, SIZE_SHIFTED4);
qmd_impl_set_prog_addr_64!(clc3c0, QMDV02_02);
qmd_impl_set_register_count!(clc3c0, QMDV02_02, REGISTER_COUNT_V);
@@ -308,6 +322,11 @@ mod qmd_3_0 {
}
qmd_impl_common!(clc6c0, QMDV03_00);
fn set_crs_size(&mut self, crs_size: u32) {
assert!(crs_size == 0);
}
qmd_impl_set_cbuf!(clc6c0, QMDV03_00, SIZE_SHIFTED4);
qmd_impl_set_prog_addr_64!(clc6c0, QMDV03_00);
qmd_impl_set_register_count!(clc6c0, QMDV03_00, REGISTER_COUNT_V);
@@ -337,6 +356,7 @@ fn fill_qmd<Q: QMD>(info: &nak_shader_info, qmd_info: &nak_qmd_info) -> Q {
);
qmd.set_prog_addr(qmd_info.addr);
qmd.set_register_count(info.num_gprs);
qmd.set_crs_size(info.crs_size);
qmd.set_slm_size(info.slm_size);
assert!(qmd_info.smem_size >= cs_info.smem_size);