feat(device): applications ask for the device features their shaders use
Device
- Device::Initialize(required, optional) takes DeviceFeatures, the five
core feature structs vulkan10 to vulkan14. The library enables only what
its own shaders and code use. Device::enabledFeatures says what was
enabled, supportedFeatures what the GPU has, apiVersion the version in
use.
- shaderInt16, shaderFloat16, storageBuffer16BitAccess, scalarBlockLayout
and the uniform-buffer, storage-buffer and storage-image non-uniform
indexing bits are no longer enabled for everyone. An application whose
shaders take uint16_t spec constants passes
{.vulkan10 = {.shaderInt16 = VK_TRUE}}. scalarBlockLayout stays on with
the NVIDIA workaround, whose TLAS address may sit in a struct's tail
padding.
- Every GPU is weighed before one is chosen: Vulkan 1.3, the swapchain and,
below 1.4, maintenance5 extensions, the library's needs, the required
features. One that can't run the application is skipped, saying why when
it ranks higher. A CPU device runs it only when nothing else is listed,
and CRAFTER_GRAPHICS_DEVICE never falls back. A GPU two drivers both list
is tried through each.
- When no GPU qualifies, Initialize throws naming each GPU's gaps. It
destroys the instance it made, before any Wayland connection, so it can
be called again asking for less.
- maintenance5 is vulkan14's on a 1.4 GPU and VK_KHR_maintenance5's below.
CRAFTER_GRAPHICS_NO_VULKAN_1_4 runs as a 1.3 application, to exercise
that path on a 1.4 GPU.
- VK_KHR_spirv_1_4 and VK_KHR_shader_float_controls, core since 1.2, are no
longer enabled, nor VK_EXT_shader_atomic_float, which was enabled without
its feature struct. memoryDecompression's feature bit is queried before
it is enabled.
Shaders
- VulkanShader checks a module's capabilities, declared directly or
implicitly, against the enabled core features, the GPU's subgroup
operations and the optional groups, and throws naming the field to pass,
or saying the GPU lacks it. The tables are generated from vk.xml and
SPIR-V's grammar.
- WorkaroundNvidiaAS::Patch sized a row-major matrix push member by its
columns, so the TLAS address could land inside it.
Window
- The swapchain format is one whose own feature flags allow storage reads
and writes without a format, which since Vulkan 1.3 each format says for
itself; shaderStorageImageRead/WriteWithoutFormat are no longer required.
Tests
- DeviceFeatures: ResolveFeatures, ChooseDevice and CheckShaderCapabilities,
without a GPU.
- FeatureRequests: required and optional features end to end, the 1.3
path, and a retry after a refusal.
- PushConstantRewrite: a row-major mat3x4 push member.
- HeapASRead, HeapDynamicIndexHit, RTPassPushData and the ray-tracing
examples ask for the features their shaders use.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c62109caf3
commit
bcdc885de8
18 changed files with 1721 additions and 333 deletions
|
|
@ -93,7 +93,7 @@ constexpr std::string_view kHeader =
|
|||
"layout(descriptor_heap) uniform writeonly image2D image[];\n"
|
||||
"layout(location = 0) rayPayloadEXT vec3 hitValue;\n";
|
||||
|
||||
const std::array<Case, 5> kCases = {{
|
||||
const std::array<Case, 6> kCases = {{
|
||||
// No push constant at all → Patch synthesizes a fresh single-member block at offset 0.
|
||||
{ "no-push-constant", std::string_view{
|
||||
""
|
||||
|
|
@ -114,6 +114,12 @@ const std::array<Case, 5> kCases = {{
|
|||
"layout(push_constant) uniform PC { vec4 v[2]; uint f; } pc;\n"
|
||||
}, true, true, 40 },
|
||||
|
||||
// Existing block {row-major mat3x4 @0}: 3 columns of 4 rows, stored as 4
|
||||
// rows 16 bytes apart, so it ends at 64, not at the 48 its 3 columns give.
|
||||
{ "merge-row-major-mat3x4", std::string_view{
|
||||
"layout(push_constant) uniform PC { layout(row_major) mat3x4 m; } pc;\n"
|
||||
}, true, true, 64 },
|
||||
|
||||
// Push constant but NO acceleration-structure read → Patch is a no-op; the
|
||||
// single user block must survive untouched and still validate.
|
||||
{ "push-constant-no-as", std::string_view{
|
||||
|
|
@ -133,7 +139,9 @@ std::string BuildSource(const Case& c) {
|
|||
// Reference the push constant so glslang keeps the block in the module.
|
||||
std::string_view g = c.glsl;
|
||||
std::string extra = "vec4(hitValue, 1.0)";
|
||||
if (g.find("mat4 m;") != std::string_view::npos)
|
||||
if (g.find("mat3x4 m;") != std::string_view::npos)
|
||||
extra = "vec4(hitValue, 1.0) + pc.m[2]";
|
||||
else if (g.find("mat4 m;") != std::string_view::npos)
|
||||
extra = "pc.m * vec4(hitValue, 1.0) + vec4(pc.l, float(pc.f))";
|
||||
else if (g.find("uint f; } pc;") != std::string_view::npos && g.find("vec4 v[2]") != std::string_view::npos)
|
||||
extra = "vec4(hitValue, 1.0) + pc.v[0] + pc.v[1] + vec4(float(pc.f))";
|
||||
|
|
|
|||
Loading…
Reference in a new issue