Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
}
if (srv_count > 32)
return refuse("more than 32 SRVs");
if (uav_count > 8)
return refuse("more than 8 UAVs");
if (uav_count > 16)
return refuse("more than 16 UAVs");

for (size_t i = 0; i < program.samplers.size(); ++i) {
const auto &s = program.samplers[i];
Expand Down
4 changes: 2 additions & 2 deletions src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ const char* load_compute_translation(ComputeTranslation& tr, ID3D12Device* devic
: line.rfind("udsrc", 0) == 0 ? "an entry value that is not a root constant or a buffer descriptor word"
: line.rfind("smp", 0) == 0 ? "a sampler that is not a plain static one" : "an unknown manifest line";
}
if (tr.uds.size() != declared_uds || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8)
if (tr.uds.size() != declared_uds || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 16)
return "entry value, input or output count";
for (const ComputeTranslation::Slot& ud : tr.uds) {
const auto& slots = ud.source >= ComputeTranslation::output_word3 ? tr.uavs : tr.srvs;
Expand Down Expand Up @@ -658,7 +658,7 @@ bool translate_compute_natively(ComputeTranslation& tr, ID3D12Device* device)
tr.samplers.comparison.push_back(sampler.comparison);
tr.samplers.lod_limits.push_back(sampler.explicit_lod && !sampler.comparison);
}
if (tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8)
if (tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 16)
throw std::runtime_error("more entry values, inputs or outputs than the dispatch path binds");
// Direct modules use shader model 6.6 with WaveSize(32).
if (adapter_32_lane_waves(device) != 1)
Expand Down
3 changes: 2 additions & 1 deletion src/startup_stubs/translated_sampler_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ inline HRESULT create_translated_root(ID3D12Device* device, UINT constants, UINT
bool* serialized = nullptr)
{
if (serialized) *serialized = false;
D3D12_ROOT_PARAMETER parameters[11]{};
D3D12_ROOT_PARAMETER parameters[19]{};
parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
parameters[0].Constants.Num32BitValues = constants;
// A compute program's outputs (u0..) follow its resources in the same table; bounded heap SRVs follow in space 2.
Expand All @@ -148,6 +148,7 @@ inline HRESULT create_translated_root(ID3D12Device* device, UINT constants, UINT
const D3D12_DESCRIPTOR_RANGE sampler_range{
D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, translated_sampler_count, 0, translated_sampler_space, 0};
UINT count = sampler_root_parameter(srvs + uavs + heap_srvs);
if (count + atomic + (samplers.heap ? 1u : 0u) > std::size(parameters)) return E_INVALIDARG;
for (UINT i = 0; i < atomic; ++i) {
auto &param = parameters[count++];
param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
Expand Down
53 changes: 50 additions & 3 deletions tests/native_uav_slots_check.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Check the DXIL shader flag for more than 8 UAV slots in direct compute.
"""Check the DXIL shader flag and runtime manifest limit (16 UAVs) in direct compute.

DXC sets flag 0x8000 when a module declares more than 8 UAV slots, and the validator
refuses a module whose declared flags differ ("Flags must match usage"). Each program
stores to N buffer descriptors read from one table, so the module declares N UAVs.
8 UAVs must compile without the flag (the negative control); 9 must compile with it.
- Container path: 8 UAVs compiles without the flag; 9, 16 and 17 compile with it.
- Request manifest path (Refs #3224): 8, 9 and 16 UAVs publish `<key>.txt` with
`uav 0`..`uav N-1` and `<key>.cs.cso`; 17 UAVs is refused with `more than 16 UAVs`.
"""
from pathlib import Path
import re
Expand All @@ -12,6 +14,8 @@
import tempfile

from native_direct_container_check import compute, words
from startup_compute_translate_check import state_a, write_request
from startup_gfx2hlsl_compute_check import USER7, root_blob


def program(uavs):
Expand All @@ -30,10 +34,27 @@ def program(uavs):
return compute(words(*code), table=True)


def request_program(uavs):
# Table 1 base is in s6 (root_blob: param 0 = 2 constants s4..s5, param 1 = table s6).
code = [0xBE940306, 0xBE950380] # s_mov_b32 s20, s6; s_mov_b32 s21, 0
for k in range(uavs):
# s_load_dwordx4 s[24+4k:27+4k], s[20:21], 32*k (srsrc = 6 + k, up to 22 for 17 UAVs)
code += [0xF408000A | (24 + 4 * k) << 6, 0xFA000000 | 32 * k]
code += [
0xBF8CC07F, # s_waitcnt lgkmcnt(0)
(26 << 25) | (5 << 17) | 130, # v_lshlrev_b32 v5, 2, v0
]
for k in range(uavs):
# buffer_store_dword v0, v5, s[24+4k:27+4k], 0 offen
code += [0xE0701000, 0x80000005 | (6 + k) << 16]
code.append(0xBF810000) # s_endpgm
return words(*code)


def main(cli, sdk):
with tempfile.TemporaryDirectory() as temp:
work = Path(temp)
for uavs in (8, 9):
for uavs in (8, 9, 16, 17):
source = work / f'uav{uavs}.c67'
source.write_bytes(program(uavs))
shader = source.with_suffix('.cso')
Expand All @@ -44,6 +65,32 @@ def main(cli, sdk):
assert declared == uavs, (uavs, declared, run.stdout)
print(f'{uavs} UAVs: compiled and validated')

# Runtime manifest publication: 8, 9 and 16 UAVs publish; 17 UAVs is refused.
sa = state_a((32, 1, 1), USER7)
root = root_blob()
for uavs in (8, 9, 16, 17):
req_dir = work / f'req_{uavs}'
req_dir.mkdir()
key = f'{write_request(req_dir, request_program(uavs), sa, root=root):016x}'
run = subprocess.run([cli, sdk, work / 'cache', 'gfx1013-direct-cs@0', '--requests', req_dir, req_dir],
capture_output=True, text=True, timeout=60)
manifest = req_dir / f'{key}.txt'
cso = req_dir / f'{key}.cs.cso'
fail = req_dir / f'{key}.fail'
if uavs <= 16:
assert run.returncode == 0 and manifest.is_file() and cso.is_file() and not fail.exists(), (
uavs, run.stdout, run.stderr, fail.read_text() if fail.exists() else '')
text = manifest.read_text()
for k in range(uavs):
assert f'uav {k} table 1 {32 * k}\n' in text, (uavs, k, text)
assert f'uav {uavs} ' not in text, (uavs, text)
print(f'{uavs} UAVs: runtime manifest published')
else:
assert not manifest.exists() and cso.is_file(), (uavs, run.stdout, run.stderr)
assert 'unsupported startup runtime manifest bindings: more than 16 UAVs' in run.stdout, (
uavs, run.stdout, run.stderr)
print(f'{uavs} UAVs: runtime manifest refused (more than 16 UAVs)')


if __name__ == '__main__':
if len(sys.argv) != 3:
Expand Down
1 change: 1 addition & 0 deletions tests/startup_triage_run_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ def check_every_shader_reason_entry_is_reachable(failures: list[str]) -> None:
("unsupported startup runtime manifest bindings: SRV kind texture_srv 2d array",
"runtime manifest: SRV kind texture_srv 2d array"),
("unsupported startup runtime manifest bindings: more than 8 UAVs", "runtime manifest: more than 8 UAVs"),
("unsupported startup runtime manifest bindings: more than 16 UAVs", "runtime manifest: more than 16 UAVs"),
("native compute +0x1c: unproven resource descriptor s12", "unproven resource descriptor"),
("native compute +0x20: unbound numeric SGPR s0", "unbound numeric SGPR"),
("unknown gfx1013 instruction format at byte 24", "undecodable word"),
Expand Down
2 changes: 1 addition & 1 deletion tools/startup/triage_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
r"(?:SRV|UAV) kind [a-z0-9_]{1,32}(?: [a-z0-9-]{1,20})?(?: array)?|"
r"(?:SRV|UAV) registers not contiguous|group size has a zero dimension|"
r"root constants above root parameter 15|view above root parameter 15|"
r"more than (?:8 root constants in one root parameter|32 user data words|32 SRVs|8 UAVs)|"
r"more than (?:8 root constants in one root parameter|32 user data words|32 SRVs|(?:8|16) UAVs)|"
r"resource heap view|sampler heap|comparison sampler|"
r"stride words from a view that is not one raw vector SRV)\Z"), r"runtime manifest: \1"),
(re.compile(r"graphics request key mismatch\b"), "graphics request key mismatch"),
Expand Down
Loading