Skip to content
Merged
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,7 @@ if(OFFSCREEN_AGILITY_620_DIR)
endforeach()
target_compile_definitions(offscreen_check PRIVATE OFFSCREEN_AGILITY_620)
target_compile_definitions(startup_indirect_draw_indexed PRIVATE OFFSCREEN_AGILITY_620)
target_compile_definitions(startup_stream_consumer PRIVATE OFFSCREEN_AGILITY_620)
endif()
set(OFFSCREEN_WARP_DIR "" CACHE PATH "Directory containing an app-local x64 d3d10warp.dll (Microsoft.Direct3D.WARP)")
if(OFFSCREEN_WARP_DIR)
Expand Down
13 changes: 13 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17819,3 +17819,16 @@ ctest --preset dev --no-tests=error -R '^(pixel_aot_f16_cvt_norm_warp|pixel_aot_
Linux controls (including exhaustive verification against `fractions.Fraction` across all 63,488 finite binary16 values and single-instruction DPP16/DPP8 permutation-to-intrinsic checks pinning `QuadReadAcross{X,Y,Diagonal}` and `QuadReadLaneAt` lane order), `form_coverage_check.check_f16_cvt_norm_forms`, and Python mutation checks ran locally; Ubuntu LLVM 15 `pixel_aot_binary` round-trips run on PR CI, while `pixel_aot_f16_cvt_norm_{warp,hardware}` runs in `dev`/`release` presets and `main` CI (not `ctest --preset pr`). The draw harness compiles each fixture both optimized (`-denorm preserve`) and unoptimized (`-Od -denorm ftz`) so DXC retains the pure-`uint` conversion arithmetic in DXIL rather than constant-folding `plain_e32`/`plain_e64`/`sdwa` to immediate stores (note: because no binary32 float ops are emitted in `cvt_norm_{i16,u16}_f16`, `-denorm ftz` produces the same integer instructions as `-denorm preserve`).

