From 0e4480d8b3d7d99abd8ceff8d1fd79f9f7d8ccf0 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Jan 2023 20:53:19 -0600 Subject: [PATCH] nak: Add a nir_shader_compiler_options to nak_compiler Part-of: --- src/nouveau/compiler/nak.h | 3 ++ src/nouveau/compiler/nak.rs | 49 +++++++++++++++++++++++++++++- src/nouveau/compiler/nak_private.h | 2 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h index 0d1bcf359a3..8c908916d32 100644 --- a/src/nouveau/compiler/nak.h +++ b/src/nouveau/compiler/nak.h @@ -22,6 +22,9 @@ struct nv_device_info; struct nak_compiler *nak_compiler_create(const struct nv_device_info *dev); void nak_compiler_destroy(struct nak_compiler *nak); +const struct nir_shader_compiler_options * +nak_nir_options(const struct nak_compiler *nak); + void nak_optimize_nir(nir_shader *nir, const struct nak_compiler *nak); void nak_preprocess_nir(nir_shader *nir, const struct nak_compiler *nak); void nak_postprocess_nir(nir_shader *nir, const struct nak_compiler *nak); diff --git a/src/nouveau/compiler/nak.rs b/src/nouveau/compiler/nak.rs index 99b4f133bc1..ac544e7e04f 100644 --- a/src/nouveau/compiler/nak.rs +++ b/src/nouveau/compiler/nak.rs @@ -20,6 +20,41 @@ use nak_from_nir::*; use std::os::raw::c_void; use util::NextMultipleOf; +fn nir_options(dev: &nv_device_info) -> nir_shader_compiler_options { + let mut op: nir_shader_compiler_options = unsafe { std::mem::zeroed() }; + + op.lower_fdiv = true; + op.lower_flrp16 = true; + op.lower_flrp32 = true; + op.lower_flrp64 = true; + op.lower_bitfield_extract = true; + op.lower_bitfield_insert = true; + op.lower_pack_half_2x16 = true; + op.lower_pack_unorm_2x16 = true; + op.lower_pack_snorm_2x16 = true; + op.lower_pack_unorm_4x8 = true; + op.lower_pack_snorm_4x8 = true; + op.lower_unpack_half_2x16 = true; + op.lower_unpack_unorm_2x16 = true; + op.lower_unpack_snorm_2x16 = true; + op.lower_unpack_unorm_4x8 = true; + op.lower_unpack_snorm_4x8 = true; + op.lower_extract_byte = true; + op.lower_extract_word = true; + op.lower_insert_byte = true; + op.lower_insert_word = true; + op.lower_cs_local_index_to_id = true; + op.lower_device_index_to_zero = true; + op.lower_uadd_sat = true; // TODO + op.lower_usub_sat = true; // TODO + op.lower_iadd_sat = true; // TODO + op.use_interpolated_input_intrinsics = true; + op.lower_mul_2x32_64 = true; // TODO + op.lower_int64_options = !0; + + op +} + #[no_mangle] pub extern "C" fn nak_compiler_create( dev: *const nv_device_info, @@ -27,7 +62,10 @@ pub extern "C" fn nak_compiler_create( assert!(!dev.is_null()); let dev = unsafe { &*dev }; - let nak = Box::new(nak_compiler { sm: dev.sm }); + let nak = Box::new(nak_compiler { + sm: dev.sm, + nir_options: nir_options(dev), + }); Box::into_raw(nak) } @@ -37,6 +75,15 @@ pub extern "C" fn nak_compiler_destroy(nak: *mut nak_compiler) { unsafe { Box::from_raw(nak) }; } +#[no_mangle] +pub extern "C" fn nak_nir_options( + nak: *const nak_compiler, +) -> *const nir_shader_compiler_options { + assert!(!nak.is_null()); + let nak = unsafe { &*nak }; + &nak.nir_options +} + #[repr(C)] struct ShaderBin { bin: nak_shader_bin, diff --git a/src/nouveau/compiler/nak_private.h b/src/nouveau/compiler/nak_private.h index e984b570083..05b48150021 100644 --- a/src/nouveau/compiler/nak_private.h +++ b/src/nouveau/compiler/nak_private.h @@ -16,6 +16,8 @@ extern "C" { struct nak_compiler { uint8_t sm; + + struct nir_shader_compiler_options nir_options; }; #ifdef __cplusplus