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
9 changes: 9 additions & 0 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,15 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv
complete CPU read. Copies of descriptors written earlier resolve to the fallback until that upload succeeds.
`LEONIDA_TITLE_IMAGE_DEFER=0` allocates these textures eagerly. The memory probe reports the live unbound
image count and its Vulkan memory requirements in MiB.
- With `LEONIDA_TITLE_PARTIAL_MIPS=1`, such a texture can be filled before all its pages are readable. The XG
layout of a 2D texture of one slice stores its mips from the smallest to the largest, so the mips from `m` on are
the first `mip_chain_bytes(layout, m)` bytes from its base (`xg_xs_layout.h`; checked in `xg_xs_test` for tiled,
tail and linear layouts). The probe (`texture_memory_readable_bytes`) returns how many bytes from the base are
readable and `first_mip_within` the first mip those hold. When the last slot-70 view starts at that mip or later,
the mips from there on are filled and only the descriptor keys of views that start there or later are published.
The others stay on the fallback (`PendingImage::first_mip`) until a later fill has their mips. The image still has
memory for every mip: `LEONIDA_TITLE_PARTIAL_MIPS_MB` (2048) limits the image memory of the textures filled in
part. Arrays, cubes and volumes are filled whole or not at all.
- Small optimal Vulkan images synthesized for slot-70 texture views share memory pages. Each slice meets the
image's size, alignment and memory type requirements. The GPU retirement queue destroys the image before its
slice can be reused. Large images, dedicated-only images, and failed pool allocations use individual memory
Expand Down
2 changes: 2 additions & 0 deletions runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w
| `LEONIDA_TITLE_VIEW_REFRESH_MS` | `0` | The shortest time, in milliseconds, between two checks of a title texture's bytes when a device slot 70 view of it is written. `0` checks at every view. The periodic pass still checks the texture on its own period, and a texture known stale is checked at once. Has no effect with `LEONIDA_TITLE_FILL_ASYNC=1`. |
| `LEONIDA_TITLE_EVERY_BUDGET_US` | `0` | Microseconds one pass over the textures filled from the title's memory may spend on the textures it visits every pass (mapped by the title, or known stale), resuming where the last pass stopped; the texture that crosses the limit is finished. A mapped texture never filled yet is visited first whatever the limit. `0` visits all of them every pass. It limits the synchronous pass only: with `LEONIDA_TEXTURE_REFRESH_ASYNC=1` the pass runs on the refresh worker, and the limit does not apply. |
| `LEONIDA_TITLE_TEXTURE_FILL_MS` | `8` | Milliseconds one pass over the textures filled from the title's memory may spend filling; a texture already started is finished. `0` removes the time limit and leaves `LEONIDA_TITLE_TEXTURE_FILL_MB` to bound the pass. |
| `LEONIDA_TITLE_PARTIAL_MIPS` | unset | `1`: a 2D texture of one slice the title keeps in its own memory, whose larger mips are not readable, is filled from the first mip that is when its last slot-70 view starts there or later. Views that start above keep the fallback until a later fill has their mips. Unset, a texture waits for all its mips. |
| `LEONIDA_TITLE_PARTIAL_MIPS_MB` | `2048` | With `LEONIDA_TITLE_PARTIAL_MIPS=1`, the image memory the textures filled in part may hold, in MiB: each has memory for all its mips. A texture past it keeps the fallback. |
| `LEONIDA_MAP_READBACK` | unset | `1` writes the GPU's texels of a small render or unordered-access target the title placed into the title's pages when the title maps it, so a CPU read of the target sees what the GPU rendered (the title reads its exposure statistics that way). Only a single-row, single-mip, single-layer, single-sample 2D target of at most 4 KiB a row; the copy waits for the GPU's work already submitted, and a page that is not writable is left as it is. Unset, the title reads its own pages, which the GPU never writes. |
| `LEONIDA_SLOT133_IMPORT` | on | *Diagnostic.* `0` imports no title-placed buffer (device slot 133) as host memory: each takes the shadow-buffer fallback, so no GPU store can reach the title's memory through an import. |
| `LEONIDA_ARENA_NULL_MB` | `0` | `n` (MiB) keeps the first `n` MiB of the descriptor arena, at `heap_base + 0`, zeroed and never allocated, and moves the zero page and the quad indices above it. A translated shader whose address arithmetic starts from a null base then reads or writes there instead of in a title buffer or the shared zero page. Ignored when it would take half of the arena or more; the device logs the region it made. |
Expand Down
9 changes: 5 additions & 4 deletions runtime/shims/d3d12_title_image_upload.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ class TitleImageUpload {
ready_ = VK_NULL_HANDLE;
}

// Uploads the mips from `from` on; `tiled` then needs only mip_chain_bytes(layout, from) bytes.
template<class Device>
bool write(Device& d, leonida::ResourceId id, const leonida::ResourceBinding& image,
const xg_xs::Texture& layout, const std::uint8_t* tiled, std::vector<std::uint64_t>& columns,
bool inspect, bool& nonzero) {
bool inspect, bool& nonzero, unsigned from = 0) {
const auto block = leonida::copy_block_format(image, VK_IMAGE_ASPECT_COLOR_BIT);
const auto mips = layout.layout.mips;
const auto layers = layout.array;
if (!block.bytes || block.bytes != layout.format.bytes || !mips || mips > image.mip_levels ||
if (!block.bytes || block.bytes != layout.format.bytes || from >= mips || mips > image.mip_levels ||
!layers || layers > image.array_layers) return false;

regions_.clear();
VkDeviceSize bytes = 0;
for (unsigned layer = 0; layer < layers; ++layer) {
for (unsigned level = 0; level < mips; ++level) {
for (unsigned level = from; level < mips; ++level) {
const auto& mip = layout.layout.plane[0].mips[level];
VkBufferImageCopy copy{};
copy.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, level, layer, 1};
Expand Down Expand Up @@ -81,7 +82,7 @@ class TitleImageUpload {
[](std::uint8_t c) { return c != 0; });
}

const VkImageSubresourceRange range{VK_IMAGE_ASPECT_COLOR_BIT, 0, mips, 0, layers};
const VkImageSubresourceRange range{VK_IMAGE_ASPECT_COLOR_BIT, from, mips - from, 0, layers};
const auto result = d.context->write_staged_title_image(id, range, [&](const leonida::ReplayFunctions& replay,
const leonida::LayoutPieces& pieces) {
auto& vk = d.context->vk;
Expand Down
Loading
Loading