first commit
This commit is contained in:
125
rendering_api/vulkan/src/commands/vulkan_command.cpp
Normal file
125
rendering_api/vulkan/src/commands/vulkan_command.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "gryphn/gryphn_utils.h"
|
||||
#include "core/commands/gryphn_command.h"
|
||||
#include "vulkan_command_buffer.h"
|
||||
#include "../graphics_pipeline/vulkan_renderpass.h"
|
||||
#include "../graphics_pipeline/vulkan_graphics_pipeline.h"
|
||||
#include "../vertex_buffers/vulkan_buffers.h"
|
||||
#include "../push_constant/vulkan_push_constant.h"
|
||||
#include "core/shaders/gryphn_shader_module.h"
|
||||
#include "core/uniform_descriptor/uniform_buffer/gryphn_uniform_buffer.h"
|
||||
#include "../uniform_descriptor/vulkan_uniform.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include "../framebuffers/vulkan_framebuffer.h"
|
||||
#include <array>
|
||||
|
||||
GN_EXPORT gnReturnCode gnCommandBufferStartFn(const gnCommandBuffer& commandBuffer) {
|
||||
VkCommandBufferBeginInfo beginInfo{};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
beginInfo.flags = 0; // Optional
|
||||
beginInfo.pInheritanceInfo = nullptr; // Optional
|
||||
|
||||
if (vkBeginCommandBuffer(commandBuffer.commandBuffer->commandBuffer, &beginInfo) != VK_SUCCESS) {
|
||||
return GN_FAILED;
|
||||
}
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
GN_EXPORT void gnCommandBeginRenderPassFn(gnCommandBuffer& commandBuffer, const gnRenderPassFrame& frame) {
|
||||
gnRenderPassFrame* frameptr = const_cast<gnRenderPassFrame*>(&frame);
|
||||
if (frame.renderPassFrame == nullptr) frameptr->renderPassFrame = new gnPlatformRenderPassFrame();
|
||||
frameptr->renderPassFrame->renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
frameptr->renderPassFrame->renderPassInfo.renderPass = frameptr->renderPass->renderpass->renderPass;
|
||||
frameptr->renderPassFrame->renderPassInfo.framebuffer = frameptr->framebuffer->framebuffer->framebuffer;
|
||||
frameptr->renderPassFrame->renderPassInfo.renderArea.offset = { (int)frameptr->offset.x, (int)frameptr->offset.y };
|
||||
frameptr->renderPassFrame->renderPassInfo.renderArea.extent = { frameptr->area.x, frameptr->area.y };
|
||||
|
||||
std::array<VkClearValue, 2> clearValues{};
|
||||
clearValues[0].color = {{frame.clearColor.r / 255.0f, frame.clearColor.g / 255.0f, frame.clearColor.b / 255.0f, frame.clearColor.a}};
|
||||
clearValues[1].depthStencil = {1.0f, 0};
|
||||
frame.renderPassFrame->renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
|
||||
frame.renderPassFrame->renderPassInfo.pClearValues = clearValues.data();
|
||||
|
||||
vkCmdBeginRenderPass(commandBuffer.commandBuffer->commandBuffer, &frame.renderPassFrame->renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
}
|
||||
|
||||
GN_EXPORT void gnCommandSetGraphicsPipelineFn(const gnCommandBuffer& commandBuffer, const gnGraphicsPipeline& graphicsPipeline) {
|
||||
vkCmdBindPipeline(commandBuffer.commandBuffer->commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline.graphicsPipeline->graphicsPipeline);
|
||||
}
|
||||
|
||||
GN_EXPORT void gnCommandSetViewportFn(const gnCommandBuffer& commandBuffer, gnViewportDescriptionData data) {
|
||||
commandBuffer.commandBuffer->viewport.x = data.offset.x;
|
||||
commandBuffer.commandBuffer->viewport.y = data.offset.y;
|
||||
commandBuffer.commandBuffer->viewport.width = data.size.x;
|
||||
commandBuffer.commandBuffer->viewport.height = data.size.y;
|
||||
commandBuffer.commandBuffer->viewport.minDepth = data.depth.a;
|
||||
commandBuffer.commandBuffer->viewport.maxDepth = data.depth.b;
|
||||
|
||||
vkCmdSetViewport(commandBuffer.commandBuffer->commandBuffer, 0, 1, &commandBuffer.commandBuffer->viewport);
|
||||
}
|
||||
GN_EXPORT void gnCommandSetScissorFn(const gnCommandBuffer& commandBuffer, gnScissorDescriptionData data) {
|
||||
commandBuffer.commandBuffer->scissor.offset = {(int)data.offset.x, (int)data.offset.y};
|
||||
commandBuffer.commandBuffer->scissor.extent = { data.extent.x, data.extent.y };
|
||||
vkCmdSetScissor(commandBuffer.commandBuffer->commandBuffer, 0, 1, &commandBuffer.commandBuffer->scissor);
|
||||
}
|
||||
GN_EXPORT void gnCommandBindBufferFn(const gnCommandBuffer& commandBuffer, const gnBuffer& buffer) {
|
||||
if (buffer.bufferType == GN_VERTEX_BUFFER) {
|
||||
VkBuffer vertexBuffers[] = {buffer.buffer->buffer};
|
||||
VkDeviceSize offsets[] = {0};
|
||||
vkCmdBindVertexBuffers(commandBuffer.commandBuffer->commandBuffer, 0, 1, vertexBuffers, offsets);
|
||||
} else {
|
||||
VkIndexType type;
|
||||
if (buffer.dataType == GN_UINT8) { /* TODO: switch to vulkan 1.4 */ }
|
||||
if (buffer.dataType == GN_UINT16) { type = VK_INDEX_TYPE_UINT16; /* TODO: switch to vulkan 1.4 */ }
|
||||
if (buffer.dataType == GN_UINT32) { type = VK_INDEX_TYPE_UINT32; /* TODO: switch to vulkan 1.4 */ }
|
||||
|
||||
vkCmdBindIndexBuffer(commandBuffer.commandBuffer->commandBuffer, buffer.buffer->buffer, 0, type);
|
||||
}
|
||||
}
|
||||
|
||||
GN_EXPORT void gnCommandDrawFn(const gnCommandBuffer& commandBuffer, int vertexCount, int instanceCount, int firstVertex, int firstInstance) {
|
||||
vkCmdDraw(commandBuffer.commandBuffer->commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
}
|
||||
GN_EXPORT void gnCommandDrawIndexedFn(const gnCommandBuffer& commandBuffer, gnUInt indexCount, gnUInt instanceCount, gnUInt firstIndex, gnInt vertexOffset, gnUInt firstInstance) {
|
||||
vkCmdDrawIndexed(commandBuffer.commandBuffer->commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
|
||||
}
|
||||
GN_EXPORT void gnCommandBindBufferUniformFn(const gnCommandBuffer& commandBuffer, gnGraphicsPipeline& graphicsPipeline, gnBufferUniform& uniformBuffer, gnInt set) {
|
||||
vkCmdBindDescriptorSets(
|
||||
commandBuffer.commandBuffer->commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
graphicsPipeline.graphicsPipeline->pipelineLayout, set, 1,
|
||||
&uniformBuffer.uniform->uniform->descriptorSets[uniformBuffer.index], 0, nullptr
|
||||
);
|
||||
}
|
||||
GN_EXPORT void gnCommandBindSamplerUniformFn(const gnCommandBuffer& commandBuffer, const gnGraphicsPipeline& graphicsPipeline, const gnSamplerUniform& sampler, gnInt set) {
|
||||
vkCmdBindDescriptorSets(
|
||||
commandBuffer.commandBuffer->commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
graphicsPipeline.graphicsPipeline->pipelineLayout, set, 1,
|
||||
&sampler.uniform->uniform->descriptorSets[sampler.index], 0, nullptr
|
||||
);
|
||||
}
|
||||
GN_EXPORT void gnCommandPushConstantFn(gnCommandBuffer& commandBuffer, const gnGraphicsPipeline& graphicsPipeline, const gnPushConstant& pushConstant, void* data) {
|
||||
int stageBit = 0;
|
||||
|
||||
if (gnContainsShaderStage(pushConstant.stage, GN_VERTEX_SHADER_MODULE)) stageBit |= VK_SHADER_STAGE_VERTEX_BIT;
|
||||
if (gnContainsShaderStage(pushConstant.stage, GN_FRAGMENT_SHADER_MODULE)) stageBit |= VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
vkCmdPushConstants(commandBuffer.commandBuffer->commandBuffer,
|
||||
graphicsPipeline.graphicsPipeline->pipelineLayout,
|
||||
stageBit, pushConstant.offset, pushConstant.size, data);
|
||||
}
|
||||
GN_EXPORT void gnCommandEndRenderPassFn(const gnCommandBuffer& commandBuffer) {
|
||||
vkCmdEndRenderPass(commandBuffer.commandBuffer->commandBuffer);
|
||||
}
|
||||
void gnCommandBindShader(const gnCommandBuffer& commandBuffer, const gnShader& shader) {
|
||||
// vkCmdBindShadersEXT(
|
||||
// commandBuffer.commandBuffer->commandBuffer,
|
||||
// 2,
|
||||
// VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
// const VkShaderEXT* pShaders);
|
||||
}
|
||||
GN_EXPORT gnReturnCode gnCommandBufferEndFn(const gnCommandBuffer& commandBuffer) {
|
||||
if (vkEndCommandBuffer(commandBuffer.commandBuffer->commandBuffer) != VK_SUCCESS) {
|
||||
return GN_FAILED;
|
||||
}
|
||||
return GN_SUCCESS;
|
||||
}
|
143
rendering_api/vulkan/src/commands/vulkan_command_buffer.cpp
Normal file
143
rendering_api/vulkan/src/commands/vulkan_command_buffer.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
#include "gryphn/gryphn_utils.h"
|
||||
#include "core/commands/gryphn_command_buffer.h"
|
||||
#include "../graphics_pipeline/vulkan_renderpass.h"
|
||||
#include "../presentation_queue/vulkan_queue_families.h"
|
||||
#include "../instance/vulkan_instance.h"
|
||||
#include "vulkan_command_buffer.h"
|
||||
#include "../graphics_pipeline/vulkan_graphics_pipeline.h"
|
||||
|
||||
VkCommandBuffer beginSingleTimeCommands(const gnOutputDevice& outputDevice) {
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandPool = outputDevice.outputDevice->commandPool;
|
||||
allocInfo.commandBufferCount = 1;
|
||||
|
||||
VkCommandBuffer commandBuffer;
|
||||
vkAllocateCommandBuffers(outputDevice.outputDevice->device, &allocInfo, &commandBuffer);
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo{};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
|
||||
vkBeginCommandBuffer(commandBuffer, &beginInfo);
|
||||
|
||||
return commandBuffer;
|
||||
}
|
||||
|
||||
|
||||
void endSingleTimeCommands(VkCommandBuffer commandBuffer, const gnOutputDevice& outputDevice) {
|
||||
vkEndCommandBuffer(commandBuffer);
|
||||
|
||||
VkSubmitInfo submitInfo{};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &commandBuffer;
|
||||
|
||||
vkQueueSubmit(outputDevice.outputDevice->graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
vkQueueWaitIdle(outputDevice.outputDevice->graphicsQueue);
|
||||
|
||||
vkFreeCommandBuffers(outputDevice.outputDevice->device, outputDevice.outputDevice->commandPool, 1, &commandBuffer);
|
||||
}
|
||||
|
||||
// GN_EXPORT gnReturnCode _gnCreateCommandBuffersFn(gnList<gnCommandBuffer> *commandBuffers, const gnGraphicsPipeline& pipeline) {
|
||||
// std::vector<VkCommandBuffer> commandBufferList;
|
||||
// for (int i = 0; i < gnListLength(*commandBuffers); i++) {
|
||||
// if ((*commandBuffers)[i].commandBuffer == nullptr) (*commandBuffers)[i].commandBuffer = new gnPlatformCommandBuffer();
|
||||
|
||||
// (*commandBuffers)[i].commandBuffer->outputDevice = pipeline.renderPass->renderpass->outputDevice;
|
||||
// commandBufferList.push_back((*commandBuffers)[i].commandBuffer->commandBuffer);
|
||||
// }
|
||||
|
||||
// VkCommandBufferAllocateInfo allocInfo{};
|
||||
// allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
// allocInfo.commandPool = *pipeline.graphicsPipeline->commandPool;
|
||||
// allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
// allocInfo.commandBufferCount = (uint32_t) gnListLength(*commandBuffers);
|
||||
|
||||
// if (vkAllocateCommandBuffers(pipeline.renderPass->renderpass->outputDevice->outputDevice->device, &allocInfo, commandBufferList.data()) != VK_SUCCESS) {
|
||||
// return GN_FAILED;
|
||||
// }
|
||||
|
||||
// for (int i = 0; i < gnListLength(*commandBuffers); i++) {
|
||||
// (*commandBuffers)[i].commandBuffer->commandBuffer = commandBufferList[i];
|
||||
// }
|
||||
|
||||
// return GN_SUCCESS;
|
||||
// }
|
||||
|
||||
// GN_EXPORT gnReturnCode _gnCreateCommandBuffersFn(std::vector<gnCommandBuffer>* commandBuffers, const gnGraphicsPipeline &pipeline) {
|
||||
// std::vector<VkCommandBuffer> commandBufferList;
|
||||
// for (int i = 0; i < commandBuffers->size(); i++) {
|
||||
// (*commandBuffers)[i].commandBuffer->outputDevice = pipeline.renderPass->renderpass->outputDevice;
|
||||
// commandBufferList.push_back((*commandBuffers)[i].commandBuffer->commandBuffer);
|
||||
// }
|
||||
|
||||
// VkCommandBufferAllocateInfo allocInfo{};
|
||||
// allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
// allocInfo.commandPool = *pipeline.graphicsPipeline->commandPool;
|
||||
// allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
// allocInfo.commandBufferCount = (uint32_t) commandBuffers->size();
|
||||
|
||||
// if (vkAllocateCommandBuffers(pipeline.renderPass->renderpass->outputDevice->outputDevice->device, &allocInfo, commandBufferList.data()) != VK_SUCCESS) {
|
||||
// return GN_FAILED;
|
||||
// }
|
||||
|
||||
// for (int i = 0; i < commandBuffers->size(); i++) {
|
||||
// (*commandBuffers)[i].commandBuffer->commandBuffer = commandBufferList[i];
|
||||
// }
|
||||
|
||||
// return GN_SUCCESS;
|
||||
// }
|
||||
|
||||
GN_EXPORT gnReturnCode _gnCreateCommandBuffersFn(gnCommandBuffer* commandBuffers, gnUInt commandBufferCount, const gnOutputDevice& outputDevice) {
|
||||
std::vector<VkCommandBuffer> commandBufferList;
|
||||
for (int i = 0; i < commandBufferCount; i++) {
|
||||
commandBuffers[i].commandBuffer = new gnPlatformCommandBuffer();
|
||||
commandBuffers[i].commandBuffer->outputDevice = const_cast<gnOutputDevice*>(&outputDevice);
|
||||
commandBufferList.push_back(commandBuffers[i].commandBuffer->commandBuffer);
|
||||
}
|
||||
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.commandPool = outputDevice.outputDevice->commandPool;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandBufferCount = (uint32_t) commandBufferCount;
|
||||
|
||||
if (vkAllocateCommandBuffers(outputDevice.outputDevice->device, &allocInfo, commandBufferList.data()) != VK_SUCCESS) {
|
||||
return GN_FAILED;
|
||||
}
|
||||
|
||||
for (int i = 0; i < commandBufferCount; i++) {
|
||||
commandBuffers[i].commandBuffer->commandBuffer = commandBufferList[i];
|
||||
}
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
GN_EXPORT gnReturnCode gnCreateCommandBufferFn(gnCommandBuffer* commandBuffer, const gnOutputDevice& device) {
|
||||
commandBuffer->commandBuffer->outputDevice = const_cast<gnOutputDevice*>(&device);
|
||||
|
||||
{ // create the command buffer
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.commandPool = device.outputDevice->commandPool;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandBufferCount = 1;
|
||||
|
||||
if (vkAllocateCommandBuffers(device.outputDevice->device, &allocInfo, &commandBuffer->commandBuffer->commandBuffer) != VK_SUCCESS) {
|
||||
return GN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
GN_EXPORT void gnCommandBufferResetFn(const gnCommandBuffer& commandBuffer) {
|
||||
vkResetCommandBuffer(commandBuffer.commandBuffer->commandBuffer, 0);
|
||||
}
|
||||
|
||||
GN_EXPORT void gnDestroyCommandBufferFn(const gnCommandBuffer& commandBuffer) {
|
||||
// do nothing this function is archaic
|
||||
}
|
15
rendering_api/vulkan/src/commands/vulkan_command_buffer.h
Normal file
15
rendering_api/vulkan/src/commands/vulkan_command_buffer.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "core/graphics_pipeline/gryphn_graphics_pipeline.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
struct gnPlatformCommandBuffer {
|
||||
VkCommandBuffer commandBuffer;
|
||||
|
||||
gnOutputDevice* outputDevice;
|
||||
|
||||
VkViewport viewport{};
|
||||
VkRect2D scissor{};
|
||||
};
|
||||
|
||||
VkCommandBuffer beginSingleTimeCommands(const gnOutputDevice& outputDevice);
|
||||
void endSingleTimeCommands(VkCommandBuffer commandBuffer, const gnOutputDevice& outputDevice);
|
55
rendering_api/vulkan/src/commands/vulkan_command_present.cpp
Normal file
55
rendering_api/vulkan/src/commands/vulkan_command_present.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "core/commands/present_command/gryphn_command_present.h"
|
||||
#include "../presentation_queue/vulkan_presentation_queue.h"
|
||||
#include "../sync_objects/vulkan_sync_semaphore.h"
|
||||
#include "../output_device/vulkan_output_devices.h"
|
||||
|
||||
struct gnPlatformCommandPresentData {
|
||||
VkPresentInfoKHR presentInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR
|
||||
};
|
||||
gnPresentationQueue* presentationQueue;
|
||||
VkResult result;
|
||||
};
|
||||
|
||||
void gnCommandPresentDataSetSignalSemaphoreFn(gnCommandPresentData& presentCommandData, const gnSyncSemaphore& semaphore) {
|
||||
presentCommandData.commandPresentData->presentInfo.waitSemaphoreCount = 1;
|
||||
presentCommandData.commandPresentData->presentInfo.pWaitSemaphores = &semaphore.semaphore->semaphore;
|
||||
}
|
||||
void gnCommandPresentDataSetPresentationQueueFn(gnCommandPresentData& presentCommandData, const gnPresentationQueue& presentationQueue) {
|
||||
presentCommandData.commandPresentData->presentInfo.swapchainCount = 1;
|
||||
presentCommandData.commandPresentData->presentInfo.pSwapchains = &presentationQueue.presentationQueue->swapChain;
|
||||
|
||||
presentCommandData.commandPresentData->presentationQueue = const_cast<gnPresentationQueue*>(&presentationQueue);
|
||||
}
|
||||
|
||||
void gnCommandPresentDataSetImageIndexFn(gnCommandPresentData& presentCommandData, gnUInt* imageIndex) {
|
||||
presentCommandData.commandPresentData->presentInfo.pImageIndices = imageIndex;
|
||||
}
|
||||
GN_EXPORT gnPresentationQueueState gnCommandPresentGetValidPresentationQueueFn(gnCommandPresentData& presentCommandData) {
|
||||
if (presentCommandData.commandPresentData->result == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
return GN_OUT_OF_DATE;
|
||||
} else if (presentCommandData.commandPresentData->result == VK_SUBOPTIMAL_KHR) {
|
||||
return GN_SUBOPTIMAL;
|
||||
}
|
||||
else if (presentCommandData.commandPresentData->result == VK_SUCCESS) {
|
||||
return GN_VALID;
|
||||
}
|
||||
return GN_VALID;
|
||||
}
|
||||
GN_EXPORT gnReturnCode gnCommandPresentFn(gnCommandPresentData& presentCommandData) {
|
||||
if (presentCommandData.commandPresentData == nullptr) presentCommandData.commandPresentData = new gnPlatformCommandPresentData();
|
||||
|
||||
gnCommandPresentDataSetSignalSemaphoreFn(presentCommandData, *presentCommandData.semaphore);
|
||||
gnCommandPresentDataSetPresentationQueueFn(presentCommandData, *presentCommandData.presentationQueue);
|
||||
gnCommandPresentDataSetImageIndexFn(presentCommandData, presentCommandData.imageIndex);
|
||||
|
||||
uint32_t imageIndex = *presentCommandData.imageIndex;
|
||||
presentCommandData.commandPresentData->presentInfo.pImageIndices = &imageIndex;
|
||||
|
||||
presentCommandData.commandPresentData->result =
|
||||
vkQueuePresentKHR(presentCommandData.commandPresentData->presentationQueue->presentationQueue->outputDevice->outputDevice->presentQueue, &presentCommandData.commandPresentData->presentInfo);
|
||||
if (presentCommandData.commandPresentData->result != VK_SUCCESS) {
|
||||
return GN_FAILED;
|
||||
}
|
||||
return GN_SUCCESS;
|
||||
}
|
56
rendering_api/vulkan/src/commands/vulkan_command_submit.cpp
Normal file
56
rendering_api/vulkan/src/commands/vulkan_command_submit.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <gryphn/gryphn_utils.h>
|
||||
#include "core/commands/submit_command/gryphn_command_submit.h"
|
||||
#include "../sync_objects/vulkan_sync_semaphore.h"
|
||||
#include "vulkan_command_buffer.h"
|
||||
#include "../sync_objects/vulkan_fence.h"
|
||||
|
||||
struct gnPlatformCommandSubmitData {
|
||||
VkSubmitInfo submitInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO
|
||||
};
|
||||
VkResult result;
|
||||
};
|
||||
|
||||
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
|
||||
|
||||
void gnCommandSubmitDataSetWaitSemaphoreFn(gnCommandSubmitData& data, const gnSyncSemaphore& semaphore) {
|
||||
data.commandSubmitData->submitInfo.waitSemaphoreCount = 1;
|
||||
data.commandSubmitData->submitInfo.pWaitSemaphores = &semaphore.semaphore->semaphore;
|
||||
data.commandSubmitData->submitInfo.pWaitDstStageMask = waitStages;
|
||||
}
|
||||
|
||||
void gnCommandSubmitDataSetCommandBufferFn(gnCommandSubmitData& data, const gnCommandBuffer& commandBuffer) {
|
||||
data.commandSubmitData->submitInfo.commandBufferCount = 1;
|
||||
data.commandSubmitData->submitInfo.pCommandBuffers = &commandBuffer.commandBuffer->commandBuffer;
|
||||
}
|
||||
|
||||
void gnCommandSubmitDataSetSignalSemaphoreFn(gnCommandSubmitData& data, const gnSyncSemaphore& semaphore) {
|
||||
data.commandSubmitData->submitInfo.signalSemaphoreCount = 1;
|
||||
data.commandSubmitData->submitInfo.pSignalSemaphores = &semaphore.semaphore->semaphore;
|
||||
}
|
||||
GN_EXPORT gnPresentationQueueState gnCommandSubmitGetValidPresentationQueueFn(gnCommandSubmitData& data) {
|
||||
if (data.commandSubmitData->result == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
return GN_OUT_OF_DATE;
|
||||
} else if (data.commandSubmitData->result == VK_SUBOPTIMAL_KHR) {
|
||||
return GN_SUBOPTIMAL;
|
||||
}
|
||||
else if (data.commandSubmitData->result == VK_SUCCESS) {
|
||||
return GN_VALID;
|
||||
}
|
||||
return GN_VALID;
|
||||
}
|
||||
GN_EXPORT gnReturnCode gnCommandSubmitFn(gnCommandSubmitData& data, const gnFence& fence) {
|
||||
if (data.commandSubmitData == nullptr) data.commandSubmitData = new gnPlatformCommandSubmitData();
|
||||
|
||||
gnCommandSubmitDataSetWaitSemaphoreFn(data, *data.waitSemaphore);
|
||||
gnCommandSubmitDataSetCommandBufferFn(data, *data.commandBuffer);
|
||||
gnCommandSubmitDataSetSignalSemaphoreFn(data, *data.signalSemaphore);
|
||||
|
||||
data.commandSubmitData->result = vkQueueSubmit(fence.fence->device->outputDevice->graphicsQueue, 1, &data.commandSubmitData->submitInfo, fence.fence->fence);
|
||||
|
||||
if (data.commandSubmitData->result != VK_SUCCESS) {
|
||||
return GN_FAILED;
|
||||
}
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user