Independent Windows 11 (`26200.9974`, DXC `1.9.2602.17`, `debug_layer=unavailable`) measurements on `bd8f6f42` ([comment 1](https://github.com/R0Y00/Xbox2Windows/pull/2857#issuecomment-7196200555)) and `3100f363` ([comment 2](https://github.com/R0Y00/Xbox2Windows/pull/2857#issuecomment-7200844836)) passed `pixel_aot_f16_cvt_norm_hardware` (`AMD Radeon RX 9070 XT` `1002:7550`, driver `32.0.32029.2010`) and `pixel_aot_f16_cvt_norm_warp` with `max_absolute_error=0`, all 20 mutation draws mismatching, and DXIL disassembly confirming the `-Od` pass retains the `mul`/`lshr`/`shl` integer path. Scope limits: under `#839`'s static finite-proof contract (`half16_arith_source` / `half16_dpp_source`), operands are statically known per-lane uniform values, so device draw readbacks do not distinguish lane-routing changes on `dpp16`/`dpp8` (the permutation-to-intrinsic mapping is pinned statically in `check_f16_cvt_norm_controls`), mutation draws compile optimized rather than `-Od`, and the exhaustive 63,488-value check runs in Python rather than on-device.


## Native raw pixel buffer UAV binding

The native graphics cache and draw stand-in support a single raw pixel UAV from a tracked descriptor table for a direct non-indexed draw without SRVs. The manifest records the table parameter and byte offset; the runtime requires an aligned raw R32_TYPELESS buffer view with valid bounds, UAV resource flags and compatible state, retains the resource, and orders consecutive UAV uses. Typed/structured views, mixed views and other draw paths are outside this slice (#3212, #3215; separate from #3094/#2981).

```powershell
cmake --preset dev
cmake --build --preset dev --target startup_stream_consumer d3d12_xs_shim compile_dxil native_raw_buffer_view_check
ctest --preset dev --no-tests=error -j1 -R '^(native_pixel_raw_uav_(warp|hardware)|native_raw_buffer_view_controls)$'
```

Repeat with the release preset. The source-built shader pair goes through request publication, native DXIL, actual PSO/draw and GPU readback. The fixture checks full buffer and color-target contents, nonzero/short/end views, decoy and invalid descriptors; the validator also checks alignment and bounds. Local RX 7900 XT/WARP Debug and Release runs passed 54 cases (3,456 DWORDs and 1,728 pixels); the independent review over main 886a5a28 reproduced the same counts on RTX 4060 Laptop and WARP with the D3D12 debug layer enabled and zero errors. Actual title rendering impact is not established.
8 changes: 8 additions & 0 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,14 @@ std::optional<std::string> format_graphics_runtime_manifest(const DirectGraphics
const auto &b = bindings.views[bindings.srv_count + j];
if (b.root_parameter >= 16 || b.array_count != 1)
return std::nullopt;
if (b.kind == ComputeViewKind::raw_buffer_uav) {
// First slice: one pixel UAV with no other resource views. Vertex stores,
// mixed views and aliases need their own runtime acceptance.
if (uav_count != 1 || bindings.srv_count || !pair.vertex.bindings.empty())
return std::nullopt;
uav_lines << "uav " << j << " raw table " << b.root_parameter << ' ' << b.byte_offset << '\n';
continue;
}
if (b.kind != ComputeViewKind::texture_uav && b.kind != ComputeViewKind::half4_texture_uav)
return std::nullopt;
if (b.image_dimension != 1 && b.image_dimension != 5)
Expand Down
3 changes: 2 additions & 1 deletion src/native_buffer_store_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ inline bool native_buffer_store_view(const ComputeViewBinding &binding, D3D12_UN
if (view.Buffer.StructureByteStride) return false;
UINT stride = binding.required_bytes;
if (binding.kind == ComputeViewKind::raw_buffer_uav) {
if (view.Format != DXGI_FORMAT_R32_TYPELESS || view.Buffer.Flags != D3D12_BUFFER_UAV_FLAG_RAW)
if (view.Format != DXGI_FORMAT_R32_TYPELESS || view.Buffer.Flags != D3D12_BUFFER_UAV_FLAG_RAW ||
view.Buffer.FirstElement % (D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT / 4))
return false;
stride = 4;
} else if (view.Buffer.Flags) {
Expand Down
52 changes: 44 additions & 8 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

// A pixel-stage image store (#1996 item F, #2742): tools/startup/gfx2hlsl.py writes 'uav N tex2d|tex2da table P O'
// for the RWTexture2D<float4> or RWTexture2DArray<float4> at u<N>, whose descriptor is at byte O of the title's
// root table P. Only that form is read; a view qualifier or a 'channels' field, as in the compute line, is refused.
// root table P. The native compiler also emits raw table views; a view qualifier or a 'channels' field, as in the compute line, is refused.
// A trailing 'typedload' means the binding must also support a typed UAV load. The translator does not emit it
// for a component store, which does not read the texel.
struct PixelUav {
unsigned index = 0, parameter = 0, offset = 0;
bool array = false;
bool raw = false;
bool needs_typed_load = false;
};
constexpr unsigned pixel_uav_limit = 8;
Expand All @@ -39,16 +40,18 @@ const char* read_pixel_uav_line(const std::string& line, PixelUav& out)
};
if (w.size() < 2 || w[0] != "uav" || !number(w[1], out.index)) return "malformed view index";
if (w.size() < 3) return "missing view kind";
if (w[2] == "raw" || w[2] == "table") return "buffer view (raw uav) is not bound";
if (w[2] != "tex2d" && w[2] != "tex2da") return "only tex2d and tex2da views are bound";
if (w[2] == "table") return "legacy untyped buffer view is not bound";
if (w[2] != "tex2d" && w[2] != "tex2da" && w[2] != "raw") return "only tex2d, tex2da and raw views are bound";
out.array = w[2] == "tex2da";
out.raw = w[2] == "raw";
if (w.size() > 3 && (w[3] == "float" || w[3] == "uint" || w[3] == "sint")) return "a view qualifier is not read for pixel stores";
if (w.size() < 4 || w[3] != "table") return "view source is not a table";
if (w.size() < 6) return "missing table parameter or offset";
if (w.size() > 7 || (w.size() == 7 && w[6] != "typedload")) return "unexpected field after the table offset";
if (!number(w[4], out.parameter) || out.parameter >= 16) return "table parameter out of range";
if (!number(w[5], out.offset)) return "malformed table offset";
out.needs_typed_load = w.size() == 7;
if (out.raw && (out.needs_typed_load || out.offset % 32)) return "raw view requires an aligned table record without typedload";
return nullptr;
}

Expand Down Expand Up @@ -500,7 +503,7 @@ void load_translation(Translation& tr, const std::string& rtv_request = {})
load_pso_recipes(tr);
if (previously_missing) InterlockedDecrement(&translation_missing);
InterlockedIncrement(&translation_ready);
log("x2w-draw pipeline %016llx translated: %zu entry values, %zu resources, %zu writable textures, %zu static samplers, sampler_heap=%u",
log("x2w-draw pipeline %016llx translated: %zu entry values, %zu resources, %zu writable views, %zu static samplers, sampler_heap=%u",
tr.key, tr.uds.size(), tr.srvs.size(), tr.uavs.size(), tr.samplers.statics.size(), tr.samplers.heap ? 1u : 0u);
}

Expand Down Expand Up @@ -2361,7 +2364,7 @@ struct PixelUavBinding {
D3D12_UNORDERED_ACCESS_VIEW_DESC view{};
};

// draw_lock held. The writable textures of tr (#1996 F), from the unordered-access views the title created at
// draw_lock held. The writable views of tr (#1996 F), from the unordered-access views the title created at
// their table entries (pixel_uav_view). False, with the reason logged, when one cannot be bound as the program
// expects: the draw is then not translated, and no other view is bound in its place.
bool resolve_pixel_uavs(const Translation& tr, const Pass& pass, PixelUavBinding* out)
Expand All @@ -2374,6 +2377,11 @@ bool resolve_pixel_uavs(const Translation& tr, const Pass& pass, PixelUavBinding
};
for (std::size_t i = 0; i < tr.uavs.size(); ++i) {
const PixelUav& uav = tr.uavs[i];
if (uav.raw) {
const UINT stride = device_of(the_device)->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
if (stride < 32 || uav.offset % stride)
return refuse(i, "raw UAV offset is not a descriptor boundary", uav.offset);
}
const x2w_startup::ViewTable& table = pass.view_tables[uav.parameter];
if (!table.address) return refuse(i, "no descriptor table at the parameter", uav.parameter);
const u64 entry = table.record(uav.offset, 32);
Expand Down Expand Up @@ -2401,8 +2409,21 @@ bool resolve_pixel_uavs(const Translation& tr, const Pass& pass, PixelUavBinding
title_view.Format = desktop_format(title_view.Format);
}
const D3D12_RESOURCE_DESC desc = texture->GetDesc();
const char* reason = pixel_uav_view(device_of(the_device), desc, described ? &title_view : nullptr,
uav.array, out[i].view, uav.needs_typed_load);
const char* reason = nullptr;
if (uav.raw) {
const auto* info = resource_info(resource);
if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS))
return refuse(i, "resource lacks ALLOW_UNORDERED_ACCESS", record.resource);
const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::raw_buffer_uav, uav.parameter, uav.offset, uav.index, 4};
if (!described || record.counter || !info || info->initial_state != D3D12_RESOURCE_STATE_COMMON ||
desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
!x2w::native_buffer_store_view(binding, title_view, desc.Width))
return refuse(i, "incompatible raw buffer UAV", record.resource);
out[i].view = title_view;
} else {
reason = pixel_uav_view(device_of(the_device), desc, described ? &title_view : nullptr,
uav.array, out[i].view, uav.needs_typed_load);
}
if (reason) {
static LONG refused_view;
if (first_calls(refused_view, 16))
Expand Down Expand Up @@ -2524,8 +2545,17 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI
ReleaseSRWLockExclusive(&draw_lock);
return false;
}
const bool raw_uav = std::any_of(tr->uavs.begin(), tr->uavs.end(), [](const PixelUav& uav) { return uav.raw; });
// ponytail: prove direct draws with one writable buffer first. SRVs and indexed
// draws can alias it through guest addresses, so do not guess their independence.
if (raw_uav && (indexed || indirect || tr->uavs.size() != 1 || !tr->srvs.empty())) {
log("x2w-draw %016llx raw UAV requires one writable view and a direct non-indexed draw without SRVs", tr->key);
ReleaseSRWLockExclusive(&draw_lock);
return false;
}
PixelUavBinding uav_bindings[pixel_uav_limit];
if (!resolve_pixel_uavs(*tr, pass, uav_bindings)) {
if (!resolve_pixel_uavs(*tr, pass, uav_bindings) ||
(raw_uav && !retain_with_recording(self, x2w_startup::ComPtr<ID3D12Resource>(uav_bindings[0].resource)))) {
ReleaseSRWLockExclusive(&draw_lock);
return false;
}
Expand Down Expand Up @@ -2901,6 +2931,12 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI
for (UINT j = 0; j < tr->uavs.size(); ++j) {
const D3D12_CPU_DESCRIPTOR_HANDLE dest{draw_heap->GetCPUDescriptorHandleForHeapStart().ptr + SIZE_T{first + n + j} * draw_heap_increment};
require_state(self, uav_bindings[j].resource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
if (tr->uavs[j].raw) {
D3D12_RESOURCE_BARRIER barrier{};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
barrier.UAV.pResource = uav_bindings[j].resource;
list->ResourceBarrier(1, &barrier);
}
device_of(the_device)->CreateUnorderedAccessView(uav_bindings[j].resource, nullptr, &uav_bindings[j].view, dest);
static LONG shown;
if (first_calls(shown, 6)) {
Expand Down
1 change: 1 addition & 0 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "state_block_blend.h"
#include "title_heap_memory.h"
#include "startup_stubs/xmem_section_buffer.h"
#include "native_buffer_store_view.h"
#ifdef X2W_NATIVE_SHADERS // d3d12_xs_shim only: the C++ shader compiler (startup_stubs/d3d12_compute_dispatch.inl)
#include "gfx1013_compute_native.h"
#include "shader_dxil_compiler.h"
Expand Down
14 changes: 14 additions & 0 deletions tests/cmake/native_pixel_raw_uav.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Source-built native pixel buffer writes through the runtime-published graphics cache.
add_executable(native_raw_buffer_view_check tests/native_raw_buffer_view_check.cpp)
target_include_directories(native_raw_buffer_view_check PRIVATE src)
target_compile_features(native_raw_buffer_view_check PRIVATE cxx_std_17)
add_test(NAME native_raw_buffer_view_controls COMMAND native_raw_buffer_view_check)
if(TARGET compile_dxil AND TARGET startup_stream_consumer
AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
foreach(backend IN ITEMS warp hardware)
add_test(NAME native_pixel_raw_uav_${backend} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_pixel_raw_uav_check.py"
"$<TARGET_FILE:compile_dxil>" "$<TARGET_FILE:startup_stream_consumer>" "${DXC_BIN_DIR}" ${backend})
set_tests_properties(native_pixel_raw_uav_${backend} PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120)
endforeach()
endif()
Loading
Loading