@@ -1104,6 +1104,18 @@ void Graphics::setDepthMode(CompareMode compare, bool write)
1104
1104
states.back ().depthWrite = write;
1105
1105
}
1106
1106
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
+
1107
1119
void Graphics::setWireframe (bool enable)
1108
1120
{
1109
1121
flushBatchedDraws ();
@@ -1357,6 +1369,11 @@ void Graphics::initDynamicState()
1357
1369
vkCmdSetFrontFaceEXT (
1358
1370
commandBuffers.at (currentFrame), Vulkan::getFrontFace (states.back ().winding ));
1359
1371
}
1372
+
1373
+ if (optionalDeviceExtensions.extendedDynamicState3 )
1374
+ {
1375
+ vkCmdSetDepthClampEnableEXT (commandBuffers.at (currentFrame), Vulkan::getBool (states.back ().depthClampEnable ));
1376
+ }
1360
1377
}
1361
1378
1362
1379
void Graphics::beginSwapChainFrame ()
@@ -1782,6 +1799,8 @@ static void findOptionalDeviceExtensions(VkPhysicalDevice physicalDevice, Option
1782
1799
{
1783
1800
if (strcmp (extension.extensionName , VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME) == 0 )
1784
1801
optionalDeviceExtensions.extendedDynamicState = true ;
1802
+ if (strcmp (extension.extensionName , VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME) == 0 )
1803
+ optionalDeviceExtensions.extendedDynamicState3 = true ;
1785
1804
if (strcmp (extension.extensionName , VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME) == 0 )
1786
1805
optionalDeviceExtensions.memoryRequirements2 = true ;
1787
1806
if (strcmp (extension.extensionName , VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0 )
@@ -1844,6 +1863,8 @@ void Graphics::createLogicalDevice()
1844
1863
std::vector<const char *> enabledExtensions (deviceExtensions.begin (), deviceExtensions.end ());
1845
1864
if (optionalDeviceExtensions.extendedDynamicState )
1846
1865
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);
1847
1868
if (optionalDeviceExtensions.memoryRequirements2 )
1848
1869
enabledExtensions.push_back (VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
1849
1870
if (optionalDeviceExtensions.dedicatedAllocation )
@@ -2609,13 +2630,23 @@ void Graphics::prepareDraw(VertexAttributesID attributesID, const BufferBindings
2609
2630
if (optionalDeviceExtensions.extendedDynamicState )
2610
2631
{
2611
2632
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 );
2613
2643
}
2614
2644
else
2615
2645
{
2616
2646
configuration.noDynamicState .winding = states.back ().winding ;
2617
2647
configuration.noDynamicState .depthState .compare = states.back ().depthTest ;
2618
2648
configuration.noDynamicState .depthState .write = states.back ().depthWrite ;
2649
+ configuration.noDynamicState .depthClampEnable = states.back ().depthClampEnable ;
2619
2650
configuration.noDynamicState .stencilAction = states.back ().stencil .action ;
2620
2651
configuration.noDynamicState .stencilCompare = states.back ().stencil .compare ;
2621
2652
configuration.noDynamicState .cullmode = cullmode;
@@ -3012,7 +3043,6 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
3012
3043
3013
3044
VkPipelineRasterizationStateCreateInfo rasterizer{};
3014
3045
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3015
- rasterizer.depthClampEnable = VK_FALSE;
3016
3046
rasterizer.rasterizerDiscardEnable = VK_FALSE;
3017
3047
rasterizer.polygonMode = Vulkan::getPolygonMode (configuration.wireFrame );
3018
3048
rasterizer.lineWidth = 1 .0f ;
@@ -3022,6 +3052,9 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
3022
3052
rasterizer.frontFace = Vulkan::getFrontFace (noDynamicStateConfiguration->winding );
3023
3053
}
3024
3054
3055
+ if (!optionalDeviceExtensions.extendedDynamicState3 )
3056
+ rasterizer.depthClampEnable = Vulkan::getBool (noDynamicStateConfiguration->depthClampEnable );
3057
+
3025
3058
rasterizer.depthBiasEnable = VK_FALSE;
3026
3059
rasterizer.depthBiasConstantFactor = 0 .0f ;
3027
3060
rasterizer.depthBiasClamp = 0 .0f ;
@@ -3098,7 +3131,7 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
3098
3131
3099
3132
std::vector<VkDynamicState> dynamicStates;
3100
3133
3101
- if (optionalDeviceExtensions.extendedDynamicState )
3134
+ if (optionalDeviceExtensions.extendedDynamicState3 )
3102
3135
dynamicStates = {
3103
3136
VK_DYNAMIC_STATE_SCISSOR,
3104
3137
VK_DYNAMIC_STATE_VIEWPORT,
@@ -3111,15 +3144,30 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
3111
3144
VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT,
3112
3145
VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT,
3113
3146
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
+ };
3115
3163
else
3116
3164
dynamicStates = {
3117
3165
VK_DYNAMIC_STATE_SCISSOR,
3118
3166
VK_DYNAMIC_STATE_VIEWPORT,
3119
3167
VK_DYNAMIC_STATE_STENCIL_WRITE_MASK,
3120
3168
VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
3121
3169
VK_DYNAMIC_STATE_STENCIL_REFERENCE,
3122
- };
3170
+ };
3123
3171
3124
3172
VkPipelineDynamicStateCreateInfo dynamicState{};
3125
3173
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
0 commit comments