fix(device): stop requiring samplerAnisotropy, and remove SamplerVulkan, the class it was required for

Device::Initialize counted samplerAnisotropy among the library's own
features because SamplerVulkan turned anisotropic filtering on (#168).
Nothing in this repository has made a SamplerVulkan since 6e94cc6,
which replaced Sponza's with a sampler-heap write. So Initialize
enabled the feature for every application where the GPU had it, and
skipped a GPU without it, for a class this repository no longer used.
Design rule 8 has the library enable only the device features its own
shaders use.

SamplerVulkan: removed. #168's other suggestion keeps it, with
deferred deletion, a clamp to maxSamplerAnisotropy and anisotropy left
to the application. But the VkSampler it makes has no way into the
heap, which takes a sampler's create-info rather than a sampler
object: vkWriteSamplerDescriptorsEXT writes the descriptor straight
from the VkSamplerCreateInfo. In descriptor-set mode the heap makes
each slot's VkSampler itself, in DescriptorHeapVulkan::WriteSamplerSets,
from the same create-info. A class that fitted the heap would hold a
SamplerSlot and that write; a one-call sampler write for code without
a UIRenderer is #177's, which asks for heap-mode writers on
DescriptorHeapVulkan for images, buffers and samplers alike. The
partition leaves project.cpp's ifaces and the umbrella module.

Device: samplerAnisotropy leaves the library's features. No sampler
the library, its tests or its examples make sets anisotropyEnable. An
application that wants anisotropic filtering asks Device::Initialize
for the feature.

Docs: AGENTS.template.md counts 40 partitions and no longer lists
:SamplerVulkan. AGENTS.consumer.md describes samplers as slots written
from a create-info: through UIRenderer::RegisterSampler, or, without a
UIRenderer, through vkWriteSamplerDescriptorsEXT as Sponza does, or
WriteSamplerSets in descriptor-set mode. It says that anisotropyEnable
needs .vulkan10.samplerAnisotropy from the application. The README
names samplerAnisotropy among the features an application asks for.

Tests: FeatureRequests checks, in its main run and in its Vulkan 1.3
child (CRAFTER_GRAPHICS_NO_VULKAN_1_4), that samplerAnisotropy is off
after a Device::Initialize that does not ask for it. With the
requirement put back, the check fails in both, on the RTX 4090 here,
which has the feature.
This commit is contained in:
Jorijn van der Graaf 2026-11-26 09:25:32 +01:00
commit 594e1612f7
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
8 changed files with 13 additions and 58 deletions

View file

@ -69,7 +69,7 @@ Frames are pipelined three deep and nothing waits for the GPU at steady state, s
- `VulkanBuffer<T, Mapped>`: `Create(usage, memoryFlags, count, preferredFlags = 0)`; `Resize(...)` reuses the allocation when the request fits and the usage matches, otherwise queues the old one and creates; `size` (bytes), `buffer`, `address` (non-zero only with `VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT`), `memoryPropertyFlagsChosen`. With `Mapped`, `value` is the `T*` of a persistent map: after writing, call `FlushDevice()` (whole buffer), `FlushDevice(offset, bytes)` (a range, rounded to `nonCoherentAtomSize`) or `FlushDevice(cmd, dstAccess, dstStage)`, which flushes and records the host-write barrier; all three are no-ops on coherent memory. `FlushHost()` is the invalidate for readback. A UI item buffer is `GraphicsBuffer<QuadItem, true>` with `STORAGE_BUFFER | SHADER_DEVICE_ADDRESS` usage and `HOST_VISIBLE` memory with `DEVICE_LOCAL` as the preferred fourth argument (the examples pass both as required, which throws on a GPU without a host-visible device-local type), flushed each frame before the dispatch that reads it.
- Static geometry: `VulkanBuffer<T, false>::UploadDeviceLocal(usage, src, count, cmd, dstAccess, dstStage)` places the buffer in device memory, written directly on ReBAR and UMA and staged through a per-frame staging ring on a small BAR, and records the barrier to `dstStage`. `UploadDeviceLocalRange(src, offset, count, cmd, dstAccess, dstStage)` re-uploads the dirty window `[offset, offset + count)`; `src` points at the first dirty element (`vertices.data() + offset`), not at the array's start. A re-upload into a buffer a frame may still read is ordered after those reads on the GPU.
- `ImageVulkan<Pixel>` (`Image2D<Pixel>` is the portable alias): `Create(width, height, mipLevels, cmd, format, usage, layout, consumerStage = RAY_TRACING_SHADER, streamed = false)` makes the image and a mapped staging buffer `image.buffer`; fill `image.buffer.value` and `Update(cmd, layout)` copies it in, builds the mip chain by blits and transitions to `layout` for `consumerStage`. `Update(const CompressedTextureAsset&, cmd, layout)` decompresses a `.ctex` on the GPU, or the CPU. A static image releases its staging after the first upload; `streamed = true` keeps it (the font atlas, through `UpdateRegion`). Pass `VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT` as `consumerStage` for an image a compute shader samples; the RT default is corrected to compute on a device without ray tracing. `image`, `imageView` and `descriptor` are public for raw descriptor writes; `Destroy()` releases.
- `SamplerVulkan<Pixel>` makes one linear, repeat, 16x anisotropic sampler at construction (`textureSampler`). The UI has `UIRenderer::RegisterSampler(const VkSamplerCreateInfo&)` and `RegisterLinearClampSampler()`.
- Samplers live in sampler slots, written from a `VkSamplerCreateInfo`. `UIRenderer::RegisterSampler(const VkSamplerCreateInfo&)` writes the sampler into every frame's sampler heap (in descriptor-set mode into every frame's set, through a `VkSampler` the heap creates and owns) and returns a `SamplerSlot`; `RegisterLinearClampSampler()` registers a linear, clamp-to-edge one. Without a `UIRenderer`, in heap mode (ray tracing), call `Device::vkWriteSamplerDescriptorsEXT` with the create-info for each frame `f`, into `heap.samplerHeap[f].value + heap.SamplerByteOffset(range.firstElement)`, `Device::descriptorHeapProperties.samplerDescriptorSize` bytes, then flush, as `examples/Sponza/main.cpp` does; in descriptor-set mode `heap.WriteSamplerSets(range.firstElement, info)` does it. The library makes no anisotropic sampler and does not enable `samplerAnisotropy`: a create-info with `anisotropyEnable` needs `.vulkan10.samplerAnisotropy` among `Device::Initialize`'s required features (or its optional ones, checked in `Device::enabledFeatures`).
### UI