@@ -1104,6 +1104,18 @@ void Graphics::setDepthMode(CompareMode compare, bool write)
11041104 states.back ().depthWrite = write;
11051105}
11061106
1107+ void Graphics::setDepthClamp (bool enable)
1108+ {
1109+ flushBatchedDraws ();
1110+
1111+ if (optionalDeviceExtensions.extendedDynamicState3 )
1112+ {
1113+ vkCmdSetDepthClampEnableEXT (commandBuffers.at (currentFrame), Vulkan::getBool (enable));
1114+ }
1115+
1116+ states.back ().depthClampEnable = enable;
1117+ }
1118+
11071119void Graphics::setWireframe (bool enable)
11081120{
11091121 flushBatchedDraws ();
@@ -1357,6 +1369,11 @@ void Graphics::initDynamicState()
13571369 vkCmdSetFrontFaceEXT (
13581370 commandBuffers.at (currentFrame), Vulkan::getFrontFace (states.back ().winding ));
13591371 }
1372+
1373+ if (optionalDeviceExtensions.extendedDynamicState3 )
1374+ {
1375+ vkCmdSetDepthClampEnableEXT (commandBuffers.at (currentFrame), Vulkan::getBool (states.back ().depthClampEnable ));
1376+ }
13601377}
13611378
13621379void Graphics::beginSwapChainFrame ()
@@ -1782,6 +1799,8 @@ static void findOptionalDeviceExtensions(VkPhysicalDevice physicalDevice, Option
17821799 {
17831800 if (strcmp (extension.extensionName , VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME) == 0 )
17841801 optionalDeviceExtensions.extendedDynamicState = true ;
1802+ if (strcmp (extension.extensionName , VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME) == 0 )
1803+ optionalDeviceExtensions.extendedDynamicState3 = true ;
17851804 if (strcmp (extension.extensionName , VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME) == 0 )
17861805 optionalDeviceExtensions.memoryRequirements2 = true ;
17871806 if (strcmp (extension.extensionName , VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0 )
@@ -1844,6 +1863,8 @@ void Graphics::createLogicalDevice()
18441863 std::vector<const char *> enabledExtensions (deviceExtensions.begin (), deviceExtensions.end ());
18451864 if (optionalDeviceExtensions.extendedDynamicState )
18461865 enabledExtensions.push_back (VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
1866+ if (optionalDeviceExtensions.extendedDynamicState3 )
1867+ enabledExtensions.push_back (VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME);
18471868 if (optionalDeviceExtensions.memoryRequirements2 )
18481869 enabledExtensions.push_back (VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
18491870 if (optionalDeviceExtensions.dedicatedAllocation )
@@ -2609,13 +2630,23 @@ void Graphics::prepareDraw(VertexAttributesID attributesID, const BufferBindings
26092630 if (optionalDeviceExtensions.extendedDynamicState )
26102631 {
26112632 vkCmdSetCullModeEXT (commandBuffers.at (currentFrame), Vulkan::getCullMode (cullmode));
2612- pipeline = s->getCachedGraphicsPipeline (this , configuration.core );
2633+ if (!optionalDeviceExtensions.extendedDynamicState3 )
2634+ {
2635+ // If extended dynamic state 3 is not supported, we need to set the depth clamp enable manually via no dynamic state.
2636+ // But the depth clamp enable is not part of the core dynamic state, so we need to use noDynamicState only for depth clamp enable.
2637+ // Rest of the dynamic state is still set via extended dynamic state.
2638+ configuration.noDynamicState .depthClampEnable = states.back ().depthClampEnable ;
2639+ pipeline = s->getCachedGraphicsPipeline (this , configuration);
2640+ }
2641+ else
2642+ pipeline = s->getCachedGraphicsPipeline (this , configuration.core );
26132643 }
26142644 else
26152645 {
26162646 configuration.noDynamicState .winding = states.back ().winding ;
26172647 configuration.noDynamicState .depthState .compare = states.back ().depthTest ;
26182648 configuration.noDynamicState .depthState .write = states.back ().depthWrite ;
2649+ configuration.noDynamicState .depthClampEnable = states.back ().depthClampEnable ;
26192650 configuration.noDynamicState .stencilAction = states.back ().stencil .action ;
26202651 configuration.noDynamicState .stencilCompare = states.back ().stencil .compare ;
26212652 configuration.noDynamicState .cullmode = cullmode;
@@ -3012,7 +3043,6 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
30123043
30133044 VkPipelineRasterizationStateCreateInfo rasterizer{};
30143045 rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3015- rasterizer.depthClampEnable = VK_FALSE;
30163046 rasterizer.rasterizerDiscardEnable = VK_FALSE;
30173047 rasterizer.polygonMode = Vulkan::getPolygonMode (configuration.wireFrame );
30183048 rasterizer.lineWidth = 1 .0f ;
@@ -3022,6 +3052,9 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
30223052 rasterizer.frontFace = Vulkan::getFrontFace (noDynamicStateConfiguration->winding );
30233053 }
30243054
3055+ if (!optionalDeviceExtensions.extendedDynamicState3 )
3056+ rasterizer.depthClampEnable = Vulkan::getBool (noDynamicStateConfiguration->depthClampEnable );
3057+
30253058 rasterizer.depthBiasEnable = VK_FALSE;
30263059 rasterizer.depthBiasConstantFactor = 0 .0f ;
30273060 rasterizer.depthBiasClamp = 0 .0f ;
@@ -3098,7 +3131,7 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
30983131
30993132 std::vector<VkDynamicState> dynamicStates;
31003133
3101- if (optionalDeviceExtensions.extendedDynamicState )
3134+ if (optionalDeviceExtensions.extendedDynamicState3 )
31023135 dynamicStates = {
31033136 VK_DYNAMIC_STATE_SCISSOR,
31043137 VK_DYNAMIC_STATE_VIEWPORT,
@@ -3111,15 +3144,30 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
31113144 VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT,
31123145 VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT,
31133146 VK_DYNAMIC_STATE_STENCIL_OP_EXT,
3114- };
3147+ VK_DYNAMIC_STATE_DEPTH_CLAMP_ENABLE_EXT,
3148+ };
3149+ else if (optionalDeviceExtensions.extendedDynamicState )
3150+ dynamicStates = {
3151+ VK_DYNAMIC_STATE_SCISSOR,
3152+ VK_DYNAMIC_STATE_VIEWPORT,
3153+ VK_DYNAMIC_STATE_STENCIL_WRITE_MASK,
3154+ VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
3155+ VK_DYNAMIC_STATE_STENCIL_REFERENCE,
3156+
3157+ VK_DYNAMIC_STATE_CULL_MODE_EXT,
3158+ VK_DYNAMIC_STATE_FRONT_FACE_EXT,
3159+ VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT,
3160+ VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT,
3161+ VK_DYNAMIC_STATE_STENCIL_OP_EXT,
3162+ };
31153163 else
31163164 dynamicStates = {
31173165 VK_DYNAMIC_STATE_SCISSOR,
31183166 VK_DYNAMIC_STATE_VIEWPORT,
31193167 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK,
31203168 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
31213169 VK_DYNAMIC_STATE_STENCIL_REFERENCE,
3122- };
3170+ };
31233171
31243172 VkPipelineDynamicStateCreateInfo dynamicState{};
31253173 dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
0 commit comments