diff --git a/runtime/vk.h b/runtime/vk.h index 82154bb8..b9f1e585 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -61,6 +61,7 @@ typedef struct { int amd_sc; // AMD's Windows driver branch for RDNA 1 and 2 ("AMD proprietary shader compiler") int mesa; // a Mesa driver the game runs on: RADV, ANV or NVK int intel_igpu_win; // Intel's Windows driver on an integrated GPU (UHD, Iris Xe, Core Ultra graphics) + int demote; // shaderDemoteToHelperInvocation enabled: modules may use OpDemoteToHelperInvocation } VkCaps; extern VkCaps vk_caps; void vk_caps_driver(VkPhysicalDevice p); // first, before vkCreateDevice: vk_caps.amd, amd_sc, mesa, intel_igpu_win diff --git a/runtime/vk_device.c b/runtime/vk_device.c index ccc16b7d..6d047228 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -401,6 +401,9 @@ static int create_device(void) { else if (!h->textureCompressionBC) miss = "textureCompressionBC"; if (miss) { rt_log("vk: required feature missing on %s: %s", g_vk.props.deviceName, miss); free(c); return 0; } if (!c->fault.deviceFault) g_vk.has_device_fault = 0; // vkGetDeviceFaultInfoEXT needs the feature, not just the extension + // Vulkan 1.3 requires the feature, and the chain goes to vkCreateDevice as the driver filled it, so it is enabled + // wherever reported; vk_pipeline.c spirv_demote emits OpDemoteToHelperInvocation only when it is. + vk_caps.demote = c->f13.shaderDemoteToHelperInvocation; rt_log("vk: GPU address map for device faults: %s", has_abr && c->abr.reportAddressBinding ? "on (VK_EXT_device_address_binding_report; TOTK_ADDR_REPORT=0 turns it off)" : !ab_want ? "off (TOTK_ADDR_REPORT=0 or no VK_EXT_debug_utils)" diff --git a/runtime/vk_pipeline.c b/runtime/vk_pipeline.c index ea3de6f6..08e4c066 100644 --- a/runtime/vk_pipeline.c +++ b/runtime/vk_pipeline.c @@ -883,13 +883,18 @@ out: // that selection's merge block, so the fragment goes on computing and writes nothing. An OpKill anywhere else (the end // of a function, a switch case) stays. NULL: nothing to change. // On by default on AMD's own drivers, where the fringe shows; other drivers keep the translator's OpKill, their output -// unchanged. TOTK_DEMOTE=1 or 0 overrides on any driver. +// unchanged. TOTK_DEMOTE=1 or 0 overrides on any driver that enables shaderDemoteToHelperInvocation (vk_caps.demote, +// set in vk_device.c create_device); without the feature the module keeps OpKill, since the capability would be invalid. static uint32_t *spirv_demote(const uint32_t *w, uint64_t n, uint64_t *out_n) { enum { OP_EXTENSION = 10, OP_CAPABILITY = 17, OP_SELECTION_MERGE = 247, OP_LABEL = 248, OP_BRANCH = 249, OP_BRANCH_CONDITIONAL = 250, OP_KILL = 252, OP_DEMOTE = 5380, CAP_DEMOTE = 5379 }; static const char ext_name[36] = "SPV_EXT_demote_to_helper_invocation"; // 35 characters and the terminator: 9 words static int on = -1; - if (on < 0) on = rt_knob("DEMOTE", vk_caps.amd && !vk_caps.mesa ? "1" : "0"); + if (on < 0) { + on = vk_caps.demote && rt_knob("DEMOTE", vk_caps.amd && !vk_caps.mesa ? "1" : "0"); + rt_log("vk_pipeline: discard as demote: %s (shaderDemoteToHelperInvocation %d, TOTK_DEMOTE)", on ? "on" : "off", + vk_caps.demote); + } if (!on || n < 5) return NULL; uint64_t kills = 0; for (uint64_t i = 5; i < n;) {