20 vkDestroyShaderModule(
ctx->deviceHandle(), shderModule,
nullptr);
22 vkDestroyPipeline(
ctx->deviceHandle(),
pipeline,
nullptr);
30 std::vector<VkDescriptorPoolSize> poolSizes = {
36 VkDescriptorPoolCreateInfo descriptorPoolInfo =
45 std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
48 VkDescriptorSetLayoutCreateInfo descriptorLayout =
52 VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
57 VkDescriptorSetAllocateInfo allocInfo =
61 std::vector<VkWriteDescriptorSet> writeDescriptorSets = {
64 vkUpdateDescriptorSets(
ctx->deviceHandle(),
static_cast<uint32_t
>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
69 VkPipelineInputAssemblyStateCreateInfo inputAssemblyState =
72 VkPipelineRasterizationStateCreateInfo rasterizationState =
75 VkPipelineColorBlendAttachmentState blendAttachmentState =
78 VkPipelineColorBlendStateCreateInfo colorBlendState =
81 VkPipelineDepthStencilStateCreateInfo depthStencilState =
84 VkPipelineViewportStateCreateInfo viewportState =
87 VkPipelineMultisampleStateCreateInfo multisampleState =
90 std::vector<VkDynamicState> dynamicStateEnables = {
91 VK_DYNAMIC_STATE_VIEWPORT,
92 VK_DYNAMIC_STATE_SCISSOR
94 VkPipelineDynamicStateCreateInfo dynamicState =
98 std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
108 std::vector<VkVertexInputBindingDescription> inputBindings = {
113 std::vector<VkVertexInputAttributeDescription> inputAttributes = {
121 inputState.vertexBindingDescriptionCount =
static_cast<uint32_t
>(inputBindings.size());
122 inputState.pVertexBindingDescriptions = inputBindings.data();
123 inputState.vertexAttributeDescriptionCount =
static_cast<uint32_t
>(inputAttributes.size());
124 inputState.pVertexAttributeDescriptions = inputAttributes.data();
126 pipelineCreateInfo.pVertexInputState = &inputState;
127 pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
128 pipelineCreateInfo.pRasterizationState = &rasterizationState;
129 pipelineCreateInfo.pColorBlendState = &colorBlendState;
130 pipelineCreateInfo.pMultisampleState = &multisampleState;
131 pipelineCreateInfo.pViewportState = &viewportState;
132 pipelineCreateInfo.pDepthStencilState = &depthStencilState;
133 pipelineCreateInfo.pDynamicState = &dynamicState;
134 pipelineCreateInfo.stageCount =
static_cast<uint32_t
>(shaderStages.size());
135 pipelineCreateInfo.pStages = shaderStages.data();
136 pipelineCreateInfo.renderPass = renderPass;
144 bufferBarrier.srcAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
145 bufferBarrier.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
146 bufferBarrier.srcQueueFamilyIndex =
ctx->queueFamilyIndices.graphics;
147 bufferBarrier.dstQueueFamilyIndex =
ctx->queueFamilyIndices.compute;
148 bufferBarrier.size = VK_WHOLE_SIZE;
150 std::vector<VkBufferMemoryBarrier> bufferBarriers;
151 bufferBarrier.buffer =
mVertex.bufferHandle();
152 bufferBarriers.push_back(bufferBarrier);
153 vkCmdPipelineBarrier(commandBuffer,
154 VK_PIPELINE_STAGE_VERTEX_INPUT_BIT,
155 VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
158 static_cast<uint32_t
>(bufferBarriers.size()), bufferBarriers.data(),
167 bufferBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
168 bufferBarrier.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
169 bufferBarrier.srcQueueFamilyIndex =
ctx->queueFamilyIndices.compute;
170 bufferBarrier.dstQueueFamilyIndex =
ctx->queueFamilyIndices.graphics;
171 bufferBarrier.size = VK_WHOLE_SIZE;
172 std::vector<VkBufferMemoryBarrier> bufferBarriers;
173 bufferBarrier.buffer =
mVertex.bufferHandle();
174 bufferBarriers.push_back(bufferBarrier);
175 vkCmdPipelineBarrier(
177 VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
178 VK_PIPELINE_STAGE_VERTEX_INPUT_BIT,
181 static_cast<uint32_t
>(bufferBarriers.size()), bufferBarriers.data(),
191 VkDeviceSize offsets[1] = { 0 };
196 VkBuffer dataBuffer =
mVertex.bufferHandle();
198 vkCmdBindPipeline(drawCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
pipeline);
200 vkCmdBindIndexBuffer(drawCmdBuffer,
mIndex.bufferHandle(), 0, VK_INDEX_TYPE_UINT32);
201 vkCmdBindVertexBuffers(drawCmdBuffer, 0, 1, &dataBuffer, offsets);
202 vkCmdDrawIndexed(drawCmdBuffer,
mIndex.size(), 1, 0, 0, 0);
211 return getAssetPath() +
"shaders/" +
shaderDir +
"/";
216 VkPipelineShaderStageCreateInfo shaderStage = {};
217 shaderStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
218 shaderStage.stage = stage;
220 shaderStage.pName =
"main";
221 assert(shaderStage.module != VK_NULL_HANDLE);
227 auto triSet = std::dynamic_pointer_cast<TriangleSet>(this->inTopology()->getDataPtr());
228 if (triSet ==
nullptr)
231 this->
mIndex.resize(triSet->mIndex.size());
234 this->
mVertex.resize(3 * triSet->mTriangleIndex.size(), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
235 this->
mIndex.resize(3 * triSet->mTriangleIndex.size());
238 program->load(getAssetPath() +
"shaders/glsl/graphics/SetupVertexFromPoints.comp.spv");
243 program->enqueue(groupSize, &this->
mVertex, &this->
mIndex, triSet->mPoints.handle(), triSet->mIndex.handle(), &this->particleNumber);
253 auto triSet = std::dynamic_pointer_cast<TriangleSet>(this->inTopology()->getDataPtr());
254 assert(triSet !=
nullptr);
void setupDescriptorPool()
void updateGraphicsContext() override
void addComputeToGraphicsBarriers(VkCommandBuffer commandBuffer)
VkConstant< uint32_t > particleNumber
VkPipelineShaderStageCreateInfo loadShader(std::string fileName, VkShaderStageFlagBits stage)
VkUniform< GraphicsUBO > mUniform
void buildCommandBuffers(VkCommandBuffer drawCmdBuffer) override
std::string getShadersPath() const
bool initializeImpl() override
VkPipelineLayout pipelineLayout
void setupLayoutsAndDescriptors()
void preparePipelines(VkRenderPass renderPass)
VkDescriptorSet descriptorSet
VkDeviceArray< Vertex > mVertex
VkDescriptorSetLayout descriptorSetLayout
bool specializedComputeQueue
std::vector< VkShaderModule > shaderModules
std::shared_ptr< VkProgram > program
void addGraphicsToComputeBarriers(VkCommandBuffer commandBuffer)
VkDeviceArray< uint32_t > mIndex
VkDescriptorPool descriptorPool
VkContext * currentContext()
static VkSystem * instance()
This is an implementation of AdditiveCCD based on peridyno.
static dim3 vkDispatchSize(uint totalSize, uint blockSize)
bool vkTransfer(VkHostArray< T > &dst, const VkDeviceArray< T > &src)
VkVertexInputAttributeDescription vertexInputAttributeDescription(uint32_t binding, uint32_t location, VkFormat format, uint32_t offset)
VkDescriptorSetLayoutBinding descriptorSetLayoutBinding(VkDescriptorType type, VkShaderStageFlags stageFlags, uint32_t binding, uint32_t descriptorCount=1)
VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(uint32_t attachmentCount, const VkPipelineColorBlendAttachmentState *pAttachments)
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo(const VkDescriptorSetLayoutBinding *pBindings, uint32_t bindingCount)
VkPipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(uint32_t viewportCount, uint32_t scissorCount, VkPipelineViewportStateCreateFlags flags=0)
VkDescriptorPoolSize descriptorPoolSize(VkDescriptorType type, uint32_t descriptorCount)
VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(VkPolygonMode polygonMode, VkCullModeFlags cullMode, VkFrontFace frontFace, VkPipelineRasterizationStateCreateFlags flags=0)
VkDescriptorPoolCreateInfo descriptorPoolCreateInfo(uint32_t poolSizeCount, VkDescriptorPoolSize *pPoolSizes, uint32_t maxSets)
VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(const VkDynamicState *pDynamicStates, uint32_t dynamicStateCount, VkPipelineDynamicStateCreateFlags flags=0)
VkVertexInputBindingDescription vertexInputBindingDescription(uint32_t binding, uint32_t stride, VkVertexInputRate inputRate)
VkWriteDescriptorSet writeDescriptorSet(VkDescriptorSet dstSet, VkDescriptorType type, uint32_t binding, VkDescriptorBufferInfo *bufferInfo, uint32_t descriptorCount=1)
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo(const VkDescriptorSetLayout *pSetLayouts, uint32_t setLayoutCount=1)
VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(VkColorComponentFlags colorWriteMask, VkBool32 blendEnable)
VkGraphicsPipelineCreateInfo pipelineCreateInfo()
VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo(VkSampleCountFlagBits rasterizationSamples, VkPipelineMultisampleStateCreateFlags flags=0)
VkDescriptorSetAllocateInfo descriptorSetAllocateInfo(VkDescriptorPool descriptorPool, const VkDescriptorSetLayout *pSetLayouts, uint32_t descriptorSetCount)
VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(VkBool32 depthTestEnable, VkBool32 depthWriteEnable, VkCompareOp depthCompareOp)
VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology topology, VkPipelineInputAssemblyStateCreateFlags flags, VkBool32 primitiveRestartEnable)
VkPipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo()
VkBufferMemoryBarrier bufferMemoryBarrier()
Initialize a buffer memory barrier with no image transfer ownership.