bug-14365: add dynamic state to PSO
authorCourtney Goeltzenleuchter <courtney@LunarG.com>
Mon, 21 Sep 2015 23:19:25 +0000 (17:19 -0600)
committerCourtney Goeltzenleuchter <courtney@LunarG.com>
Wed, 23 Sep 2015 17:15:00 +0000 (11:15 -0600)
This commit covers phase 2 of the removal of dynamic
state objects. Now, an application can include an array
of VK_DYNAMIC_STATE_* values that tell the driver
which PSO dynamic state elements to use.
I.e. if VK_DYNAMIC_STATE_LINE_WIDTH was specified in the
pDynamicState array then the ICD should use the lineWidth
defined at PSO create time and ignore any set using
vkCmdSetLineWidth.
To accomplish that the driver will make a copy of the
dynamic state specified in the PSO as well as a bitmask
of the affected state. When vkCmdSet* is called, the
driver will check if a PSO override is current and ignore
the call if so.
At PSO bind time the command buffer's dynamic state
will be updated and the PSO override bitmask set so that
any future vkCmdSet*'s will be appropriately ignored.
TODO: Validation layer should probably indicate a warning
if app tries to do vkCmdSet on state defined by the PSO.

include/vulkan.h
layers/draw_state.cpp

index 2a1e06d4e6625cbb9e75582ffbe52a5cc90eacb5..8be2b4f3194cce351cd5f37b5f1af5c07dbdd7bd 100644 (file)
@@ -41,7 +41,7 @@ extern "C" {
     ((major << 22) | (minor << 12) | patch)
 
 // Vulkan API version supported by this file
-#define VK_API_VERSION VK_MAKE_VERSION(0, 170, 1)
+#define VK_API_VERSION VK_MAKE_VERSION(0, 170, 2)
 
 
 #if defined(__cplusplus) && (_MSC_VER >= 1800 || __cplusplus >= 201103L)
@@ -206,9 +206,10 @@ typedef enum {
     VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO = 43,
     VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO = 44,
     VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO = 45,
+    VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO = 46,
     VK_STRUCTURE_TYPE_BEGIN_RANGE = VK_STRUCTURE_TYPE_APPLICATION_INFO,
-    VK_STRUCTURE_TYPE_END_RANGE = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
-    VK_STRUCTURE_TYPE_NUM = (VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO - VK_STRUCTURE_TYPE_APPLICATION_INFO + 1),
+    VK_STRUCTURE_TYPE_END_RANGE = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
+    VK_STRUCTURE_TYPE_NUM = (VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO - VK_STRUCTURE_TYPE_APPLICATION_INFO + 1),
     VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
 } VkStructureType;
 
@@ -669,6 +670,22 @@ typedef enum {
     VK_BLEND_OP_MAX_ENUM = 0x7FFFFFFF
 } VkBlendOp;
 
+typedef enum {
+    VK_DYNAMIC_STATE_VIEWPORT = 0,
+    VK_DYNAMIC_STATE_SCISSOR = 1,
+    VK_DYNAMIC_STATE_LINE_WIDTH = 2,
+    VK_DYNAMIC_STATE_DEPTH_BIAS = 3,
+    VK_DYNAMIC_STATE_BLEND_CONSTANTS = 4,
+    VK_DYNAMIC_STATE_DEPTH_BOUNDS = 5,
+    VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK = 6,
+    VK_DYNAMIC_STATE_STENCIL_WRITE_MASK = 7,
+    VK_DYNAMIC_STATE_STENCIL_REFERENCE = 8,
+    VK_DYNAMIC_STATE_BEGIN_RANGE = VK_DYNAMIC_STATE_VIEWPORT,
+    VK_DYNAMIC_STATE_END_RANGE = VK_DYNAMIC_STATE_STENCIL_REFERENCE,
+    VK_DYNAMIC_STATE_NUM = (VK_DYNAMIC_STATE_STENCIL_REFERENCE - VK_DYNAMIC_STATE_VIEWPORT + 1),
+    VK_DYNAMIC_STATE_MAX_ENUM = 0x7FFFFFFF
+} VkDynamicState;
+
 typedef enum {
     VK_TEX_FILTER_NEAREST = 0,
     VK_TEX_FILTER_LINEAR = 1,
@@ -1640,6 +1657,9 @@ typedef struct {
     VkStructureType                             sType;
     const void*                                 pNext;
     uint32_t                                    viewportCount;
+    const VkViewport*                           pViewports;
+    uint32_t                                    scissorCount;
+    const VkRect2D*                             pScissors;
 } VkPipelineViewportStateCreateInfo;
 
 typedef struct {
@@ -1651,6 +1671,10 @@ typedef struct {
     VkCullMode                                  cullMode;
     VkFrontFace                                 frontFace;
     VkBool32                                    depthBiasEnable;
+    float                                       depthBias;
+    float                                       depthBiasClamp;
+    float                                       slopeScaledDepthBias;
+    float                                       lineWidth;
 } VkPipelineRasterStateCreateInfo;
 
 typedef struct {
@@ -1667,6 +1691,9 @@ typedef struct {
     VkStencilOp                                 stencilPassOp;
     VkStencilOp                                 stencilDepthFailOp;
     VkCompareOp                                 stencilCompareOp;
+    uint32_t                                    stencilCompareMask;
+    uint32_t                                    stencilWriteMask;
+    uint32_t                                    stencilReference;
 } VkStencilOpState;
 
 typedef struct {
@@ -1679,6 +1706,8 @@ typedef struct {
     VkBool32                                    stencilTestEnable;
     VkStencilOpState                            front;
     VkStencilOpState                            back;
+    float                                       minDepthBounds;
+    float                                       maxDepthBounds;
 } VkPipelineDepthStencilStateCreateInfo;
 
 typedef struct {
@@ -1701,8 +1730,16 @@ typedef struct {
     VkLogicOp                                   logicOp;
     uint32_t                                    attachmentCount;
     const VkPipelineColorBlendAttachmentState*  pAttachments;
+    float                                       blendConst[4];
 } VkPipelineColorBlendStateCreateInfo;
 
+typedef struct {
+    VkStructureType                             sType;
+    const void*                                 pNext;
+    uint32_t                                    dynamicStateCount;
+    const VkDynamicState*                       pDynamicStates;
+} VkPipelineDynamicStateCreateInfo;
+
 typedef struct {
     VkStructureType                             sType;
     const void*                                 pNext;
@@ -1716,6 +1753,7 @@ typedef struct {
     const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
     const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
     const VkPipelineColorBlendStateCreateInfo*  pColorBlendState;
+    const VkPipelineDynamicStateCreateInfo*     pDynamicState;
     VkPipelineCreateFlags                       flags;
     VkPipelineLayout                            layout;
     VkRenderPass                                renderPass;
index f6b6a6d2927e7900b356305e88995da2961b94aa..a0780fdacc2282f9ea3d17bbf9ec6880f7f90016 100644 (file)
@@ -2332,7 +2332,12 @@ VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex
         if (pCB->state == CB_UPDATE_ACTIVE) {
             pCB->drawCount[DRAW]++;
             skipCall |= validate_draw_state(pCB, VK_FALSE);
-            /* TODO: Check that scissor and viewport counts are the same */
+            /* TODOVV: Check that scissor and viewport counts are the same */
+            /* TODOVV: Do we need to check that viewportCount given in pipeline's
+             * VkPipelineViewportStateCreateInfo matches scissor & viewport counts
+             * given as dynamic state? Or is the count given in VkPipelineViewportStateCreateInfo
+             * simply indicate the number of viewport / scissor to use at this time?
+             */
             // TODO : Need to pass cmdBuffer as srcObj here
             skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
                     "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);