Skip to content
Closed
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
5 changes: 5 additions & 0 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,11 @@ side inwards:
`TEXTURE2DMS` view reads layer zero, while `TEXTURE2DMSARRAY` selects a range starting at
`FirstArraySlice` (`ArraySize = UINT_MAX` selects the remaining layers). The format-support query
advertises `MULTISAMPLE_LOAD` when the format can be sampled with MSAA and its binding pair is available.
- Xbox device slots 70 (SRV) and 71 (UAV) can select a live texture created by slot 133.
The address and resource description select the most recent compatible placement, including when
several live resources share an address. UAVs require writable backing. A 3D UAV can select one
complete mip. A missing placement or unsupported view gives a null descriptor.
Set `LEONIDA_PLACED_TEXTURE_UAV=0` to restore null placed UAVs.
- A texture is named in its T#s by an address of its own, above 4 GiB and 256 bytes apart, that nothing
dereferences; its entries leave the set and the table when it is destroyed.
- `VulkanDeviceInfo::bindless` says the Vulkan device has the features this needs: `runtimeDescriptorArray`,
Expand Down
3 changes: 3 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3637,6 +3637,9 @@ if(TARGET Vulkan::Headers)
target_compile_options(d3d12_set0_compute_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_set0_compute COMMAND d3d12_set0_compute_test)
set_tests_properties(d3d12_set0_compute PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME d3d12_placed_texture_uav_off COMMAND d3d12_set0_compute_test)
set_tests_properties(d3d12_placed_texture_uav_off PROPERTIES SKIP_RETURN_CODE 77
ENVIRONMENT "LEONIDA_PLACED_TEXTURE_UAV=0")
set(depth_uav_shader ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/cs_depth_stencil_uav.comp)
foreach(variant IN ITEMS DEPTH_STENCIL_2D DEPTH_STENCIL_ARRAY DEPTH16_2D DEPTH16_ARRAY)
set(spv ${CMAKE_CURRENT_BINARY_DIR}/generated/cs_depth_uav_${variant}.spv)
Expand Down
93 changes: 87 additions & 6 deletions runtime/test/d3d12_set0_compute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
#include "d3d12_test_shaders.h"
#include "../shims/d3d12_com.h"
#include "../shims/d3d12_xs_device.h"
#include "../src/gfx10_descriptors.h"
#include "../src/shader_library.h"

#include <array>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -53,6 +55,82 @@ Texel gradient(UINT x, UINT y) {
// The second texture: the first one point-reflected, so no texel of it is in the same place.
Texel reflected(UINT x, UINT y) { return gradient(texture_size - 1 - x, texture_size - 1 - y); }

// Exercise the console ABI: slot 133 publishes a placement and slots 70/71 receive descriptions
// plus an address, with no resource pointer. The address itself is opaque to these GPU-only tests.
HRESULT place(ID3D12Device* dev, void* address, const D3D12_RESOURCE_DESC& desc, UINT layout, ID3D12Resource** out) {
using Fn = HRESULT(WINAPI*)(ID3D12Device*, void*, const D3D12_RESOURCE_DESC*, UINT, const void*, REFIID, void**);
return reinterpret_cast<Fn>(slot(dev, 133))(dev, address, &desc, layout, nullptr, IID_PPV_ARGS(out));
}

template<class View>
void placed_view(ID3D12Device* dev, UINT method, const D3D12_RESOURCE_DESC& desc, const View& view,
const void* address, D3D12_CPU_DESCRIPTOR_HANDLE dest) {
std::array<UINT, 16> words{};
static_assert(sizeof(View) <= 10 * sizeof(UINT));
std::memcpy(words.data(), &view, sizeof(view));
std::memcpy(words.data() + 10, &address, sizeof(address));
using Fn = void(WINAPI*)(ID3D12Device*, const D3D12_RESOURCE_DESC*, const void*, D3D12_CPU_DESCRIPTOR_HANDLE);
reinterpret_cast<Fn>(slot(dev, method))(dev, &desc, words.data(), dest);
}

