From 4dec1e68730d6518736b9256eabe2fbce5e82cf8 Mon Sep 17 00:00:00 2001 From: itar3 <62651854+itar3@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:55:54 +0500 Subject: [PATCH 1/6] Vulkan: scaled and 10:10:10:2 vertex formats Adds R8, R8G8 and R8G8B8A8 USCALED/SSCALED, R16, R16G16 and R16G16B16A16 USCALED/SSCALED, and A2B10G10R10 UNORM/SNORM packed formats, with their Vulkan mappings and size tables. USCALED/SSCALED read unnormalized integers as floats, which vertex data from consoles often needs. Vulkan only: D3D12 has no scaled formats. Co-Authored-By: Claude Opus 5.5 --- plume_render_interface_types.h | 48 ++++++++++++++++++++++++++++++++++ plume_vulkan.cpp | 28 ++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/plume_render_interface_types.h b/plume_render_interface_types.h index ad63e0e..dc09493 100644 --- a/plume_render_interface_types.h +++ b/plume_render_interface_types.h @@ -166,6 +166,21 @@ namespace plume { BC7_TYPELESS, BC7_UNORM, BC7_UNORM_SRGB, + R16G16_SSCALED, + R16G16B16A16_SSCALED, + // Vertex formats: USCALED/SSCALED are unnormalized integers read as floats. + R16G16B16A16_USCALED, + R8G8B8A8_USCALED, + R8G8B8A8_SSCALED, + R16G16_USCALED, + R8G8_USCALED, + R8G8_SSCALED, + R16_USCALED, + R16_SSCALED, + R8_USCALED, + R8_SSCALED, + A2B10G10R10_UNORM_PACK32, + A2B10G10R10_SNORM_PACK32, MAX }; @@ -597,6 +612,24 @@ namespace plume { case RenderFormat::BC7_UNORM: case RenderFormat::BC7_UNORM_SRGB: return 16; + case RenderFormat::R16G16B16A16_SSCALED: + case RenderFormat::R16G16B16A16_USCALED: + return 8; + case RenderFormat::A2B10G10R10_UNORM_PACK32: + case RenderFormat::A2B10G10R10_SNORM_PACK32: + case RenderFormat::R8G8B8A8_USCALED: + case RenderFormat::R8G8B8A8_SSCALED: + case RenderFormat::R16G16_SSCALED: + case RenderFormat::R16G16_USCALED: + return 4; + case RenderFormat::R8G8_USCALED: + case RenderFormat::R8G8_SSCALED: + case RenderFormat::R16_USCALED: + case RenderFormat::R16_SSCALED: + return 2; + case RenderFormat::R8_USCALED: + case RenderFormat::R8_SSCALED: + return 1; default: assert(false && "Unknown format."); return 1; @@ -681,6 +714,21 @@ namespace plume { case RenderFormat::BC7_UNORM: case RenderFormat::BC7_UNORM_SRGB: return 4; + case RenderFormat::R16G16B16A16_SSCALED: + case RenderFormat::R16G16_SSCALED: + case RenderFormat::R16G16B16A16_USCALED: + case RenderFormat::R8G8B8A8_USCALED: + case RenderFormat::R8G8B8A8_SSCALED: + case RenderFormat::R16G16_USCALED: + case RenderFormat::R8G8_USCALED: + case RenderFormat::R8G8_SSCALED: + case RenderFormat::R16_USCALED: + case RenderFormat::R16_SSCALED: + case RenderFormat::R8_USCALED: + case RenderFormat::R8_SSCALED: + case RenderFormat::A2B10G10R10_UNORM_PACK32: + case RenderFormat::A2B10G10R10_SNORM_PACK32: + return 1; default: assert(false && "Unknown format."); return 1; diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp index 58749c4..7702a44 100644 --- a/plume_vulkan.cpp +++ b/plume_vulkan.cpp @@ -249,6 +249,34 @@ namespace plume { return VK_FORMAT_BC7_UNORM_BLOCK; case RenderFormat::BC7_UNORM_SRGB: return VK_FORMAT_BC7_SRGB_BLOCK; + case RenderFormat::R16G16B16A16_SSCALED: + return VK_FORMAT_R16G16B16A16_SSCALED; + case RenderFormat::R16G16_SSCALED: + return VK_FORMAT_R16G16_SSCALED; + case RenderFormat::R16G16B16A16_USCALED: + return VK_FORMAT_R16G16B16A16_USCALED; + case RenderFormat::R8G8B8A8_USCALED: + return VK_FORMAT_R8G8B8A8_USCALED; + case RenderFormat::R8G8B8A8_SSCALED: + return VK_FORMAT_R8G8B8A8_SSCALED; + case RenderFormat::R16G16_USCALED: + return VK_FORMAT_R16G16_USCALED; + case RenderFormat::R8G8_USCALED: + return VK_FORMAT_R8G8_USCALED; + case RenderFormat::R8G8_SSCALED: + return VK_FORMAT_R8G8_SSCALED; + case RenderFormat::R16_USCALED: + return VK_FORMAT_R16_USCALED; + case RenderFormat::R16_SSCALED: + return VK_FORMAT_R16_SSCALED; + case RenderFormat::R8_USCALED: + return VK_FORMAT_R8_USCALED; + case RenderFormat::R8_SSCALED: + return VK_FORMAT_R8_SSCALED; + case RenderFormat::A2B10G10R10_UNORM_PACK32: + return VK_FORMAT_A2B10G10R10_UNORM_PACK32; + case RenderFormat::A2B10G10R10_SNORM_PACK32: + return VK_FORMAT_A2B10G10R10_SNORM_PACK32; default: assert(false && "Unknown format."); return VK_FORMAT_UNDEFINED; From 3790072f165641aa1d2badb064231872b255f905 Mon Sep 17 00:00:00 2001 From: itar3 <62651854+itar3@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:56:09 +0500 Subject: [PATCH 2/6] Vulkan: root descriptors through VK_KHR_push_descriptor Root descriptors (RenderPipelineLayoutDesc::rootDescriptorDescs) asserted on Vulkan. Each register space becomes a push descriptor set at the set index equal to the space, after the layout's descriptor sets (empty set layouts fill any gap); setGraphicsRootDescriptor pushes the buffer. Constant buffers map to uniform buffers, SRVs and UAVs to storage buffers. Needs VK_KHR_push_descriptor (now an optional extension). Co-Authored-By: Claude Opus 5.5 --- plume_vulkan.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++- plume_vulkan.h | 12 ++++++ 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp index 7702a44..65d251e 100644 --- a/plume_vulkan.cpp +++ b/plume_vulkan.cpp @@ -11,6 +11,7 @@ #include "plume_vulkan.h" #include +#include #include #include #include @@ -84,6 +85,7 @@ namespace plume { VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME, VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME, VK_EXT_LOAD_STORE_OP_NONE_EXTENSION_NAME, + VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, VK_KHR_PRESENT_ID_EXTENSION_NAME, VK_KHR_PRESENT_WAIT_EXTENSION_NAME, VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME, @@ -1288,6 +1290,78 @@ namespace plume { setLayoutHandles.emplace_back(setLayout->vk); } + // Root descriptors: one push descriptor set per register space, placed at the set index equal + // to the space (after the descriptor sets; empty sets fill any gap). + if (desc.rootDescriptorDescsCount > 0) { + if (!device->pushDescriptorSupported) { + fprintf(stderr, "Root descriptors need VK_KHR_push_descriptor, which the device does not support.\n"); + return; + } + + std::map> spaces; + for (uint32_t i = 0; i < desc.rootDescriptorDescsCount; i++) { + const RenderRootDescriptorDesc &src = desc.rootDescriptorDescs[i]; + RootDescriptor dst; + dst.setIndex = src.registerSpace; + dst.binding = src.shaderRegister; + switch (src.type) { + case RenderRootDescriptorType::CONSTANT_BUFFER: + dst.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + break; + case RenderRootDescriptorType::SHADER_RESOURCE: + case RenderRootDescriptorType::UNORDERED_ACCESS: + dst.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + break; + default: + assert(false && "Unknown root descriptor type."); + break; + } + + rootDescriptors.emplace_back(dst); + + VkDescriptorSetLayoutBinding binding = {}; + binding.binding = dst.binding; + binding.descriptorType = dst.type; + binding.descriptorCount = 1; + binding.stageFlags = VK_SHADER_STAGE_ALL; + spaces[dst.setIndex].emplace_back(binding); + } + + for (const auto &[space, bindings] : spaces) { + if (space < setLayoutHandles.size()) { + fprintf(stderr, "Root descriptor register space %u is already used by a descriptor set.\n", space); + return; + } + + while (setLayoutHandles.size() < space) { + VkDescriptorSetLayoutCreateInfo emptyInfo = {}; + emptyInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + VkDescriptorSetLayout empty = VK_NULL_HANDLE; + if (vkCreateDescriptorSetLayout(device->vk, &emptyInfo, nullptr, &empty) != VK_SUCCESS) { + fprintf(stderr, "vkCreateDescriptorSetLayout failed for an empty set.\n"); + return; + } + + rootSetLayouts.emplace_back(empty); + setLayoutHandles.emplace_back(empty); + } + + VkDescriptorSetLayoutCreateInfo pushInfo = {}; + pushInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + pushInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR; + pushInfo.bindingCount = uint32_t(bindings.size()); + pushInfo.pBindings = bindings.data(); + VkDescriptorSetLayout pushLayout = VK_NULL_HANDLE; + if (vkCreateDescriptorSetLayout(device->vk, &pushInfo, nullptr, &pushLayout) != VK_SUCCESS) { + fprintf(stderr, "vkCreateDescriptorSetLayout failed for the root descriptors of space %u.\n", space); + return; + } + + rootSetLayouts.emplace_back(pushLayout); + setLayoutHandles.emplace_back(pushLayout); + } + } + layoutInfo.pSetLayouts = !setLayoutHandles.empty() ? setLayoutHandles.data() : nullptr; layoutInfo.setLayoutCount = uint32_t(setLayoutHandles.size()); @@ -1306,6 +1380,10 @@ namespace plume { for (VulkanDescriptorSetLayout *setLayout : descriptorSetLayouts) { delete setLayout; } + + for (VkDescriptorSetLayout setLayout : rootSetLayouts) { + vkDestroyDescriptorSetLayout(device->vk, setLayout, nullptr); + } } // VulkanShader @@ -3036,7 +3114,32 @@ namespace plume { } void VulkanCommandList::setGraphicsRootDescriptor(RenderBufferReference bufferReference, uint32_t rootDescriptorIndex) { - assert(false && "Root descriptors are not supported in Vulkan."); + pushRootDescriptor(VK_PIPELINE_BIND_POINT_GRAPHICS, activeGraphicsPipelineLayout, bufferReference, rootDescriptorIndex); + } + + void VulkanCommandList::pushRootDescriptor(VkPipelineBindPoint bindPoint, const VulkanPipelineLayout *layout, RenderBufferReference bufferReference, uint32_t rootDescriptorIndex) { + assert(layout != nullptr); + assert(rootDescriptorIndex < layout->rootDescriptors.size()); + assert(bufferReference.ref != nullptr); + + const VulkanPipelineLayout::RootDescriptor &root = layout->rootDescriptors[rootDescriptorIndex]; + const VulkanBuffer *buffer = static_cast(bufferReference.ref); + const VkPhysicalDeviceLimits &limits = layout->device->physicalDeviceProperties.limits; + const uint64_t maxRange = (root.type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ? limits.maxUniformBufferRange : limits.maxStorageBufferRange; + assert(bufferReference.offset < buffer->desc.size); + + VkDescriptorBufferInfo bufferInfo = {}; + bufferInfo.buffer = buffer->vk; + bufferInfo.offset = bufferReference.offset; + bufferInfo.range = std::min(buffer->desc.size - bufferReference.offset, maxRange); + + VkWriteDescriptorSet write = {}; + write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write.dstBinding = root.binding; + write.descriptorCount = 1; + write.descriptorType = root.type; + write.pBufferInfo = &bufferInfo; + vkCmdPushDescriptorSetKHR(vk, bindPoint, layout->vk, root.setIndex, 1, &write); } void VulkanCommandList::setRaytracingPipelineLayout(const RenderPipelineLayout *pipelineLayout) { @@ -4211,6 +4314,7 @@ namespace plume { // Fill Vulkan-only capabilities. loadStoreOpNoneSupported = supportedOptionalExtensions.find(VK_EXT_LOAD_STORE_OP_NONE_EXTENSION_NAME) != supportedOptionalExtensions.end(); + pushDescriptorSupported = supportedOptionalExtensions.find(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME) != supportedOptionalExtensions.end(); if (!nullDescriptorSupported) { nullBuffer = createBuffer(RenderBufferDesc::DefaultBuffer(16, RenderBufferFlag::VERTEX)); diff --git a/plume_vulkan.h b/plume_vulkan.h index 1d36b12..a5899f4 100644 --- a/plume_vulkan.h +++ b/plume_vulkan.h @@ -129,9 +129,19 @@ namespace plume { }; struct VulkanPipelineLayout : RenderPipelineLayout { + // A root descriptor is a binding of a push descriptor set (VK_KHR_push_descriptor): + // the set index is the register space, the binding the shader register. + struct RootDescriptor { + uint32_t setIndex = 0; + uint32_t binding = 0; + VkDescriptorType type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + }; + VkPipelineLayout vk = VK_NULL_HANDLE; std::vector pushConstantRanges; std::vector descriptorSetLayouts; + std::vector rootDescriptors; + std::vector rootSetLayouts; // Push descriptor sets and empty gap fillers. VulkanDevice *device = nullptr; VulkanPipelineLayout(VulkanDevice *device, const RenderPipelineLayoutDesc &desc); @@ -320,6 +330,7 @@ namespace plume { void setGraphicsPushConstants(uint32_t rangeIndex, const void *data, uint32_t offset = 0, uint32_t size = 0) override; void setGraphicsDescriptorSet(RenderDescriptorSet *descriptorSet, uint32_t setIndex) override; void setGraphicsRootDescriptor(RenderBufferReference bufferReference, uint32_t rootDescriptorIndex) override; + void pushRootDescriptor(VkPipelineBindPoint bindPoint, const VulkanPipelineLayout *layout, RenderBufferReference bufferReference, uint32_t rootDescriptorIndex); void setRaytracingPipelineLayout(const RenderPipelineLayout *pipelineLayout) override; void setRaytracingPushConstants(uint32_t rangeIndex, const void *data, uint32_t offset = 0, uint32_t size = 0) override; void setRaytracingDescriptorSet(RenderDescriptorSet *descriptorSet, uint32_t setIndex) override; @@ -416,6 +427,7 @@ namespace plume { VkPhysicalDeviceSampleLocationsPropertiesEXT sampleLocationProperties = {}; std::unique_ptr nullBuffer; bool loadStoreOpNoneSupported = false; + bool pushDescriptorSupported = false; bool nullDescriptorSupported = false; VulkanDevice(VulkanInterface *renderInterface, const std::string &preferredDeviceName); From b1051c3caa0637236f11d1e63b3392ae63d789e9 Mon Sep 17 00:00:00 2001 From: itar3 <62651854+itar3@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:59:00 +0500 Subject: [PATCH 3/6] Dynamic blend constants and stencil reference Adds RenderCommandList::setBlendConstants and setStencilReference, and RenderGraphicsPipelineDesc::dynamicBlendConstantsEnabled and dynamicStencilReferenceEnabled (both off by default, so existing pipelines behave as before). Vulkan: the flags enable VK_DYNAMIC_STATE_BLEND_CONSTANTS and VK_DYNAMIC_STATE_STENCIL_REFERENCE. D3D12: OMSetBlendFactor and OMSetStencilRef; binding a pipeline with a dynamic stencil reference no longer overwrites it. Metal: setBlendColor and setStencilReferenceValue through the dirty state. Without them, a renderer whose stencil reference or blend constant changes per draw needs a pipeline per value. Co-Authored-By: Claude Opus 5.5 --- plume_d3d12.cpp | 14 ++++++++++++++ plume_d3d12.h | 3 +++ plume_metal.cpp | 24 +++++++++++++++++++++--- plume_metal.h | 9 ++++++++- plume_render_interface.h | 5 +++++ plume_render_interface_types.h | 2 ++ plume_vulkan.cpp | 15 +++++++++++++++ plume_vulkan.h | 2 ++ 8 files changed, 70 insertions(+), 4 deletions(-) diff --git a/plume_d3d12.cpp b/plume_d3d12.cpp index f08f984..1b19895 100644 --- a/plume_d3d12.cpp +++ b/plume_d3d12.cpp @@ -2237,6 +2237,15 @@ namespace plume { } } + void D3D12CommandList::setBlendConstants(const float rgba[4]) { + d3d->OMSetBlendFactor(rgba); + } + + void D3D12CommandList::setStencilReference(uint32_t reference) { + d3d->OMSetStencilRef(reference); + activeStencilRef = reference; + } + void D3D12CommandList::setDepthBias(float depthBias, float depthBiasClamp, float slopeScaledDepthBias) { # ifdef PLUME_D3D12_AGILITY_SDK_ENABLED assert(d3dV9 != nullptr); @@ -2472,6 +2481,10 @@ namespace plume { assert(activeGraphicsPipeline->type == D3D12Pipeline::Type::Graphics); const D3D12GraphicsPipeline *graphicsPipeline = static_cast(activeGraphicsPipeline); + if (graphicsPipeline->dynamicStencilRef) { + return; + } + if (activeStencilRef != graphicsPipeline->stencilRef) { d3d->OMSetStencilRef(graphicsPipeline->stencilRef); activeStencilRef = graphicsPipeline->stencilRef; @@ -3086,6 +3099,7 @@ namespace plume { assert(desc.pipelineLayout != nullptr); topology = toD3D12(desc.primitiveTopology); + dynamicStencilRef = desc.dynamicStencilReferenceEnabled; const D3D12PipelineLayout *pipelineLayout = static_cast(desc.pipelineLayout); const D3D12Shader *vertexShader = static_cast(desc.vertexShader); diff --git a/plume_d3d12.h b/plume_d3d12.h index 4827452..8fcd174 100644 --- a/plume_d3d12.h +++ b/plume_d3d12.h @@ -211,6 +211,8 @@ namespace plume { void setScissors(const RenderRect *scissorRects, uint32_t count) override; void setFramebuffer(const RenderFramebuffer *framebuffer) override; void setDepthBias(float depthBias, float depthBiasClamp, float slopeScaledDepthBias) override; + void setBlendConstants(const float rgba[4]) override; + void setStencilReference(uint32_t reference) override; void clearColor(uint32_t attachmentIndex, RenderColor colorValue, const RenderRect *clearRects, uint32_t clearRectsCount) override; void clearDepthStencil(bool clearDepth, bool clearStencil, float depthValue, uint32_t stencilValue, const RenderRect *clearRects, uint32_t clearRectsCount) override; void copyBufferRegion(RenderBufferReference dstBuffer, RenderBufferReference srcBuffer, uint64_t size) override; @@ -397,6 +399,7 @@ namespace plume { std::vector inputSlots; D3D12_PRIMITIVE_TOPOLOGY topology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; uint32_t stencilRef = 0; + bool dynamicStencilRef = false; D3D12GraphicsPipeline(D3D12Device *device, const RenderGraphicsPipelineDesc &desc); ~D3D12GraphicsPipeline() override; diff --git a/plume_metal.cpp b/plume_metal.cpp index c069a44..6a04292 100644 --- a/plume_metal.cpp +++ b/plume_metal.cpp @@ -1607,6 +1607,7 @@ namespace plume { state.renderPipelineState = device->mtl->newRenderPipelineState(descriptor, &error); state.primitiveType = mapPrimitiveType(desc.primitiveTopology); state.stencilReference = desc.stencilEnabled ? desc.stencilReference : 0; + state.dynamicStencilReferenceEnabled = desc.dynamicStencilReferenceEnabled; if (desc.dynamicDepthBiasEnabled) { state.dynamicDepthBiasEnabled = true; @@ -2750,6 +2751,16 @@ namespace plume { } } + void MetalCommandList::setBlendConstants(const float rgba[4]) { + std::copy(rgba, rgba + 4, dynamicBlendConstants); + dirtyGraphicsState.blendConstants = 1; + } + + void MetalCommandList::setStencilReference(uint32_t reference) { + dynamicStencilReference = reference; + dirtyGraphicsState.depthStencil = 1; + } + void MetalCommandList::setDepthBias(float depthBias, float depthBiasClamp, float slopeScaledDepthBias) { dynamicDepthBias.depthBias = depthBias; dynamicDepthBias.depthBiasClamp = depthBiasClamp; @@ -3444,9 +3455,10 @@ namespace plume { activeRenderEncoder->setDepthStencilState(activeRenderState->depthStencilState); stateCache.lastDepthStencilState = activeRenderState->depthStencilState; } - if (activeRenderState->stencilReference != stateCache.lastStencilReference) { - activeRenderEncoder->setStencilReferenceValue(activeRenderState->stencilReference); - stateCache.lastStencilReference = activeRenderState->stencilReference; + const uint32_t stencilReference = activeRenderState->dynamicStencilReferenceEnabled ? dynamicStencilReference : activeRenderState->stencilReference; + if (stencilReference != stateCache.lastStencilReference) { + activeRenderEncoder->setStencilReferenceValue(stencilReference); + stateCache.lastStencilReference = stencilReference; } } dirtyGraphicsState.depthStencil = 0; @@ -3471,6 +3483,12 @@ namespace plume { dirtyGraphicsState.rasterizer = 0; } + // Blend constants + if (dirtyGraphicsState.blendConstants) { + activeRenderEncoder->setBlendColor(dynamicBlendConstants[0], dynamicBlendConstants[1], dynamicBlendConstants[2], dynamicBlendConstants[3]); + dirtyGraphicsState.blendConstants = 0; + } + // Depth bias if (dirtyGraphicsState.depthBias) { float newDepthBias, newSlopeScale, newClamp; diff --git a/plume_metal.h b/plume_metal.h index 59ae129..7fc20b9 100644 --- a/plume_metal.h +++ b/plume_metal.h @@ -118,6 +118,7 @@ namespace plume { uint32_t depthBias : 1; uint32_t depthStencil : 1; uint32_t rasterizer : 1; + uint32_t blendConstants : 1; }; uint32_t value; }; @@ -129,7 +130,7 @@ namespace plume { uint32_t vertexBufferSlots; void setAll() { - value = 0x1FF; // All 9 bits set + value = 0x3FF; // All 10 bits set descriptorSetDirtyIndex = 0; vertexBufferSlots = (1U << MAX_VERTEX_BUFFER_BINDINGS) - 1; } @@ -197,6 +198,7 @@ namespace plume { float depthBiasClamp; float depthBiasSlopeFactor; bool dynamicDepthBiasEnabled; + bool dynamicStencilReferenceEnabled = false; }; struct ExtendedRenderTexture : RenderTexture { @@ -428,6 +430,9 @@ namespace plume { float slopeScaledDepthBias; } dynamicDepthBias; + uint32_t dynamicStencilReference = 0; + float dynamicBlendConstants[4] = {}; + struct { uint32_t updateDirtyBits = ~0; int update[MetalBarrierStage::COUNT] = {}; @@ -481,6 +486,8 @@ namespace plume { void setScissors(const RenderRect *scissorRects, uint32_t count) override; void setFramebuffer(const RenderFramebuffer *framebuffer) override; void setDepthBias(float depthBias, float depthBiasClamp, float slopeScaledDepthBias) override; + void setBlendConstants(const float rgba[4]) override; + void setStencilReference(uint32_t reference) override; void clearColor(uint32_t attachmentIndex, RenderColor colorValue, const RenderRect *clearRects, uint32_t clearRectsCount) override; void clearDepthStencil(bool clearDepth, bool clearStencil, float depthValue, uint32_t stencilValue, const RenderRect *clearRects, uint32_t clearRectsCount) override; void copyBufferRegion(RenderBufferReference dstBuffer, RenderBufferReference srcBuffer, uint64_t size) override; diff --git a/plume_render_interface.h b/plume_render_interface.h index 2048557..94358a1 100644 --- a/plume_render_interface.h +++ b/plume_render_interface.h @@ -137,6 +137,11 @@ namespace plume { virtual void setScissors(const RenderRect *scissorRects, uint32_t count) = 0; virtual void setFramebuffer(const RenderFramebuffer *framebuffer) = 0; virtual void setDepthBias(float depthBias, float depthBiasClamp, float slopeScaledDepthBias) = 0; + // Blend constants (BLEND_FACTOR / INV_BLEND_FACTOR) for pipelines created with dynamicBlendConstantsEnabled. + virtual void setBlendConstants(const float rgba[4]) = 0; + // Stencil reference (front and back) for pipelines created with dynamicStencilReferenceEnabled. + // Like other dynamic state, set it again after binding a pipeline that has it static. + virtual void setStencilReference(uint32_t reference) = 0; virtual void clearColor(uint32_t attachmentIndex = 0, RenderColor colorValue = RenderColor(), const RenderRect *clearRects = nullptr, uint32_t clearRectsCount = 0) = 0; virtual void clearDepthStencil(bool clearDepth = true, bool clearStencil = true, float depthValue = 1.0f, uint32_t stencilValue = 0, const RenderRect *clearRects = nullptr, uint32_t clearRectsCount = 0) = 0; virtual void copyBufferRegion(RenderBufferReference dstBuffer, RenderBufferReference srcBuffer, uint64_t size) = 0; diff --git a/plume_render_interface_types.h b/plume_render_interface_types.h index dc09493..c1bb83b 100644 --- a/plume_render_interface_types.h +++ b/plume_render_interface_types.h @@ -1334,6 +1334,8 @@ namespace plume { float depthBiasClamp = 0.0f; float slopeScaledDepthBias = 0.0f; bool dynamicDepthBiasEnabled = false; + bool dynamicBlendConstantsEnabled = false; // Blend constants come from RenderCommandList::setBlendConstants. + bool dynamicStencilReferenceEnabled = false; // The stencil reference comes from RenderCommandList::setStencilReference. bool depthEnabled = false; bool depthWriteEnabled = false; bool stencilEnabled = false; diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp index 65d251e..4985216 100644 --- a/plume_vulkan.cpp +++ b/plume_vulkan.cpp @@ -1718,6 +1718,13 @@ namespace plume { dynamicStates.clear(); dynamicStates.emplace_back(VK_DYNAMIC_STATE_VIEWPORT); dynamicStates.emplace_back(VK_DYNAMIC_STATE_SCISSOR); + if (desc.dynamicBlendConstantsEnabled) { + dynamicStates.emplace_back(VK_DYNAMIC_STATE_BLEND_CONSTANTS); + } + + if (desc.dynamicStencilReferenceEnabled) { + dynamicStates.emplace_back(VK_DYNAMIC_STATE_STENCIL_REFERENCE); + } if (desc.dynamicDepthBiasEnabled) { dynamicStates.emplace_back(VK_DYNAMIC_STATE_DEPTH_BIAS); @@ -3249,6 +3256,14 @@ namespace plume { vkCmdSetDepthBias(vk, depthBias, depthBiasClamp, slopeScaledDepthBias); } + void VulkanCommandList::setBlendConstants(const float rgba[4]) { + vkCmdSetBlendConstants(vk, rgba); + } + + void VulkanCommandList::setStencilReference(uint32_t reference) { + vkCmdSetStencilReference(vk, VK_STENCIL_FACE_FRONT_AND_BACK, reference); + } + static void clearCommonRectVector(uint32_t width, uint32_t height, const RenderRect *clearRects, uint32_t clearRectsCount, std::vector &rectVector) { rectVector.clear(); diff --git a/plume_vulkan.h b/plume_vulkan.h index a5899f4..31ab25d 100644 --- a/plume_vulkan.h +++ b/plume_vulkan.h @@ -340,6 +340,8 @@ namespace plume { void setScissors(const RenderRect *scissorRects, uint32_t count) override; void setFramebuffer(const RenderFramebuffer *framebuffer) override; void setDepthBias(float depthBias, float depthBiasClamp, float slopeScaledDepthBias) override; + void setBlendConstants(const float rgba[4]) override; + void setStencilReference(uint32_t reference) override; void clearColor(uint32_t attachmentIndex, RenderColor colorValue, const RenderRect *clearRects, uint32_t clearRectsCount) override; void clearDepthStencil(bool clearDepth, bool clearStencil, float depthValue, uint32_t stencilValue, const RenderRect *clearRects, uint32_t clearRectsCount) override; void copyBufferRegion(RenderBufferReference dstBuffer, RenderBufferReference srcBuffer, uint64_t size) override; From fef4ea301d2ae6f59d10d64f9ed3199e80e8bc54 Mon Sep 17 00:00:00 2001 From: itar3 <62651854+itar3@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:59:11 +0500 Subject: [PATCH 4/6] Vulkan: framebuffer size from the attachment view's mip level A framebuffer whose attachment is a view of mip level N took the base level's size as its size and render area, larger than the attachment: on MoltenVK draws then wrote outside it (GPU page faults). The size is now the view's mip level size, for colour and depth-only framebuffers. Co-Authored-By: Claude Opus 5.5 --- plume_vulkan.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp index 4985216..24165ec 100644 --- a/plume_vulkan.cpp +++ b/plume_vulkan.cpp @@ -2661,8 +2661,13 @@ namespace plume { imageViews.emplace_back(colorAttachmentImageView); if (i == 0) { - width = uint32_t(colorAttachment->desc.width); - height = colorAttachment->desc.height; + // A view of one mip level renders at that level's size (the base + // size made MoltenVK write outside the attachment: GPU page faults). + uint32_t mip = 0; + if (desc.colorAttachmentViews && desc.colorAttachmentViews[i]) + mip = static_cast(desc.colorAttachmentViews[i])->desc.mipSlice; + width = std::max(1u, uint32_t(colorAttachment->desc.width) >> mip); + height = std::max(1u, uint32_t(colorAttachment->desc.height) >> mip); } VkAttachmentReference reference = {}; @@ -2706,8 +2711,10 @@ namespace plume { imageViews.emplace_back(depthAttachmentImageView); if (desc.colorAttachmentsCount == 0) { - width = uint32_t(depthAttachment->desc.width); - height = depthAttachment->desc.height; + const uint32_t depthMip = desc.depthAttachmentView != nullptr + ? static_cast(desc.depthAttachmentView)->desc.mipSlice : 0; + width = std::max(1u, uint32_t(depthAttachment->desc.width) >> depthMip); + height = std::max(1u, uint32_t(depthAttachment->desc.height) >> depthMip); } depthReference.attachment = uint32_t(attachments.size()); From 337809c55c021213af80605627847d60a1d6f463 Mon Sep 17 00:00:00 2001 From: itar3 <62651854+itar3@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:59:45 +0500 Subject: [PATCH 5/6] Vulkan: occlusion queries Adds RenderDevice::createOcclusionQueryPool, RenderCommandList::beginQuery and endQuery, and RenderQueryPool::getRawResults (results without waiting, false while any is unavailable). Other backends return no pool for now. Queries are precise (sample counts) when the device supports it; MoltenVK otherwise uses Metal's boolean visibility mode. A query begun inside a render pass instance stays in it instead of ending the pass (a store and reload of every attachment on tile GPUs) and ends with the pass at the latest, as Vulkan requires; queriesEndRenderPass restores begin/end outside passes. resetQueryPool now ends the active pass (vkCmdResetQueryPool is not allowed inside one). Co-Authored-By: Claude Opus 5.5 --- plume_render_interface.h | 8 +++++ plume_vulkan.cpp | 64 ++++++++++++++++++++++++++++++++++++++-- plume_vulkan.h | 18 ++++++++++- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/plume_render_interface.h b/plume_render_interface.h index 94358a1..19a8142 100644 --- a/plume_render_interface.h +++ b/plume_render_interface.h @@ -155,6 +155,10 @@ namespace plume { virtual void discardTexture(const RenderTexture* texture) = 0; // D3D12 only. virtual void resetQueryPool(const RenderQueryPool *queryPool, uint32_t queryFirstIndex, uint32_t queryCount) = 0; virtual void writeTimestamp(const RenderQueryPool *queryPool, uint32_t queryIndex) = 0; + // Occlusion queries (samples that pass the depth and stencil tests) in a pool from + // RenderDevice::createOcclusionQueryPool. + virtual void beginQuery(const RenderQueryPool *queryPool, uint32_t queryIndex) { (void)queryPool; (void)queryIndex; } + virtual void endQuery(const RenderQueryPool *queryPool, uint32_t queryIndex) { (void)queryPool; (void)queryIndex; } // Concrete implementation shortcuts. inline void barriers(RenderBarrierStages stages, const RenderBufferBarrier &barrier) { @@ -226,6 +230,8 @@ namespace plume { virtual void queryResults() = 0; virtual const uint64_t *getResults() const = 0; virtual uint32_t getCount() const = 0; + // Results of queries [first, first + count) without waiting; false if any is not available yet. + virtual bool getRawResults(uint32_t first, uint32_t count, uint64_t *out) { (void)first; (void)count; (void)out; return false; } }; struct RenderDevice { @@ -246,6 +252,8 @@ namespace plume { virtual std::unique_ptr createCommandSemaphore() = 0; virtual std::unique_ptr createFramebuffer(const RenderFramebufferDesc &desc) = 0; virtual std::unique_ptr createQueryPool(uint32_t queryCount) = 0; + // nullptr if the backend has no occlusion queries (only Vulkan has them so far). + virtual std::unique_ptr createOcclusionQueryPool(uint32_t queryCount) { (void)queryCount; return nullptr; } virtual void setBottomLevelASBuildInfo(RenderBottomLevelASBuildInfo &buildInfo, const RenderBottomLevelASMesh *meshes, uint32_t meshCount, bool preferFastBuild = true, bool preferFastTrace = false) = 0; virtual void setTopLevelASBuildInfo(RenderTopLevelASBuildInfo &buildInfo, const RenderTopLevelASInstance *instances, uint32_t instanceCount, bool preferFastBuild = true, bool preferFastTrace = false) = 0; virtual void setShaderBindingTableInfo(RenderShaderBindingTableInfo &tableInfo, const RenderShaderBindingGroups &groups, const RenderPipeline *pipeline, RenderDescriptorSet **descriptorSets, uint32_t descriptorSetCount) = 0; diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp index 24165ec..5ef189c 100644 --- a/plume_vulkan.cpp +++ b/plume_vulkan.cpp @@ -2805,7 +2805,7 @@ namespace plume { // VulkanQueryPool - VulkanQueryPool::VulkanQueryPool(VulkanDevice *device, uint32_t queryCount) { + VulkanQueryPool::VulkanQueryPool(VulkanDevice *device, uint32_t queryCount, bool occlusion) { assert(device != nullptr); assert(queryCount > 0); @@ -2813,7 +2813,7 @@ namespace plume { VkQueryPoolCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; - createInfo.queryType = VK_QUERY_TYPE_TIMESTAMP; + createInfo.queryType = occlusion ? VK_QUERY_TYPE_OCCLUSION : VK_QUERY_TYPE_TIMESTAMP; createInfo.queryCount = queryCount; VkResult res = vkCreateQueryPool(device->vk, &createInfo, nullptr, &vk); @@ -2869,6 +2869,11 @@ namespace plume { } } + bool VulkanQueryPool::getRawResults(uint32_t first, uint32_t count, uint64_t *out) { + VkResult res = vkGetQueryPoolResults(device->vk, vk, first, count, sizeof(uint64_t) * count, out, sizeof(uint64_t), VK_QUERY_RESULT_64_BIT); + return res == VK_SUCCESS; + } + const uint64_t *VulkanQueryPool::getResults() const { return results.data(); } @@ -2920,6 +2925,8 @@ namespace plume { void VulkanCommandList::begin() { vkResetCommandBuffer(vk, 0); + passQueries.clear(); + passQueriesClosed.clear(); VkCommandBufferBeginInfo beginInfo = {}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; @@ -3641,6 +3648,9 @@ namespace plume { void VulkanCommandList::resetQueryPool(const RenderQueryPool *queryPool, uint32_t queryFirstIndex, uint32_t queryCount) { assert(queryPool != nullptr); + // vkCmdResetQueryPool is not allowed inside a render pass instance. + endActiveRenderPass(); + const VulkanQueryPool *interfaceQueryPool = static_cast(queryPool); vkCmdResetQueryPool(vk, interfaceQueryPool->vk, queryFirstIndex, queryCount); } @@ -3652,6 +3662,45 @@ namespace plume { vkCmdWriteTimestamp(vk, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, interfaceQueryPool->vk, queryIndex); } + // A query begun inside a render pass instance is kept in it (no load and store of its attachments + // around the query) and ends with it at the latest; one begun outside spans the passes in between. + void VulkanCommandList::beginQuery(const RenderQueryPool *queryPool, uint32_t queryIndex) { + assert(queryPool != nullptr); + const VkQueryPool pool = static_cast(queryPool)->vk; + if (queriesEndRenderPass) { + endActiveRenderPass(); + } + + // Precise: sample counts, not just "any passed" (MoltenVK otherwise uses Metal's boolean mode). + vkCmdBeginQuery(vk, pool, queryIndex, queue->device->occlusionQueryPrecise ? VK_QUERY_CONTROL_PRECISE_BIT : 0); + if (activeRenderPass != VK_NULL_HANDLE) { + passQueries.push_back({ pool, queryIndex }); + } + } + + void VulkanCommandList::endQuery(const RenderQueryPool *queryPool, uint32_t queryIndex) { + assert(queryPool != nullptr); + const VkQueryPool pool = static_cast(queryPool)->vk; + auto matches = [&](const PassQuery &q) { return (q.pool == pool) && (q.index == queryIndex); }; + auto closed = std::find_if(passQueriesClosed.begin(), passQueriesClosed.end(), matches); + if (closed != passQueriesClosed.end()) { + // Its render pass ended first and closed it. + passQueriesClosed.erase(closed); + return; + } + + auto open = std::find_if(passQueries.begin(), passQueries.end(), matches); + if (open != passQueries.end()) { + passQueries.erase(open); + } + else { + // Begun outside a render pass: it must end outside one too. + endActiveRenderPass(); + } + + vkCmdEndQuery(vk, pool, queryIndex); + } + void VulkanCommandList::checkActiveRenderPass() { assert(targetFramebuffer != nullptr); @@ -3669,6 +3718,12 @@ namespace plume { void VulkanCommandList::endActiveRenderPass() { if (activeRenderPass != VK_NULL_HANDLE) { + for (const PassQuery &q : passQueries) { + vkCmdEndQuery(vk, q.pool, q.index); + passQueriesClosed.push_back(q); + } + + passQueries.clear(); vkCmdEndRenderPass(vk); activeRenderPass = VK_NULL_HANDLE; } @@ -4086,6 +4141,7 @@ namespace plume { deviceFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; deviceFeatures.pNext = featuresChain; vkGetPhysicalDeviceFeatures2(physicalDevice, &deviceFeatures); + occlusionQueryPrecise = deviceFeatures.features.occlusionQueryPrecise == VK_TRUE; // Check for properties. if (rayTracingFound) { @@ -4411,6 +4467,10 @@ namespace plume { return std::make_unique(this, queryCount); } + std::unique_ptr VulkanDevice::createOcclusionQueryPool(uint32_t queryCount) { + return std::make_unique(this, queryCount, true); + } + void VulkanDevice::setBottomLevelASBuildInfo(RenderBottomLevelASBuildInfo &buildInfo, const RenderBottomLevelASMesh *meshes, uint32_t meshCount, bool preferFastBuild, bool preferFastTrace) { assert(meshes != nullptr); assert(meshCount > 0); diff --git a/plume_vulkan.h b/plume_vulkan.h index 31ab25d..0cda581 100644 --- a/plume_vulkan.h +++ b/plume_vulkan.h @@ -296,9 +296,10 @@ namespace plume { std::vector results; VkQueryPool vk = VK_NULL_HANDLE; - VulkanQueryPool(VulkanDevice *device, uint32_t queryCount); + VulkanQueryPool(VulkanDevice *device, uint32_t queryCount, bool occlusion = false); virtual ~VulkanQueryPool() override; virtual void queryResults() override; + bool getRawResults(uint32_t first, uint32_t count, uint64_t *out) override; virtual const uint64_t *getResults() const override; virtual uint32_t getCount() const override; }; @@ -312,6 +313,17 @@ namespace plume { const VulkanPipelineLayout *activeGraphicsPipelineLayout = nullptr; const VulkanPipelineLayout *activeRaytracingPipelineLayout = nullptr; VkRenderPass activeRenderPass = VK_NULL_HANDLE; + // Occlusion queries begun inside the active render pass: they end with it at the latest (Vulkan + // requires a query begun in a render pass instance to end in it), and a later endQuery of one + // the pass end already closed does nothing. + struct PassQuery { + VkQueryPool pool = VK_NULL_HANDLE; + uint32_t index = 0; + }; + std::vector passQueries; + std::vector passQueriesClosed; + // true: begin and end every query outside render passes (ends the active pass). + bool queriesEndRenderPass = false; VulkanCommandList(VulkanCommandQueue *queue); ~VulkanCommandList() override; @@ -355,6 +367,8 @@ namespace plume { void discardTexture(const RenderTexture* texture) override; void resetQueryPool(const RenderQueryPool *queryPool, uint32_t queryFirstIndex, uint32_t queryCount) override; void writeTimestamp(const RenderQueryPool *queryPool, uint32_t queryIndex) override; + void beginQuery(const RenderQueryPool *queryPool, uint32_t queryIndex) override; + void endQuery(const RenderQueryPool *queryPool, uint32_t queryIndex) override; void checkActiveRenderPass(); void endActiveRenderPass(); void setDescriptorSet(VkPipelineBindPoint bindPoint, const VulkanPipelineLayout *pipelineLayout, const RenderDescriptorSet *descriptorSet, uint32_t setIndex); @@ -425,6 +439,7 @@ namespace plume { std::vector queueFamilies; RenderDeviceCapabilities capabilities; RenderDeviceDescription description; + bool occlusionQueryPrecise = false; VkPhysicalDeviceRayTracingPipelinePropertiesKHR rtPipelineProperties = {}; VkPhysicalDeviceSampleLocationsPropertiesEXT sampleLocationProperties = {}; std::unique_ptr nullBuffer; @@ -450,6 +465,7 @@ namespace plume { std::unique_ptr createCommandSemaphore() override; std::unique_ptr createFramebuffer(const RenderFramebufferDesc &desc) override; std::unique_ptr createQueryPool(uint32_t queryCount) override; + std::unique_ptr createOcclusionQueryPool(uint32_t queryCount) override; void setBottomLevelASBuildInfo(RenderBottomLevelASBuildInfo &buildInfo, const RenderBottomLevelASMesh *meshes, uint32_t meshCount, bool preferFastBuild, bool preferFastTrace) override; void setTopLevelASBuildInfo(RenderTopLevelASBuildInfo &buildInfo, const RenderTopLevelASInstance *instances, uint32_t instanceCount, bool preferFastBuild, bool preferFastTrace) override; void setShaderBindingTableInfo(RenderShaderBindingTableInfo &tableInfo, const RenderShaderBindingGroups &groups, const RenderPipeline *pipeline, RenderDescriptorSet **descriptorSets, uint32_t descriptorSetCount) override; From 2391d0dd36618b12ef22c5da3e019a847358bcd9 Mon Sep 17 00:00:00 2001 From: itar3 <62651854+itar3@users.noreply.github.com> Date: Fri, 13 Nov 2026 15:01:04 +0500 Subject: [PATCH 6/6] Vulkan: keep the render pass across framebuffer rebinds setFramebuffer ended the active render pass every time, so rebinding the active framebuffer, or binding one that got no draws before switching back, ended and restarted the pass: a store and reload of every attachment on tile GPUs (MoltenVK, mobile). Now a draw or clear ends the pass only when it needs another framebuffer. setFramebuffer(nullptr) still ends it, and dispatch, traceRays and acceleration structure builds end it themselves (they relied on setFramebuffer ending it before; resolves already do). Co-Authored-By: Claude Opus 5.5 --- plume_vulkan.cpp | 21 +++++++++++++++++++-- plume_vulkan.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp index 5ef189c..66c19a3 100644 --- a/plume_vulkan.cpp +++ b/plume_vulkan.cpp @@ -3020,6 +3020,7 @@ namespace plume { void VulkanCommandList::dispatch(uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ) { assert(activeComputePipelineLayout != nullptr); + endActiveRenderPass(); vkCmdDispatch(vk, threadGroupCountX, threadGroupCountY, threadGroupCountZ); } @@ -3029,6 +3030,7 @@ namespace plume { assert(interfaceBuffer != nullptr); assert((interfaceBuffer->desc.flags & RenderBufferFlag::SHADER_BINDING_TABLE) && "Buffer must allow being used as a shader binding table."); assert(activeRaytracingPipelineLayout != nullptr); + endActiveRenderPass(); VkBufferDeviceAddressInfo tableAddressInfo = {}; tableAddressInfo.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO; @@ -3255,7 +3257,14 @@ namespace plume { } void VulkanCommandList::setFramebuffer(const RenderFramebuffer *framebuffer) { - endActiveRenderPass(); + // The active render pass ends when a draw or clear needs another framebuffer + // (checkActiveRenderPass) or a command that is not allowed in a render pass comes. + // Rebinding the active framebuffer, or binding one that gets no draws before + // switching back, no longer ends and restarts the pass (a store and reload of + // every attachment on tile GPUs). + if (framebuffer == nullptr) { + endActiveRenderPass(); + } if (framebuffer != nullptr) { const VulkanFramebuffer *interfaceFramebuffer = static_cast(framebuffer); @@ -3561,6 +3570,7 @@ namespace plume { void VulkanCommandList::buildBottomLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, const RenderBottomLevelASBuildInfo &buildInfo) { assert(dstAccelerationStructure != nullptr); assert(scratchBuffer.ref != nullptr); + endActiveRenderPass(); const VulkanAccelerationStructure *interfaceAccelerationStructure = static_cast(dstAccelerationStructure); assert(interfaceAccelerationStructure->type == RenderAccelerationStructureType::BOTTOM_LEVEL); @@ -3595,6 +3605,7 @@ namespace plume { void VulkanCommandList::buildTopLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, RenderBufferReference instancesBuffer, const RenderTopLevelASBuildInfo &buildInfo) { assert(dstAccelerationStructure != nullptr); assert(scratchBuffer.ref != nullptr); + endActiveRenderPass(); assert(instancesBuffer.ref != nullptr); const VulkanAccelerationStructure *interfaceAccelerationStructure = static_cast(dstAccelerationStructure); @@ -3703,7 +3714,11 @@ namespace plume { void VulkanCommandList::checkActiveRenderPass() { assert(targetFramebuffer != nullptr); - + + if ((activeRenderPass != VK_NULL_HANDLE) && (activeFramebuffer != targetFramebuffer)) { + endActiveRenderPass(); + } + if (activeRenderPass == VK_NULL_HANDLE) { VkRenderPassBeginInfo beginInfo = {}; beginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; @@ -3713,6 +3728,7 @@ namespace plume { beginInfo.renderArea.extent.height = targetFramebuffer->height; vkCmdBeginRenderPass(vk, &beginInfo, VkSubpassContents::VK_SUBPASS_CONTENTS_INLINE); activeRenderPass = targetFramebuffer->renderPass; + activeFramebuffer = targetFramebuffer; } } @@ -3726,6 +3742,7 @@ namespace plume { passQueries.clear(); vkCmdEndRenderPass(vk); activeRenderPass = VK_NULL_HANDLE; + activeFramebuffer = nullptr; } } diff --git a/plume_vulkan.h b/plume_vulkan.h index 0cda581..9cced37 100644 --- a/plume_vulkan.h +++ b/plume_vulkan.h @@ -324,6 +324,8 @@ namespace plume { std::vector passQueriesClosed; // true: begin and end every query outside render passes (ends the active pass). bool queriesEndRenderPass = false; + // The framebuffer of the active render pass instance. + const VulkanFramebuffer *activeFramebuffer = nullptr; VulkanCommandList(VulkanCommandQueue *queue); ~VulkanCommandList() override;