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
25 changes: 19 additions & 6 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,13 @@ side inwards:
covers a full 2048-sampler D3D12 heap plus room for literal and static S#s.
- 2D images: up to 65536.
- storage arrays: up to 4096 each, capped by their dimension's sampled array or by 256 for storage-only 1D arrays.
- 2D-array images up to 16384, 3D and 1D images up to 4096 each (the title streams more cube maps, texture
arrays and 1D lookups than the defaults hold: each distinct T# of one takes its own index, and a native boot
filled the 1024 2D-array and 256 1D indices during the story load).
- 2D-array, 3D and 1D images: up to 65536 each, as many as 2D, grown together (one count for the three while the
limits stop them short of it), so no dimension is favoured. A texture keeps an index for each distinct T# of
it for as long as it lives, and which dimensions its textures have is the title's choice: a native boot
filled the default 1024 2D-array and 256 1D indices during the story load, and world runs filled the 4096 1D
indices of the sizes before this with 4092 T#s of 4090 live 1D textures. The bound is memory, not the
device's limits (RADV allows 8388606 sampled images): every element of every array is in each generation's
descriptor pool, used or not.

Growth leaves 64 descriptors of each limit to the other sets of a pipeline layout. It also stays within
`maxPerSetDescriptors`, which never shrinks the default counts, because a layout past it may still be
Expand All @@ -698,9 +702,18 @@ side inwards:
shader reads the fallback. `d3d12_descriptor_test` then fills each short array to its last index and checks that
the next view and sampler are refused.
The MS arrays keep their default counts. On an RTX 5070 (driver 621.24, 1048576 of each type
and 4000 samplers) the set has 65536 2D images, 3936 samplers, 16384 2D-array, 4096 3D and 4096 1D images and
4096 storage indices in each dimension: 152929 descriptors, 5-10 MiB at 32-64 bytes a descriptor. The device prints the counts it chose, and
`bindless_sizing_test` checks the rules on synthetic limits.
and 4000 samplers) the set has 65536 2D, 2D-array, 3D and 1D images each, 3936 samplers and 4096 storage indices
in each dimension: 325729 descriptors with the MS pairs, 10-20 MiB at 32-64 bytes a descriptor. RADV (Mesa 26.3,
the Raphael iGPU and the RX 7900 XTX) and llvmpipe get the same image counts and 4096 samplers. The device prints
the counts it chose (`bindless set:`), `bindless_sizing_test` checks the rules on synthetic limits, and
`vk_bindless_dimensions_test` reads 5000 live 1D, 2D-array and 3D images each through their indices in a set
sized from the device's own limits.
- A T# the title writes into a console descriptor heap that set 0 has no room for is refused, and counted in the
heap's `unbound T#s by reason` line, as `the bindless array of the T#'s dimension is full` (or `the bindless
storage arrays of the T#'s dimension are full` for a UAV whose dimension has free indices only above the shorter
storage arrays), not as `no view for the T#'s format or range`. The first such refusal of a dimension also logs
`a bindless image array is full; dimension N (name)` with the indices, the T#s and textures that hold them and how
many of those textures are still registered at their address (a texture's indices go back when it goes).
- An image view has one index in its dimension (2D, 2D array, 3D, 1D, 2DMS, 2DMS array or 1D array), shared by the
bindings for that dimension. The runtime adds sampled-image bindings in pairs for 2DMS and 2DMS array:
20/21 for floating-point and normalized color, 22/23 for unsigned integers, and 24/25 for signed integers.
Expand Down
28 changes: 28 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,34 @@ if(TARGET Vulkan::Headers)
add_test(NAME vk_null_descriptor COMMAND vk_null_descriptor_test)
set_tests_properties(vk_null_descriptor PROPERTIES SKIP_RETURN_CODE 77)
endif()
# More than 4096 live 1D, 2D-array and 3D images, each read through its bindless index, in a set sized from the
# device's limits; a full array's refusal reason and indices coming back. The shader is GLSL; without
# glslangValidator the test skips.
add_executable(vk_bindless_dimensions_test test/vk_bindless_dimensions_test.cpp)
target_link_libraries(vk_bindless_dimensions_test PRIVATE Vulkan::Headers ${CMAKE_DL_LIBS})
if(WIN32)
target_compile_definitions(vk_bindless_dimensions_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
endif()
if(MSVC)
target_compile_options(vk_bindless_dimensions_test PRIVATE /W4 /permissive- /utf-8)
endif()
if(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
set(_bindless_dimensions_spv ${CMAKE_CURRENT_BINARY_DIR}/generated/cs_bindless_dimensions.spv)
add_custom_command(OUTPUT ${_bindless_dimensions_spv}
COMMAND ${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE} -V --target-env vulkan1.3 -o ${_bindless_dimensions_spv}
${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/cs_bindless_dimensions.comp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/cs_bindless_dimensions.comp
COMMENT "Compiling the bindless dimensions test shader" VERBATIM)
target_sources(vk_bindless_dimensions_test PRIVATE ${_bindless_dimensions_spv})
target_compile_definitions(vk_bindless_dimensions_test PRIVATE
LEONIDA_TEST_BINDLESS_DIMENSIONS_SPV="${_bindless_dimensions_spv}")
else()
message(STATUS "glslangValidator not found: vk_bindless_dimensions_test skips")
endif()
if(BUILD_TESTING)
add_test(NAME vk_bindless_dimensions COMMAND vk_bindless_dimensions_test)
set_tests_properties(vk_bindless_dimensions PROPERTIES SKIP_RETURN_CODE 77)
endif()
# CPU-only: the bindless set's array sizes from synthetic device limits.
add_executable(bindless_sizing_test test/bindless_sizing_test.cpp)
target_link_libraries(bindless_sizing_test PRIVATE Vulkan::Headers)
Expand Down
47 changes: 32 additions & 15 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7116,7 +7116,9 @@ struct DeviceState {

// Gives the T# `words` a view in set 0 and an entry in the hash table, unless it has them. `storage`: shaders
// write through it too (an unordered-access view), so it also goes into the storage arrays, which are
// shorter. False when set 0 cannot show the image; the descriptor then finds the fallback at index 0.
// shorter. False when set 0 cannot show the image; the descriptor then finds the fallback at index 0. `why`, when
// given, is set to the reason when it is that set 0 has no room (or no array) for the image's dimension, and left
// alone otherwise (no view could be made for the T#).
bool bind_image(const leonida::gfx10::ImageWords& words, const leonida::gfx10::Image& image, VkImage vk_image,
VkFormat image_format, VkImageAspectFlags aspects, bool storage,
bool allow_channel_cast = false, VkFormat uint_backed = VK_FORMAT_UNDEFINED) {
Expand All @@ -7126,7 +7128,8 @@ struct DeviceState {
}
bool bind_image_locked(const leonida::gfx10::ImageWords& words, const leonida::gfx10::Image& image,
VkImage vk_image, VkFormat image_format, VkImageAspectFlags aspects, bool storage,
bool allow_channel_cast = false, VkFormat uint_backed = VK_FORMAT_UNDEFINED) {
bool allow_channel_cast = false, VkFormat uint_backed = VK_FORMAT_UNDEFINED,
const char** why = nullptr) {
namespace g = leonida::gfx10;
if (!bindless) return false;
auto pending = pending_image_keys.find(vk_image);
Expand Down Expand Up @@ -7171,7 +7174,7 @@ struct DeviceState {
const bool sampled_only = uint_backed || (view_format != image_format && view_format != VK_FORMAT_UNDEFINED);
return bind_image_views_locked(words, image, vk_image, view_format, channels_format,
uint_backed ? image_format : view_format, aspects, true, storage, {},
sampled_only);
sampled_only, why);
}
// The same for a view whose formats the caller has worked out: `view_format` of the sampled view (made when
// `sampled`), `channels_format` whose channels the T#'s swizzle selects from, `storage_format` of the storage view.
Expand All @@ -7185,7 +7188,7 @@ struct DeviceState {
bool bind_image_views_locked(const leonida::gfx10::ImageWords& words, const leonida::gfx10::Image& image,
VkImage vk_image, VkFormat view_format, VkFormat channels_format,
VkFormat storage_format, VkImageAspectFlags aspects, bool sampled, bool storage,
VolumeSlices slices, bool sampled_only) {
VolumeSlices slices, bool sampled_only, const char** why = nullptr) {
namespace g = leonida::gfx10;
if (!bindless) {
if (storage) log_once("unordered-access view needs the Vulkan bindless set; type", int(image.type));
Expand Down Expand Up @@ -7340,24 +7343,37 @@ struct DeviceState {
vk.vkDestroyImageView(info.device, entry.mirror_storage, nullptr);
entry.mirror_storage = VK_NULL_HANDLE;
}
if (first_diagnostic("a bindless image array is full; dimension", int(dimension))) {
using Refusal = leonida::BindlessSet::ImageRefusal;
const Refusal refusal = bindless->image_refusal(dimension, entry.storage != VK_NULL_HANDLE, sampled_class);
if (why)
*why = refusal == Refusal::no_array ? "set 0 has no array for the T#'s dimension"
: refusal == Refusal::storage_full ? "the bindless storage arrays of the T#'s dimension are full"
: "the bindless array of the T#'s dimension is full";
if (refusal != Refusal::no_array &&
first_diagnostic("a bindless image array is full; dimension", int(dimension))) {
// Whether the array holds live textures or stale views: the T#s it holds, the textures they name,
// and the most T#s of one texture (a texture whose T#s keep changing, a streamed mip clamp say,
// keeps an index for each until it goes).
std::size_t entries = 0, replaced = 0, most = 0;
// the most T#s of one texture (a texture whose T#s keep changing, a streamed mip clamp say, keeps an
// index for each until it goes), and how many of those textures are still the one registered at
// their address (a texture leaves the set when the one registered there goes: forget_image).
std::size_t entries = 0, replaced = 0, most = 0, registered = 0;
std::map<std::uint64_t, std::size_t> per_texture;
for (const auto& [key, held] : image_entries)
if (held.dimension == dimension) {
++entries;
most = std::max(most, ++per_texture[held.address]);
}
for (const auto& texture : per_texture) registered += images_by_address.count(texture.first);
for (const auto& held : replaced_images) replaced += held.dimension == dimension;
constexpr const char* names[] = {"2D", "2D array", "3D", "1D", "1D array", "2D MS", "2D MS array"};
std::fprintf(stderr,
"[rt] d3d12: a bindless image array is full; dimension %d: %u indices, %zu T#s of %zu "
"textures (at most %zu T#s of one), %zu replaced views kept; further T#s of this "
"dimension read the fallback\n",
int(dimension), bindless->image_capacity(dimension), entries, per_texture.size(), most,
replaced);
"[rt] d3d12: a bindless image array is full; dimension %d (%s)%s: %u indices, %u in the "
"storage arrays, %zu T#s of %zu textures (%zu registered at their address, at most %zu "
"T#s of one), %zu replaced views kept; further T#s of this dimension read the "
"fallback\n",
int(dimension), names[int(dimension)],
refusal == Refusal::storage_full ? ", its storage range" : "",
bindless->image_capacity(dimension), bindless->storage_capacity(dimension), entries,
per_texture.size(), registered, most, replaced);
}
if (entry.sampled) vk.vkDestroyImageView(info.device, entry.sampled, nullptr);
if (entry.storage) vk.vkDestroyImageView(info.device, entry.storage, nullptr);
Expand Down Expand Up @@ -13665,9 +13681,10 @@ TitleImage bind_title_image(DeviceState& device, const leonida::gfx10::ImageWord
return refuse("T# names layers the texture lacks");
const bool storage = (d.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) && !msaa &&
r.aspects() == VK_IMAGE_ASPECT_COLOR_BIT;
const char* unbound = "no view for the T#'s format or range"; // unless set 0 has no room (bind_image)
if (!device.bind_image_locked(words, image, r.descriptor_image(), r.format(), r.aspects(), storage,
r.has_view_format_list(), r.uint_backed()))
return refuse("no view for the T#'s format or range");
r.has_view_format_list(), r.uint_backed(), &unbound))
return refuse(unbound);
r.note_shader_view(); // Include descriptors written directly into title heaps.
if (r.sparse_image()) sparse = r.id();
}
Expand Down
Loading
Loading