int check_placed_uavs(ID3D12Device* device) {
alignas(256) std::byte address{};
D3D12_RESOURCE_DESC array{};
array.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
array.Width = array.Height = 8;
array.DepthOrArraySize = 6;
array.MipLevels = array.SampleDesc.Count = 1;
array.Format = DXGI_FORMAT_R32_UINT;
array.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
auto face = array;
face.DepthOrArraySize = 1;
Ref<ID3D12Resource> older, newer;
EXPECT(SUCCEEDED(place(device, &address, array, 3, &older.p)));
EXPECT(SUCCEEDED(place(device, &address, face, 3, &newer.p)));

D3D12_UNORDERED_ACCESS_VIEW_DESC view{};
view.Format = array.Format;
view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY;
view.Texture2DArray.FirstArraySlice = 5;
view.Texture2DArray.ArraySize = 1;
using Words = std::array<UINT, 8>;
Words expected{}, got{};
const D3D12_CPU_DESCRIPTOR_HANDLE dest{reinterpret_cast<SIZE_T>(got.data())};
device->CreateUnorderedAccessView(older.p, nullptr, &view, {reinterpret_cast<SIZE_T>(expected.data())});
EXPECT(expected != Words{});
const char* value = std::getenv("LEONIDA_PLACED_TEXTURE_UAV");
const bool enabled = !value || std::strcmp(value, "0") != 0;
placed_view(device, 71, array, view, &address, dest);
EXPECT(got == (enabled ? expected : Words{}));
older.reset();
got.fill(~0u);
placed_view(device, 71, array, view, &address, dest);
EXPECT(got == Words{}); // The remaining single-layer image cannot supply layer 5.

auto volume = face;
volume.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D;
volume.DepthOrArraySize = 8;
volume.MipLevels = 2;
Ref<ID3D12Resource> volume_target;
EXPECT(SUCCEEDED(place(device, &address, volume, 3, &volume_target.p)));
view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D;
view.Texture3D = {1, 0, 4};
placed_view(device, 71, volume, view, &address, dest);
leonida::gfx10::Image decoded{};
if (enabled) {
EXPECT(leonida::gfx10::decode(got, decoded) && decoded.type == leonida::gfx10::ImageType::image_3d &&
decoded.first_mip == 1 && decoded.mip_count == 1);
} else {
EXPECT(got == Words{});
}
view.Texture3D.WSize = 2;
got.fill(~0u);
placed_view(device, 71, volume, view, &address, dest);
EXPECT(got == Words{});
std::printf("placed UAVs: %u matching views, %u null controls\n", enabled ? 2 : 0, enabled ? 2 : 4);
return 0;
}

} // namespace

int main() {
Expand Down Expand Up @@ -163,10 +241,12 @@ int main() {
texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texture_desc.SampleDesc.Count = 1;
Ref<ID3D12Resource> textures[2], upload, output, readback;
for (auto& texture : textures)
EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &texture_desc,
D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS(&texture.p))));
EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &texture_desc,
D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS(&textures[0].p))));
alignas(256) std::byte placement{};
EXPECT(SUCCEEDED(place(device.p, &placement, texture_desc, 8, &textures[1].p)));
EXPECT(check_placed_uavs(device.p) == 0);
// The upload buffer: texture A at 0, texture B at 2048 (8 rows of the 256-byte pitch).
constexpr UINT64 b_offset = 2048;
const auto upload_desc = buffer_desc(4096);
Expand Down Expand Up @@ -219,8 +299,9 @@ int main() {
srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srv.Texture2D = {0, 1, 0, 0.0f};
device->CreateShaderResourceView(textures[i].p, &srv,
D3D12_CPU_DESCRIPTOR_HANDLE{SIZE_T(view_cpu + i * view_step)});
const D3D12_CPU_DESCRIPTOR_HANDLE dest{SIZE_T(view_cpu + i * view_step)};
if (i == 0) device->CreateShaderResourceView(textures[i].p, &srv, dest);
else placed_view(device.p, 70, texture_desc, srv, &placement, dest);
}
// Slot 2: bytes no view was made for. The hash table has no entry for them.
std::uint32_t unknown[8];
Expand Down
Loading