1
0

Vulkan finished

Performance slightly worse than opengl; maybe perfomance tweaks can help? Or it is so ...
This commit is contained in:
Niklas Birk 2020-03-31 14:46:21 +02:00
parent c99023f81c
commit 8c77f36f6a
3 changed files with 25 additions and 17 deletions

View File

@ -366,10 +366,18 @@ void createComputePipeline(Compute *compute)
compute->dtUniformBufferDescriptorSetLayout,
compute->staticInUniformBufferDescriptorSetLayout
};
VkPushConstantRange dtPushConstantRange = {};
dtPushConstantRange.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
dtPushConstantRange.offset = 0;
dtPushConstantRange.size = sizeof(Dt);
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = {};
pipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutCreateInfo.setLayoutCount = 3;
pipelineLayoutCreateInfo.pSetLayouts = descriptorSetLayouts;
pipelineLayoutCreateInfo.pushConstantRangeCount = 1;
pipelineLayoutCreateInfo.pPushConstantRanges = &dtPushConstantRange;
ASSERT_VK(vkCreatePipelineLayout(compute->device, &pipelineLayoutCreateInfo, NULL, &(compute->pipelineLayout)))
@ -461,7 +469,7 @@ void fillComputeBuffers(Compute *compute, float *particles, Dt *dtData, StaticIn
fillComputeBuffer(compute, compute->staticInUniformBuffer, staticInData, compute->staticInUniformBufferSize);
}
void createComputeCommandBuffer(Compute *compute, Graphics *graphics)
void createComputeCommandBuffer(Compute *compute)
{
VkCommandPoolCreateInfo commandPoolCreateInfo = {};
commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
@ -488,7 +496,7 @@ void createComputeCommandBuffer(Compute *compute, Graphics *graphics)
VkDescriptorSet descriptorSets[] = {
compute->particleBufferDescriptorSet,
compute->dtUniformBufferDescriptorSet,
compute->staticInUniformBufferDescriptorSet,
compute->staticInUniformBufferDescriptorSet
};
vkCmdBindDescriptorSets(compute->commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, compute->pipelineLayout, 0, 3,
descriptorSets, 0, NULL);
@ -624,13 +632,13 @@ void createGraphicsPipeline(Graphics *graphics)
VkVertexInputAttributeDescription positionVertexInputAttributeDescription;
positionVertexInputAttributeDescription.binding = 0;
positionVertexInputAttributeDescription.location = 0;
positionVertexInputAttributeDescription.format = VK_FORMAT_R32G32_SFLOAT;
positionVertexInputAttributeDescription.format = VK_FORMAT_R32G32B32_SFLOAT;
positionVertexInputAttributeDescription.offset = 0;
VkVertexInputAttributeDescription colInVertexInputAttributeDescription;
colInVertexInputAttributeDescription.binding = 0;
colInVertexInputAttributeDescription.location = 1;
colInVertexInputAttributeDescription.format = VK_FORMAT_R32G32_SFLOAT;
colInVertexInputAttributeDescription.format = VK_FORMAT_R32G32B32_SFLOAT;
colInVertexInputAttributeDescription.offset = 24;
VkVertexInputAttributeDescription vertexInputAttributeDescription[2] = {

View File

@ -31,6 +31,17 @@
}
#define ASSERT_GLFW_SUCCESS(res) { if (res != GLFW_TRUE) { printf("Error-Code: %d", res); return FAILURE; } }
typedef struct dt {
float dt;
} Dt;
typedef struct staticIn {
float x;
float y;
float z;
unsigned int maxParticles;
} StaticIn;
typedef struct compute {
VkInstance instance;
@ -105,17 +116,6 @@ typedef struct graphics {
VkSemaphore semaphore;
} Graphics;
typedef struct dt {
float dt;
} Dt;
typedef struct staticIn {
float x;
float y;
float z;
unsigned int maxParticles;
} StaticIn;
// Shutdown
void shutdownGLFW(GLFWwindow *window);
void shutdownComputeVulkan(Compute *compute);
@ -133,7 +133,7 @@ void createComputeDescriptorSetLayouts(Compute *compute);
void createComputeDescriptorSets(Compute *compute);
void createComputePipeline(Compute *compute);
void fillComputeBuffers(Compute *compute, float *particles, Dt *dtData, StaticIn *staticInData);
void createComputeCommandBuffer(Compute *compute, Graphics *graphics);
void createComputeCommandBuffer(Compute *compute);
// Graphics
void createGraphicsSurface(Graphics *graphics, GLFWwindow *window);

View File

@ -57,7 +57,7 @@ int main()
ASSERT_VK(vkQueueSubmit(compute.queue, 1, &submitInfo, VK_NULL_HANDLE));
ASSERT_VK(vkQueueWaitIdle(compute.queue));
createComputeCommandBuffer(&compute, &graphics);
createComputeCommandBuffer(&compute);
// Graphics
graphics.particleBuffer = compute.particleBuffer;