-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge the current vulkan-dev to the master #119
Conversation
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
In some cases the default 16 ms timeout value wasn't enough. Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Updated the shader generator. Implemented simple shader for images. Applied minor refactoring to the vulkan backend. Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
cmake/Dependencies.cmake
Outdated
add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/engines/vulkan/shaders/gepard-vulkan-spirv-binaries.h | ||
${PROJECT_SOURCE_DIR}/src/engines/vulkan/shaders/gepard-vulkan-spirv-binaries.inc.h | ||
COMMAND python ${PROJECT_SOURCE_DIR}/tools/build-vulkan-shaders.py | ||
DEPENDS ${PROJECT_SOURCE_DIR}/src/engines/vulkan/shaders/*.vert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these dependencies are needed. The shaders are part of the source tree, they are not generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are needed to trigger the custom command, otherwise once the generated files are created it won't run again if the shaders are changed or new shader is created.
cmake/Dependencies.cmake
Outdated
@@ -27,6 +27,15 @@ elseif (BACKEND STREQUAL "VULKAN") | |||
|
|||
set(VULKAN_INCLUDE_DIR ${PROJECT_BINARY_DIR}/thirdparty/include) | |||
endif() | |||
add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/engines/vulkan/shaders/gepard-vulkan-spirv-binaries.h | |||
${PROJECT_SOURCE_DIR}/src/engines/vulkan/shaders/gepard-vulkan-spirv-binaries.inc.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These generated files should be added to gitignore to prevent them from accidentally getting committed. As a matter of fact, it would be best if these would be in the build directory, so they don't mess up the source tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on adding these to gitignore, but I'm not sure how to make the IDE happy and have working code completion for the shader variables.
src/engines/vulkan/gepard-vulkan.cpp
Outdated
_vk.vkCreateFence(_device, &fenceInfo, _allocator, &fence); | ||
_vk.vkQueueSubmit(queue, 1, &submitInfo, fence); | ||
_vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | ||
vkResult = _vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | ||
if (vkResult == VK_TIMEOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use braces here.
src/engines/vulkan/gepard-vulkan.cpp
Outdated
GD_ASSERT(vkResult == VK_SUCCESS && "Queue submit failed!"); | ||
|
||
vkResult = _vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | ||
if (vkResult == VK_TIMEOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use braces here.
src/engines/vulkan/gepard-vulkan.cpp
Outdated
@@ -877,39 +1134,17 @@ void GepardVulkan::createSurfaceImage() | |||
VkFence fence; | |||
_vk.vkCreateFence(_device, &fenceInfo, _allocator, &fence); | |||
_vk.vkQueueSubmit(queue, 1, &submitInfo, fence); | |||
_vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | |||
vkResult = _vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | |||
if (vkResult == VK_TIMEOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use braces here.
src/engines/vulkan/gepard-vulkan.cpp
Outdated
_vk.vkQueueSubmit(queue, 1, &submitInfo, fence); | ||
_vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | ||
vkResult = _vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | ||
if (vkResult == VK_TIMEOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
braces :)
&_queueFamilyIndex, // const uint32_t* pQueueFamilyIndices; | ||
}; | ||
|
||
vkResult = _vk.vkCreateBuffer(_device, &bufferInfo, _allocator, &buffer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VkResult vkResult = ...
:)
}, // VkImageSubresourceRange subresourceRange; | ||
}; | ||
|
||
vkResult = _vk.vkCreateImageView(_device, &imageViewCreateInfo, _allocator, &imageView); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VkResult...
src/engines/vulkan/gepard-vulkan.cpp
Outdated
_vk.vkCreateFence(_device, &fenceInfo, _allocator, &fence); | ||
_vk.vkQueueSubmit(queue, 1, &submitInfo, fence); | ||
vkResult = _vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout); | ||
if (vkResult == VK_TIMEOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}
src/engines/vulkan/gepard-vulkan.h
Outdated
void createShaderModule(VkShaderModule& shader, const uint32_t* code, const size_t codeSize); | ||
|
||
void uploadToDeviceMemory(VkDeviceMemory buffer, const void* data, VkDeviceSize size, VkDeviceSize offset = 0); | ||
void createSimplePipeline(VkPipeline& pipeline, VkPipelineLayout& layout, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if each parameter is in a separate line?
src/gepard-image.cpp
Outdated
|
||
#include "gepard-image.h" | ||
|
||
#include <cstring> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is unnecessary.
src/engines/vulkan/gepard-vulkan.cpp
Outdated
|
||
GepardVulkan::GepardVulkan(GepardContext& context) | ||
: _context(context) | ||
, _vk("libvulkan.so") | ||
, _vk("libvulkan.so.1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the .1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it was needed before, when the libvulkan was built from source, and at some point it didn't produced the libvulkan.so, it might was a bug. I tried it locally, and it worked fine, thanks.
src/engines/vulkan/gepard-vulkan.cpp
Outdated
static const uint64_t timeout = (uint64_t)16 * oneMiliSec; // 16 ms | ||
static const uint64_t timeout = (uint64_t)32 * oneMiliSec; // 32 ms | ||
#ifdef VK_USE_PLATFORM_XCB_KHR | ||
static xcb_connection_t* xcbConnection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be placed inside the GepardVulkan class imho. As if you are creating multiple contexts they could overwrite each other.
_vk.vkFlushMappedMemoryRanges(_device, 1, &range); | ||
_vk.vkUnmapMemory(_device, vertexBufferMemory); | ||
} | ||
createBuffer(vertexBuffer, vertexBufferMemory, vertexMemoryRequirements, (VkDeviceSize)sizeof(vertexData), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there will be multiple buffers in the long run, maybe it would be good idea to create a class which represents a buffer object with all of it's memory requirement, vkBuffer, and everything. However it should not be done in this PR afaik.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I've created issue #134 to cover this, as there are other resources which would benefit from this. This will be resolved in a future PR.
GD_ASSERT(vkResult == VK_SUCCESS && "Memory bind failed!"); | ||
} | ||
|
||
void GepardVulkan::createImageView(VkImageView &imageView, VkImage image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to return the imageView instead of requesting it as a reference?
That would make it possible to directly use the result in structures (if needed) or something like this:
VkImageView view = createImageView(image);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I have tried to do this for all the resources which are created this way, but with the image I got segmentation fault, which is strange. I've created issue #137 to resolve this.
0, // VkImageViewCreateFlags flags; | ||
image, // VkImage image; | ||
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType; | ||
_imageFormat, // VkFormat format; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the _imageFormat
global for all images?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, at least for now.
const VkMemoryAllocateInfo imageAllocateInfo = { | ||
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType; | ||
nullptr, // const void* pNext; | ||
memReq.size, // VkDeviceSize allocationSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect indentation of the comments.
const VkMappedMemoryRange range = { | ||
VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType; | ||
nullptr, // const void* pNext; | ||
buffer, // VkDeviceMemory memory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect indentation of the comments.
0.0f, // float A | ||
}, // float blendConstants[4]; | ||
}; | ||
_vk.vkCreatePipelineLayout(_device, &layoutInfo, _allocator, &layout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the result be checked?
src/engines/vulkan/gepard-vulkan.cpp
Outdated
|
||
VkViewport GepardVulkan::getDefaultViewPort() | ||
{ | ||
VkViewport viewPort = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace has incorrect indentation.
_vk.vkDestroyFence(_device, fence, _allocator); | ||
} | ||
|
||
void GepardVulkan::updateSurface() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm this is only used at one place, however the internal parts of the method is used at least two other places.
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
Signed-off-by: Kristof Kosztyo <[email protected]>
src/CMakeLists.txt
Outdated
@@ -71,17 +73,19 @@ if (BACKEND STREQUAL "VULKAN" AND NOT VULKAN_FOUND) | |||
endif() | |||
|
|||
if (BACKEND STREQUAL "VULKAN") | |||
include(engines/vulkan/shaders/VulkanShaders.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file should go into the cmake/
directory, with the other cmake modules. Then you can simply use include(VulkanShaders)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
thirdparty/CMakeLists.txt
Outdated
@@ -22,7 +22,8 @@ set(INCLUDE_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/include) | |||
# - A subdirectory in PROJECT_BINARY_DIR can be used as a build directory. | |||
|
|||
add_custom_target(common ALL | |||
DEPENDS gtest) | |||
DEPENDS gtest | |||
glslang) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't only the vulkan backend depend on this? Please move this to the vulkan target below this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I wasn't sure if I first build the gles2 backend then I build the vulkan it would get the glslang and I thought it doesn't have a big toll to build the glslang for every traget. Now I've tried what happend in this case and it works flawless, thanks.
Signed-off-by: Kristof Kosztyo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
informal lgtm, thanks
Hi, I've updated the PR and add several issues which can be resolved later. Please let me know if I missed something. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there are issues to track the required improvements and some of them are already fixed I'm ok to land this. LGTM
🎉🍾🖖 |
There has been a while since the last merge, sorry about that :)
New things:
I know this is a bit big chunk of code to review, so please take your time.
Cheers!