Set dynamic pipeline state as dynamic
authorPiers Daniell <pdaniell@nvidia.com>
Tue, 29 Sep 2015 19:01:09 +0000 (13:01 -0600)
committerCourtney Goeltzenleuchter <courtney@LunarG.com>
Wed, 30 Sep 2015 22:41:04 +0000 (16:41 -0600)
demos/cube.c
demos/tri.c

index 9d3c7a8667fc5c52f59c9ef18fc3fa4229895c2f..f1b3eee4cfd94e6e898a9eecbc03d624590c626c 100644 (file)
@@ -561,20 +561,6 @@ static void demo_draw_build_cmd(struct demo *demo, VkCmdBuffer cmd_buf)
     scissor.offset.y = 0;
     vkCmdSetScissor(cmd_buf, 1, &scissor);
 
-    vkCmdSetLineWidth(cmd_buf, 1.0);
-    vkCmdSetDepthBias(cmd_buf, 0.0f, 0.0f, 0.0f);
-
-    float blend[4];
-    blend[0] = 1.0f;
-    blend[1] = 1.0f;
-    blend[2] = 1.0f;
-    blend[3] = 1.0f;
-    vkCmdSetBlendConstants(cmd_buf, blend);
-    vkCmdSetDepthBounds(cmd_buf, 0.0f, 1.0f);
-    vkCmdSetStencilCompareMask(cmd_buf, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0xff);
-    vkCmdSetStencilWriteMask(cmd_buf, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0xff);
-    vkCmdSetStencilReference(cmd_buf, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0);
-
     vkCmdDraw(cmd_buf, 12 * 3, 1, 0, 0);
     vkCmdEndRenderPass(cmd_buf);
 
@@ -1499,8 +1485,15 @@ static void demo_prepare_pipeline(struct demo *demo)
     VkPipelineDepthStencilStateCreateInfo  ds;
     VkPipelineViewportStateCreateInfo      vp;
     VkPipelineMultisampleStateCreateInfo   ms;
+    VkDynamicState                         dynamicStateEnables[VK_DYNAMIC_STATE_NUM];
+    VkPipelineDynamicStateCreateInfo       dynamicState;
     VkResult U_ASSERT_ONLY err;
 
+    memset(dynamicStateEnables, 0, sizeof dynamicStateEnables);
+    memset(&dynamicState, 0, sizeof dynamicState);
+    dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
+    dynamicState.pDynamicStates = dynamicStateEnables;
+
     memset(&pipeline, 0, sizeof(pipeline));
     pipeline.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
     pipeline.layout = demo->pipeline_layout;
@@ -1530,6 +1523,9 @@ static void demo_prepare_pipeline(struct demo *demo)
     memset(&vp, 0, sizeof(vp));
     vp.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
     vp.viewportCount = 1;
+    dynamicStateEnables[dynamicState.dynamicStateCount++] = VK_DYNAMIC_STATE_VIEWPORT;
+    vp.scissorCount = 1;
+    dynamicStateEnables[dynamicState.dynamicStateCount++] = VK_DYNAMIC_STATE_SCISSOR;
 
     memset(&ds, 0, sizeof(ds));
     ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
@@ -1576,6 +1572,7 @@ static void demo_prepare_pipeline(struct demo *demo)
     pipeline.pDepthStencilState  = &ds;
     pipeline.pStages             = shaderStages;
     pipeline.renderPass          = demo->render_pass;
+    pipeline.pDynamicState       = &dynamicState;
 
     pipeline.renderPass = demo->render_pass;
 
index b7dac9508d90c060bf9dbfd5814cd564aa6a3d31..71942b054b3fd90715bcf9af0c1db7c44bd3c2d8 100644 (file)
@@ -401,20 +401,6 @@ static void demo_draw_build_cmd(struct demo *demo)
     scissor.offset.y = 0;
     vkCmdSetScissor(demo->draw_cmd, 1, &scissor);
 
-    vkCmdSetLineWidth(demo->draw_cmd, 1.0);
-    vkCmdSetDepthBias(demo->draw_cmd, 0.0f, 0.0f, 0.0f);
-
-    float blend[4];
-    blend[0] = 1.0f;
-    blend[1] = 1.0f;
-    blend[2] = 1.0f;
-    blend[3] = 1.0f;
-    vkCmdSetBlendConstants(demo->draw_cmd, blend);
-    vkCmdSetDepthBounds(demo->draw_cmd, 0.0f, 1.0f);
-    vkCmdSetStencilCompareMask(demo->draw_cmd, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0xff);
-    vkCmdSetStencilWriteMask(demo->draw_cmd, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0xff);
-    vkCmdSetStencilReference(demo->draw_cmd, VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, 0);
-
     VkDeviceSize offsets[1] = {0};
     vkCmdBindVertexBuffers(demo->draw_cmd, VERTEX_BUFFER_BIND_ID, 1, &demo->vertices.buf, offsets);
 
@@ -1256,9 +1242,16 @@ static void demo_prepare_pipeline(struct demo *demo)
     VkPipelineDepthStencilStateCreateInfo  ds;
     VkPipelineViewportStateCreateInfo      vp;
     VkPipelineMultisampleStateCreateInfo   ms;
+    VkDynamicState                         dynamicStateEnables[VK_DYNAMIC_STATE_NUM];
+    VkPipelineDynamicStateCreateInfo       dynamicState;
 
     VkResult U_ASSERT_ONLY err;
 
+    memset(dynamicStateEnables, 0, sizeof dynamicStateEnables);
+    memset(&dynamicState, 0, sizeof dynamicState);
+    dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
+    dynamicState.pDynamicStates = dynamicStateEnables;
+
     memset(&pipeline, 0, sizeof(pipeline));
     pipeline.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
     pipeline.layout = demo->pipeline_layout;
@@ -1290,6 +1283,9 @@ static void demo_prepare_pipeline(struct demo *demo)
     memset(&vp, 0, sizeof(vp));
     vp.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
     vp.viewportCount = 1;
+    dynamicStateEnables[dynamicState.dynamicStateCount++] = VK_DYNAMIC_STATE_VIEWPORT;
+    vp.scissorCount = 1;
+    dynamicStateEnables[dynamicState.dynamicStateCount++] = VK_DYNAMIC_STATE_SCISSOR;
 
     memset(&ds, 0, sizeof(ds));
     ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
@@ -1330,6 +1326,7 @@ static void demo_prepare_pipeline(struct demo *demo)
     pipeline.pDepthStencilState  = &ds;
     pipeline.pStages             = shaderStages;
     pipeline.renderPass          = demo->render_pass;
+    pipeline.pDynamicState       = &dynamicState;
 
     memset(&pipelineCache, 0, sizeof(pipelineCache));
     pipelineCache.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
@@ -1665,7 +1662,7 @@ void VKAPI myfree(
     void*                           pUserData,
     void*                           pMem)
 {
-    return free(pMem);
+    free(pMem);
 }
 static void demo_init_vk(struct demo *demo)
 {