diff --git a/docs/experiments/native-mesh-vector-alu.md b/docs/experiments/native-mesh-vector-alu.md index e220acadf..b9315b494 100644 --- a/docs/experiments/native-mesh-vector-alu.md +++ b/docs/experiments/native-mesh-vector-alu.md @@ -79,3 +79,25 @@ and exports the bitcast result through POS0.x. `python -B tests/native_direct_mesh_check.py ` or `ctest --preset release --no-tests=error -R '^native_direct'`. + +## Mesh median and base-2 exponentiation + +The mesh vector ALU admits VOP3 `v_med3_f32` and VOP1 or VOP3 +`v_exp_f32` through the shared direct float ALU. The median path tests +all three inputs for NaN and selects the folded FMin result in that case. +When all operands are numeric it uses the median expression. The +exponent uses DXIL Exp (opcode 21), which evaluates a base-2 power. Both +operations accept source abs and neg in their valid encoded positions. + +Clamp, omod, op_sel, SDWA and DPP stay refused. The wide exponent also +refuses nonzero unused source fields and modifiers on unused operands. +The fixture evaluates the DXIL feeding the position export. It covers a +NaN in each median operand, multiple NaNs, infinities, and positive and +negative exponents. + +```powershell +ctest --preset pr --no-tests=error -R '^native_mesh_med3_exp_ir$' +``` + +The [mesh census](https://github.com/R0Y00/Xbox2Windows/issues/3703#issuecomment-7368154618) +reports 67 first refusals at the median and 23 at the exponent. diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index c01e66a99..437b31f2a 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -3204,12 +3204,14 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout } alu.write(i.dst,result); if (!full_exec) partial_writes.insert(i.dst); - } else if ((i.name=="v_min_f32" || i.name=="v_bfi_b32") && + } else if ((i.name=="v_min_f32" || i.name=="v_bfi_b32" || i.name=="v_med3_f32" || i.name=="v_exp_f32") && (i.dpp_control || i.subword || (i.wide && (i.a&0x7800)) || i.clamp || i.scale)) { // Only the plain e32/e64 forms: DPP, SDWA, op_sel, clamp and omod stay refused. // v_min_f32 abs/neg are sign-bit operations in the shared float ALU; v_bfi_b32 // takes no float modifiers there. refuse(pc,"unsupported mesh "+iname+" operand modifiers"); + } else if (i.name=="v_exp_f32" && i.wide && (i.src[1] || i.src[2] || ((i.abs|i.neg)&6))) { + refuse(pc,"unsupported mesh v_exp_f32 unused operands"); } else if (vector_exec && (i.name=="v_trunc_f32" || i.name=="v_floor_f32" || i.name=="v_ceil_f32" || i.name=="v_rndne_f32" || i.name=="v_fract_f32" || i.name=="v_cvt_u32_f32" || i.name=="v_cvt_i32_f32" || i.name=="v_mul_u32_u24" || i.name=="v_lshl_or_b32" || @@ -3219,9 +3221,9 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout i.name=="v_subrev_f32" || i.name=="v_fmac_f32" || i.name=="v_fmamk_f32" || i.name=="v_fmaak_f32" || i.name=="v_rsq_f32" || i.name=="v_rcp_f32" || i.name=="v_rcp_iflag_f32" || i.name=="v_sqrt_f32" || i.name=="v_ashrrev_i32" || i.name=="v_fma_mixlo_f16" || i.name=="v_fma_mixhi_f16" || i.name=="v_fma_mix_f32" || i.name=="v_pack_b32_f16" || - i.name=="v_log_f32" || i.name=="v_sin_f32" || i.name=="v_cos_f32" || + i.name=="v_exp_f32" || i.name=="v_log_f32" || i.name=="v_sin_f32" || i.name=="v_cos_f32" || i.name.substr(0,15)=="v_cvt_f32_ubyte" || i.name=="v_min_u32" || i.name=="v_max_f32" || - i.name=="v_min_f32" || i.name=="v_bfi_b32" || + i.name=="v_min_f32" || i.name=="v_med3_f32" || i.name=="v_bfi_b32" || i.name=="v_mad_u32_u24" || i.name=="v_add3_u32" || i.name=="v_xad_u32" || i.name=="v_bfe_u32" || i.name=="v_mov_b32" || i.name=="v_add_nc_u32" || i.name=="v_sub_nc_u32" || i.name=="v_subrev_nc_u32" || i.name=="v_add_co_ci_u32" || i.name=="v_lshlrev_b32" || i.name=="v_sub_co_u32" || i.name=="v_subrev_co_u32" || i.name=="v_lshrrev_b32" || i.name=="v_or_b32" || i.name=="v_or3_b32" || i.name=="v_and_or_b32" || diff --git a/tests/cmake/native_mesh_med3_exp.cmake b/tests/cmake/native_mesh_med3_exp.cmake new file mode 100644 index 000000000..9f196ecfa --- /dev/null +++ b/tests/cmake/native_mesh_med3_exp.cmake @@ -0,0 +1,6 @@ +if(EXISTS "${INTAKE_PYTHON}" AND TARGET compile_dxil) + add_test(NAME native_mesh_med3_exp_ir + COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_mesh_med3_exp_check.py" + "$" "${DXC_BIN_DIR}") + set_tests_properties(native_mesh_med3_exp_ir PROPERTIES TIMEOUT 60) +endif() diff --git a/tests/native_mesh_med3_exp_check.py b/tests/native_mesh_med3_exp_check.py new file mode 100644 index 000000000..44db90f9e --- /dev/null +++ b/tests/native_mesh_med3_exp_check.py @@ -0,0 +1,130 @@ +"""Evaluate the DXIL feeding POS0.x for mesh median and base-2 exponentiation.""" +from functools import lru_cache +import math +from pathlib import Path +import re +import struct +import subprocess +import sys +import tempfile + +from native_direct_mesh_check import TRIANGLE_LAYOUT, triangle +from native_mesh_small_alu_pack_check import raw_x, vop3 + + +VALUE = r'%[\w.]+' +EXP = 0x25 +MED3 = 0x157 + + +def exp_e32(src): + return 0x7E000000 | (1 << 17) | (EXP << 9) | src + + +def float_word(value): + return struct.unpack('