#ifdef ANDROID
#include "vulkan_wrapper.h"
#else
+#define NOMINMAX
#include <vulkan/vulkan.h>
#endif
#include <memory>
#include <unordered_set>
-#define GLM_FORCE_RADIANS
-#include "glm/glm.hpp"
-#include <glm/gtc/matrix_transform.hpp>
-
//--------------------------------------------------------------------------------------
// Mesh and VertexFormat Data
//--------------------------------------------------------------------------------------
-struct Vertex {
- float posX, posY, posZ, posW; // Position data
- float r, g, b, a; // Color
-};
-#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
-
-typedef enum _BsoFailSelect {
- BsoFailNone = 0x00000000,
- BsoFailLineWidth = 0x00000001,
- BsoFailDepthBias = 0x00000002,
- BsoFailViewport = 0x00000004,
- BsoFailScissor = 0x00000008,
- BsoFailBlend = 0x00000010,
- BsoFailDepthBounds = 0x00000020,
- BsoFailStencilReadMask = 0x00000040,
- BsoFailStencilWriteMask = 0x00000080,
- BsoFailStencilReference = 0x00000100,
- BsoFailCmdClearAttachments = 0x00000200,
- BsoFailIndexBuffer = 0x00000400,
-} BsoFailSelect;
-
-struct vktriangle_vs_uniform {
- // Must start with MVP
- float mvp[4][4];
- float position[3][4];
- float color[3][4];
+enum BsoFailSelect {
+ BsoFailNone,
+ BsoFailLineWidth,
+ BsoFailDepthBias,
+ BsoFailViewport,
+ BsoFailScissor,
+ BsoFailBlend,
+ BsoFailDepthBounds,
+ BsoFailStencilReadMask,
+ BsoFailStencilWriteMask,
+ BsoFailStencilReference,
+ BsoFailCmdClearAttachments,
+ BsoFailIndexBuffer
};
static const char bindStateVertShaderText[] =
return ds_formats[i];
}
}
- return (VkFormat)0;
+ return VK_FORMAT_UNDEFINED;
}
// Returns true if *any* requested features are available.
class VkLayerTest : public VkRenderFramework {
public:
- void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
+ void VKTriangleTest(BsoFailSelect failCase);
void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
- BsoFailSelect failMask);
+ BsoFailSelect failCase);
void Init(VkPhysicalDeviceFeatures *features = nullptr, const VkCommandPoolCreateFlags flags = 0) {
InitFramework(myDbgFunc, m_errorMonitor);
VkLayerTest() { m_enableWSI = false; }
};
-void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
- // Create identity matrix
- int i;
- struct vktriangle_vs_uniform data;
-
- glm::mat4 Projection = glm::mat4(1.0f);
- glm::mat4 View = glm::mat4(1.0f);
- glm::mat4 Model = glm::mat4(1.0f);
- glm::mat4 MVP = Projection * View * Model;
- const int matrixSize = sizeof(MVP);
-
- memcpy(&data.mvp, &MVP[0][0], matrixSize);
-
- static const Vertex tri_data[] = {
- {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
- };
-
- for (i = 0; i < 3; i++) {
- data.position[i][0] = tri_data[i].posX;
- data.position[i][1] = tri_data[i].posY;
- data.position[i][2] = tri_data[i].posZ;
- data.position[i][3] = tri_data[i].posW;
- data.color[i][0] = tri_data[i].r;
- data.color[i][1] = tri_data[i].g;
- data.color[i][2] = tri_data[i].b;
- data.color[i][3] = tri_data[i].a;
- }
+void VkLayerTest::VKTriangleTest(BsoFailSelect failCase) {
+ ASSERT_TRUE(m_device && m_device->initialized()); // VKTriangleTest assumes Init() has finished
ASSERT_NO_FATAL_FAILURE(InitViewport());
- VkConstantBufferObj constantBuffer(m_device, sizeof(vktriangle_vs_uniform), (const void *)&data,
- VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
-
- VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
- VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
+ VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
+ VkShaderObj ps(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipelineobj(m_device);
- pipelineobj.AddColorAttachment();
+ pipelineobj.AddDefaultColorAttachment();
pipelineobj.AddShader(&vs);
pipelineobj.AddShader(&ps);
- if (failMask & BsoFailLineWidth) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
- VkPipelineInputAssemblyStateCreateInfo ia_state = {};
- ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
- ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
- pipelineobj.SetInputAssembly(&ia_state);
- }
- if (failMask & BsoFailDepthBias) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
- VkPipelineRasterizationStateCreateInfo rs_state = {};
- rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
- rs_state.depthBiasEnable = VK_TRUE;
- rs_state.lineWidth = 1.0f;
- pipelineobj.SetRasterization(&rs_state);
- }
- // Viewport and scissors must stay in sync or other errors will occur than
- // the ones we want
- if (failMask & BsoFailViewport) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
- }
- if (failMask & BsoFailScissor) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
- }
- if (failMask & BsoFailBlend) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
- VkPipelineColorBlendAttachmentState att_state = {};
- att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
- att_state.blendEnable = VK_TRUE;
- pipelineobj.AddColorAttachment(0, &att_state);
- }
- if (failMask & BsoFailDepthBounds) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
- }
- if (failMask & BsoFailStencilReadMask) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
- }
- if (failMask & BsoFailStencilWriteMask) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
- }
- if (failMask & BsoFailStencilReference) {
- pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
+
+ bool failcase_needs_depth = false; // to mark cases that need depth attachment
+
+ switch (failCase) {
+ case BsoFailLineWidth: {
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
+ VkPipelineInputAssemblyStateCreateInfo ia_state = {};
+ ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
+ ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
+ pipelineobj.SetInputAssembly(&ia_state);
+ break;
+ }
+ case BsoFailDepthBias: {
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
+ VkPipelineRasterizationStateCreateInfo rs_state = {};
+ rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
+ rs_state.depthBiasEnable = VK_TRUE;
+ rs_state.lineWidth = 1.0f;
+ pipelineobj.SetRasterization(&rs_state);
+ break;
+ }
+ case BsoFailViewport: {
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
+ break;
+ }
+ case BsoFailScissor: {
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
+ break;
+ }
+ case BsoFailBlend: {
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
+ VkPipelineColorBlendAttachmentState att_state = {};
+ att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
+ att_state.blendEnable = VK_TRUE;
+ pipelineobj.AddColorAttachment(0, att_state);
+ break;
+ }
+ case BsoFailDepthBounds: {
+ failcase_needs_depth = true;
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
+ break;
+ }
+ case BsoFailStencilReadMask: {
+ failcase_needs_depth = true;
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
+ break;
+ }
+ case BsoFailStencilWriteMask: {
+ failcase_needs_depth = true;
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
+ break;
+ }
+ case BsoFailStencilReference: {
+ failcase_needs_depth = true;
+ pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
+ break;
+ }
+
+ case BsoFailIndexBuffer:
+ break;
+ case BsoFailCmdClearAttachments:
+ break;
+ case BsoFailNone:
+ break;
+ default:
+ break;
}
VkDescriptorSetObj descriptorSet(m_device);
- descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
- ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
+ VkImageView *depth_attachment = nullptr;
+ if (failcase_needs_depth) {
+ m_depth_stencil_fmt = FindSupportedDepthStencilFormat(gpu());
+ ASSERT_TRUE(m_depth_stencil_fmt != VK_FORMAT_UNDEFINED);
+
+ m_depthStencil->Init(m_device, static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height), m_depth_stencil_fmt,
+ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
+ depth_attachment = m_depthStencil->BindInfo();
+ }
+
+ ASSERT_NO_FATAL_FAILURE(InitRenderTarget(1, depth_attachment));
m_commandBuffer->begin();
- m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
- GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
+ GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failCase);
+
+ m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
// render triangle
- if (failMask & BsoFailIndexBuffer) {
+ if (failCase == BsoFailIndexBuffer) {
// Use DrawIndexed w/o an index buffer bound
m_commandBuffer->DrawIndexed(3, 1, 0, 0, 0);
} else {
m_commandBuffer->Draw(3, 1, 0, 0);
}
- if (failMask & BsoFailCmdClearAttachments) {
+ if (failCase == BsoFailCmdClearAttachments) {
VkClearAttachment color_attachment = {};
color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
- if (m_depthStencil->Initialized()) {
- commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
- } else {
- commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
- }
+ commandBuffer->ClearAllBuffers(m_renderTargets, m_clear_color, m_depthStencil, m_depth_clear_color, m_stencil_clear_color);
- commandBuffer->PrepareAttachments();
+ commandBuffer->PrepareAttachments(m_renderTargets, m_depthStencil);
// Make sure depthWriteEnable is set so that Depth fail test will work
// correctly
// Make sure stencilTestEnable is set so that Stencil fail test will work
VkPipelineObj pipe(&test_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
// Introduce failure by setting unsupported polygon mode
rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
pipe.SetRasterization(&rs_ci);
VkPipelineObj pipe(&test_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
// Introduce failure by setting unsupported polygon mode
rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
pipe.SetRasterization(&rs_ci);
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
m_commandBuffer->begin();
- m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
+ m_commandBuffer->ClearAllBuffers(m_renderTargets, m_clear_color, nullptr, m_depth_clear_color, m_stencil_clear_color);
m_commandBuffer->end();
testFence.init(*m_device, fenceInfo);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkViewport view_port = {};
att_state1.blendEnable = VK_TRUE;
att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
att_state2.blendEnable = VK_FALSE;
- pipeline.AddColorAttachment(0, &att_state1);
- pipeline.AddColorAttachment(1, &att_state2);
+ pipeline.AddColorAttachment(0, att_state1);
+ pipeline.AddColorAttachment(1, att_state2);
pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
m_errorMonitor->VerifyFound();
vkDestroyRenderPass(m_device->device(), renderpass, NULL);
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_096005e2);
VkPipelineObj pipeline(m_device);
pipeline.AddShader(&vs_obj);
- pipeline.AddColorAttachment(0, &att_state1);
+ pipeline.AddColorAttachment(0, att_state1);
VkGraphicsPipelineCreateInfo info = {};
pipeline.InitGraphicsPipelineCreateInfo(&info);
ASSERT_NO_FATAL_FAILURE(Init());
// Dynamic depth bias
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
+ VKTriangleTest(BsoFailDepthBias);
m_errorMonitor->VerifyFound();
}
ASSERT_NO_FATAL_FAILURE(Init());
// Dynamic line width
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
+ VKTriangleTest(BsoFailLineWidth);
m_errorMonitor->VerifyFound();
}
// Dynamic viewport state
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
+ VKTriangleTest(BsoFailViewport);
m_errorMonitor->VerifyFound();
}
// Dynamic scissor state
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
+ VKTriangleTest(BsoFailScissor);
m_errorMonitor->VerifyFound();
}
// Dynamic blend constant state
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Dynamic blend constants state not set for this command buffer");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
+ VKTriangleTest(BsoFailBlend);
m_errorMonitor->VerifyFound();
}
// Dynamic depth bounds
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Dynamic depth bounds state not set for this command buffer");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
+ VKTriangleTest(BsoFailDepthBounds);
m_errorMonitor->VerifyFound();
}
// Dynamic stencil read mask
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Dynamic stencil read mask state not set for this command buffer");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
+ VKTriangleTest(BsoFailStencilReadMask);
m_errorMonitor->VerifyFound();
}
// Dynamic stencil write mask
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Dynamic stencil write mask state not set for this command buffer");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
+ VKTriangleTest(BsoFailStencilWriteMask);
m_errorMonitor->VerifyFound();
}
// Dynamic stencil reference
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Dynamic stencil reference state not set for this command buffer");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
+ VKTriangleTest(BsoFailStencilReference);
m_errorMonitor->VerifyFound();
}
ASSERT_NO_FATAL_FAILURE(Init());
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"Index buffer object not bound to this command buffer when Indexed ");
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
+ VKTriangleTest(BsoFailIndexBuffer);
m_errorMonitor->VerifyFound();
}
// We luck out b/c by default the framework creates CB w/ the
// VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
m_commandBuffer->begin();
- m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
+ m_commandBuffer->ClearAllBuffers(m_renderTargets, m_clear_color, nullptr, m_depth_clear_color, m_stencil_clear_color);
m_commandBuffer->end();
// Bypass framework since it does the waits automatically
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
err = pipe.CreateVKPipeline(pipeline_layout, renderPass());
ASSERT_VK_SUCCESS(err);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound BufferView ");
VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkViewport view_port = {};
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
m_commandBuffer->begin();
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
// First error case is destroying sampler prior to cmd buffer submission
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
VkCommandBufferObj cmd_buf(m_device, m_commandPool);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
m_commandBuffer->begin();
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
m_commandBuffer->begin();
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
VkViewport viewport = {0, 0, 16, 16, 0, 1};
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
m_commandBuffer->begin();
VkPipelineObj pipeline_dyn_vp(m_device);
pipeline_dyn_vp.AddShader(&vs);
pipeline_dyn_vp.AddShader(&fs);
- pipeline_dyn_vp.AddColorAttachment();
+ pipeline_dyn_vp.AddDefaultColorAttachment();
pipeline_dyn_vp.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
pipeline_dyn_vp.SetScissor(m_scissors);
ASSERT_VK_SUCCESS(pipeline_dyn_vp.CreateVKPipeline(pipeline_layout, m_renderPass));
VkPipelineObj pipeline_dyn_sc(m_device);
pipeline_dyn_sc.AddShader(&vs);
pipeline_dyn_sc.AddShader(&fs);
- pipeline_dyn_sc.AddColorAttachment();
+ pipeline_dyn_sc.AddDefaultColorAttachment();
pipeline_dyn_sc.SetViewport(m_viewports);
pipeline_dyn_sc.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
ASSERT_VK_SUCCESS(pipeline_dyn_sc.CreateVKPipeline(pipeline_layout, m_renderPass));
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.SetMSAA(&pipe_ms_state_ci);
pipe.CreateVKPipeline(pipeline_layout, renderPass());
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
VkViewport view_port = {};
m_viewports.push_back(view_port);
pipe.SetViewport(m_viewports);
ASSERT_NO_FATAL_FAILURE(Init());
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_1860001e);
- VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
+ VKTriangleTest(BsoFailCmdClearAttachments);
m_errorMonitor->VerifyFound();
}
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.SetMSAA(&pipe_ms_state_ci);
pipe.CreateVKPipeline(pipeline_layout, renderPass());
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.SetMSAA(&pipe_ms_state_ci);
pipe.SetViewport(m_viewports);
pipe.SetScissor(m_scissors);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.SetMSAA(&pipe_ms_state_ci);
pipe.SetViewport(m_viewports);
pipe.SetScissor(m_scissors);
VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
delete_this_pipeline = pipe.handle();
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_25400804);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_23e00750);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_26600874);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&tcs);
pipe.AddShader(&tes);
ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkRenderpassObj render_pass(&test_device);
VkPipelineObj pipe(&test_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkPipelineObj pipe(m_device);
pipe.SetInputAssembly(&iasci);
pipe.SetTessellation(&tsci);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&tcs);
pipe.AddShader(&tes);
VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
pipe.SetInputAssembly(&iasci_bad);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
pipe.SetInputAssembly(&iasci_bad);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
{
VkPipelineObj pipe(m_device);
pipe.SetInputAssembly(&iasci);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
pipe.AddShader(&fs);
/* set up CB 0, not written */
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetObj descriptorSet(m_device);
pipe.AddShader(&fs);
/* set up CB 0, not written, but also masked */
- pipe.AddColorAttachment(0);
+ pipe.AddDefaultColorAttachment(0);
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetObj descriptorSet(m_device);
pipe.AddShader(&fs);
/* set up CB 0, not written */
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
/* FS writes CB 1, but we don't configure it */
pipe.AddShader(&fs);
/* set up CB 0; type is UNORM by default */
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetObj descriptorSet(m_device);
pipe.AddShader(&fs);
/* set up CB 0; type is UNORM by default */
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetObj descriptorSet(m_device);
pipe.AddShader(&fs);
/* set up CB 0; type is UNORM by default */
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetObj descriptorSet(m_device);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
VkTextureObj texture(m_device, nullptr);
VkSamplerObj sampler(m_device);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
VkTextureObj texture(m_device, nullptr);
VkSamplerObj sampler(m_device);
pipe.SetScissor(m_scissors);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
static const float bo_data[1] = {1.f};
pipe.SetScissor(m_scissors);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.CreateVKPipeline(pipeline_layout, renderPass());
vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkPipelineObj pipe(m_device);
pipe.SetInputAssembly(&iasci);
pipe.SetTessellation(&tsci);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&tcs);
pipe.AddShader(&tes);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&gs);
pipe.AddShader(&fs);
VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
VkPipelineObj pipe(m_device);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.AddShader(&vs);
pipe.AddShader(&fs);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
VkPipelineObj pipe(&test_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
// Set polygonMode to a good value
rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
pipe.SetRasterization(&rs_ci);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
- pipe.AddColorAttachment();
+ pipe.AddDefaultColorAttachment();
pipe.SetMSAA(&ms_state_ci);
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_09600bc2);
if (props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
img->Init((uint32_t)m_width, (uint32_t)m_height, 1, m_render_target_fmt,
- VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR);
+ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
+ VK_IMAGE_TILING_LINEAR);
} else if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
img->Init((uint32_t)m_width, (uint32_t)m_height, 1, m_render_target_fmt,
- VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
+ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
+ VK_IMAGE_TILING_OPTIMAL);
} else {
FAIL() << "Neither Linear nor Optimal allowed for render target";
}
VkPipelineLayout VkDescriptorSetObj::GetPipelineLayout() const { return m_pipeline_layout.handle(); }
-VkDescriptorSet VkDescriptorSetObj::GetDescriptorSetHandle() const { return m_set->handle(); }
+VkDescriptorSet VkDescriptorSetObj::GetDescriptorSetHandle() const {
+ if (m_set)
+ return m_set->handle();
+ else
+ return VK_NULL_HANDLE;
+}
void VkDescriptorSetObj::CreateVKDescriptorSet(VkCommandBufferObj *commandBuffer) {
if (m_type_counts.size()) {
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
VK_MEMORY_INPUT_COPY_BIT*/,
VkImageLayout image_layout) {
- const VkImageSubresourceRange subresourceRange = subresource_range(aspect, 0, 1, 0, 1);
+ const VkImageSubresourceRange subresourceRange =
+ subresource_range(aspect, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS);
VkImageMemoryBarrier barrier;
barrier = image_memory_barrier(output_mask, input_mask, Layout(), image_layout, subresourceRange);
VkPipelineObj::VkPipelineObj(VkDeviceObj *device) {
m_device = device;
- m_vi_state.pNext = VK_NULL_HANDLE;
+ m_vi_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
+ m_vi_state.pNext = nullptr;
m_vi_state.flags = 0;
m_vi_state.vertexBindingDescriptionCount = 0;
- m_vi_state.pVertexBindingDescriptions = VK_NULL_HANDLE;
+ m_vi_state.pVertexBindingDescriptions = nullptr;
m_vi_state.vertexAttributeDescriptionCount = 0;
- m_vi_state.pVertexAttributeDescriptions = VK_NULL_HANDLE;
+ m_vi_state.pVertexAttributeDescriptions = nullptr;
m_ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
- m_ia_state.pNext = VK_NULL_HANDLE;
+ m_ia_state.pNext = nullptr;
m_ia_state.flags = 0;
m_ia_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
m_ia_state.primitiveRestartEnable = VK_FALSE;
+ m_te_state = nullptr;
+
+ m_vp_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
+ m_vp_state.pNext = VK_NULL_HANDLE;
+ m_vp_state.flags = 0;
+ m_vp_state.viewportCount = 1;
+ m_vp_state.scissorCount = 1;
+ m_vp_state.pViewports = nullptr;
+ m_vp_state.pScissors = nullptr;
+
m_rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
- m_rs_state.pNext = VK_NULL_HANDLE;
+ m_rs_state.pNext = nullptr;
m_rs_state.flags = 0;
m_rs_state.depthClampEnable = VK_FALSE;
m_rs_state.rasterizerDiscardEnable = VK_FALSE;
m_rs_state.cullMode = VK_CULL_MODE_BACK_BIT;
m_rs_state.frontFace = VK_FRONT_FACE_CLOCKWISE;
m_rs_state.depthBiasEnable = VK_FALSE;
- m_rs_state.lineWidth = 1.0f;
m_rs_state.depthBiasConstantFactor = 0.0f;
m_rs_state.depthBiasClamp = 0.0f;
m_rs_state.depthBiasSlopeFactor = 0.0f;
+ m_rs_state.lineWidth = 1.0f;
- memset(&m_cb_state, 0, sizeof(m_cb_state));
- m_cb_state.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
- m_cb_state.pNext = VK_NULL_HANDLE;
- m_cb_state.logicOp = VK_LOGIC_OP_COPY;
- m_cb_state.blendConstants[0] = 1.0f;
- m_cb_state.blendConstants[1] = 1.0f;
- m_cb_state.blendConstants[2] = 1.0f;
- m_cb_state.blendConstants[3] = 1.0f;
-
- m_ms_state.pNext = VK_NULL_HANDLE;
m_ms_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
+ m_ms_state.pNext = nullptr;
m_ms_state.flags = 0;
- m_ms_state.pSampleMask = NULL;
+ m_ms_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+ m_ms_state.sampleShadingEnable = VK_FALSE;
+ m_ms_state.minSampleShading = 0.0f;
+ m_ms_state.pSampleMask = nullptr;
m_ms_state.alphaToCoverageEnable = VK_FALSE;
m_ms_state.alphaToOneEnable = VK_FALSE;
- m_ms_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
- m_ms_state.minSampleShading = 0;
- m_ms_state.sampleShadingEnable = 0;
-
- m_vp_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
- m_vp_state.pNext = VK_NULL_HANDLE;
- m_vp_state.flags = 0;
- m_vp_state.viewportCount = 1;
- m_vp_state.scissorCount = 1;
- m_vp_state.pViewports = NULL;
- m_vp_state.pScissors = NULL;
m_ds_state = nullptr;
- m_te_state = nullptr;
+ memset(&m_cb_state, 0, sizeof(m_cb_state));
+ m_cb_state.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
+ m_cb_state.blendConstants[0] = 1.0f;
+ m_cb_state.blendConstants[1] = 1.0f;
+ m_cb_state.blendConstants[2] = 1.0f;
+ m_cb_state.blendConstants[3] = 1.0f;
memset(&m_pd_state, 0, sizeof(m_pd_state));
}
m_vi_state.vertexBindingDescriptionCount = count;
}
-void VkPipelineObj::AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att) {
+void VkPipelineObj::AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState &att) {
if (binding + 1 > m_colorAttachments.size()) {
m_colorAttachments.resize(binding + 1);
}
- m_colorAttachments[binding] = *att;
+ m_colorAttachments[binding] = att;
}
void VkPipelineObj::SetDepthStencil(const VkPipelineDepthStencilStateCreateInfo *ds_state) { m_ds_state = ds_state; }
bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
}
-void VkCommandBufferObj::ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color,
- VkDepthStencilObj *depthStencilObj) {
- uint32_t i;
- const VkFlags output_mask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
- VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
- const VkFlags input_mask = 0;
-
+void VkCommandBufferObj::ClearAllBuffers(const vector<VkImageObj *> &color_objs, VkClearColorValue clear_color,
+ VkDepthStencilObj *depth_stencil_obj, float depth_clear_value,
+ uint32_t stencil_clear_value) {
// whatever we want to do, we do it to the whole buffer
- VkImageSubresourceRange srRange = {};
- srRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- srRange.baseMipLevel = 0;
- srRange.levelCount = VK_REMAINING_MIP_LEVELS;
- srRange.baseArrayLayer = 0;
- srRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
-
- VkImageMemoryBarrier memory_barrier = {};
- memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
- memory_barrier.srcAccessMask = output_mask;
- memory_barrier.dstAccessMask = input_mask;
- memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
- memory_barrier.subresourceRange = srRange;
- VkImageMemoryBarrier *pmemory_barrier = &memory_barrier;
-
- VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
- VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
-
- for (i = 0; i < m_renderTargets.size(); i++) {
- memory_barrier.image = m_renderTargets[i]->image();
- memory_barrier.oldLayout = m_renderTargets[i]->Layout();
- vkCmdPipelineBarrier(handle(), src_stages, dest_stages, 0, 0, NULL, 0, NULL, 1, pmemory_barrier);
- m_renderTargets[i]->Layout(memory_barrier.newLayout);
-
- vkCmdClearColorImage(handle(), m_renderTargets[i]->image(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &srRange);
+ VkImageSubresourceRange subrange = {};
+ // srRange.aspectMask to be set later
+ subrange.baseMipLevel = 0;
+ subrange.levelCount = VK_REMAINING_MIP_LEVELS;
+ subrange.baseArrayLayer = 0;
+ subrange.layerCount = VK_REMAINING_ARRAY_LAYERS;
+
+ const VkImageLayout clear_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+
+ for (const auto &color_obj : color_objs) {
+ subrange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ color_obj->Layout(VK_IMAGE_LAYOUT_UNDEFINED);
+ color_obj->SetLayout(this, subrange.aspectMask, clear_layout);
+ ClearColorImage(color_obj->image(), clear_layout, &clear_color, 1, &subrange);
}
- if (depthStencilObj) {
- VkImageSubresourceRange dsRange = {};
- dsRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
- dsRange.baseMipLevel = 0;
- dsRange.levelCount = VK_REMAINING_MIP_LEVELS;
- dsRange.baseArrayLayer = 0;
- dsRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
-
- // prepare the depth buffer for clear
-
- memory_barrier.oldLayout = memory_barrier.newLayout;
- memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
- memory_barrier.image = depthStencilObj->handle();
- memory_barrier.subresourceRange = dsRange;
+ if (depth_stencil_obj && depth_stencil_obj->Initialized()) {
+ subrange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
+ if (FormatIsDepthOnly(depth_stencil_obj->format())) subrange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
+ if (FormatIsStencilOnly(depth_stencil_obj->format())) subrange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
- vkCmdPipelineBarrier(handle(), src_stages, dest_stages, 0, 0, NULL, 0, NULL, 1, pmemory_barrier);
+ depth_stencil_obj->Layout(VK_IMAGE_LAYOUT_UNDEFINED);
+ depth_stencil_obj->SetLayout(this, subrange.aspectMask, clear_layout);
- VkClearDepthStencilValue clear_value = {depth_clear_color, stencil_clear_color};
- vkCmdClearDepthStencilImage(handle(), depthStencilObj->handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1, &dsRange);
-
- // prepare depth buffer for rendering
- memory_barrier.image = depthStencilObj->handle();
- memory_barrier.newLayout = memory_barrier.oldLayout;
- memory_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
- memory_barrier.subresourceRange = dsRange;
- vkCmdPipelineBarrier(handle(), src_stages, dest_stages, 0, 0, NULL, 0, NULL, 1, pmemory_barrier);
+ VkClearDepthStencilValue clear_value = {depth_clear_value, stencil_clear_value};
+ ClearDepthStencilImage(depth_stencil_obj->handle(), clear_layout, &clear_value, 1, &subrange);
}
}
vkCmdClearDepthStencilImage(handle(), image, imageLayout, pColor, rangeCount, pRanges);
}
-void VkCommandBufferObj::PrepareAttachments() {
- uint32_t i;
- const VkFlags output_mask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
- VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
- const VkFlags input_mask = VK_ACCESS_HOST_READ_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT | VK_ACCESS_INDEX_READ_BIT |
- VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_UNIFORM_READ_BIT | VK_ACCESS_SHADER_READ_BIT |
- VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
- VK_ACCESS_MEMORY_READ_BIT;
-
- VkImageSubresourceRange srRange = {};
- srRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- srRange.baseMipLevel = 0;
- srRange.levelCount = VK_REMAINING_MIP_LEVELS;
- srRange.baseArrayLayer = 0;
- srRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
-
- VkImageMemoryBarrier memory_barrier = {};
- memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
- memory_barrier.srcAccessMask = output_mask;
- memory_barrier.dstAccessMask = input_mask;
- memory_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
- memory_barrier.subresourceRange = srRange;
- VkImageMemoryBarrier *pmemory_barrier = &memory_barrier;
+void VkCommandBufferObj::PrepareAttachments(const vector<VkImageObj *> &color_atts, VkDepthStencilObj *depth_stencil_att) {
+ for (const auto &color_att : color_atts) {
+ color_att->SetLayout(this, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
+ }
- VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
- VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+ if (depth_stencil_att && depth_stencil_att->Initialized()) {
+ VkImageAspectFlags aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
+ if (FormatIsDepthOnly(depth_stencil_att->Format())) aspect = VK_IMAGE_ASPECT_DEPTH_BIT;
+ if (FormatIsStencilOnly(depth_stencil_att->Format())) aspect = VK_IMAGE_ASPECT_STENCIL_BIT;
- for (i = 0; i < m_renderTargets.size(); i++) {
- memory_barrier.image = m_renderTargets[i]->image();
- memory_barrier.oldLayout = m_renderTargets[i]->Layout();
- vkCmdPipelineBarrier(handle(), src_stages, dest_stages, 0, 0, NULL, 0, NULL, 1, pmemory_barrier);
- m_renderTargets[i]->Layout(memory_barrier.newLayout);
+ depth_stencil_att->SetLayout(this, aspect, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
}
}
void VkCommandBufferObj::BindDescriptorSet(VkDescriptorSetObj &descriptorSet) {
VkDescriptorSet set_obj = descriptorSet.GetDescriptorSetHandle();
- // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer
- // view)
- vkCmdBindDescriptorSets(handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, descriptorSet.GetPipelineLayout(), 0, 1, &set_obj, 0, NULL);
+ // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view)
+ if (set_obj) {
+ vkCmdBindDescriptorSets(handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, descriptorSet.GetPipelineLayout(), 0, 1, &set_obj, 0,
+ NULL);
+ }
}
void VkCommandBufferObj::BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
VkImageView *VkDepthStencilObj::BindInfo() { return &m_attachmentBindInfo; }
+VkFormat VkDepthStencilObj::Format() const { return this->m_depth_stencil_fmt; }
+
void VkDepthStencilObj::Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format, VkImageUsageFlags usage) {
VkImageViewCreateInfo view_info = {};