Skip to content
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

Merged
merged 24 commits into from
Oct 5, 2018

Conversation

kkristof
Copy link
Member

@kkristof kkristof commented Oct 1, 2018

There has been a while since the last merge, sorry about that :)
New things:

  • SPIR-V generator, which creates a nice header from the shader sources
  • Basic image implementation
  • Image support for the vulkan backend
    • Every image related canvas function is supported
  • New utility functions for the vulkan backend, these should streamline the development
  • Compile time SPIR-V generation

I know this is a bit big chunk of code to review, so please take your time.
Cheers!

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]>
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]>
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
Copy link
Member

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.

Copy link
Member Author

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.

@@ -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
Copy link
Member

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.

Copy link
Member Author

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.

apps/examples/image/image.cpp Outdated Show resolved Hide resolved
_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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braces here.

GD_ASSERT(vkResult == VK_SUCCESS && "Queue submit failed!");

vkResult = _vk.vkWaitForFences(_device, 1, &fence, VK_TRUE, timeout);
if (vkResult == VK_TIMEOUT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braces here.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braces here.

_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)
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VkResult...

_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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{}

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,
Copy link
Member

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?


#include "gepard-image.h"

#include <cstring>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is unnecessary.


GepardVulkan::GepardVulkan(GepardContext& context)
: _context(context)
, _vk("libvulkan.so")
, _vk("libvulkan.so.1")
Copy link
Member

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?

Copy link
Member Author

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.

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;
Copy link
Member

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);
Copy link
Member

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.

Copy link
Member Author

@kkristof kkristof Oct 3, 2018

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)
Copy link
Member

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);

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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?


VkViewport GepardVulkan::getDefaultViewPort()
{
VkViewport viewPort = {
Copy link
Member

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()
Copy link
Member

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.

@@ -71,17 +73,19 @@ if (BACKEND STREQUAL "VULKAN" AND NOT VULKAN_FOUND)
endif()

if (BACKEND STREQUAL "VULKAN")
include(engines/vulkan/shaders/VulkanShaders.cmake)
Copy link
Member

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

@@ -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)
Copy link
Member

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.

Copy link
Member Author

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.

@kkristof
Copy link
Member Author

kkristof commented Oct 3, 2018

For all the vkResult and structure comment related issues I have created issue #135 and #136.

szledan
szledan previously approved these changes Oct 4, 2018
Copy link
Member

@szledan szledan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

informal lgtm, thanks

@kkristof
Copy link
Member Author

kkristof commented Oct 4, 2018

Hi, I've updated the PR and add several issues which can be resolved later. Please let me know if I missed something. Thanks.

@szledan szledan dismissed their stale review October 5, 2018 13:22

because it was not a real approve

Copy link
Member

@elecro elecro left a 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

@kkristof kkristof merged commit b2aa74d into GepardGraphics:master Oct 5, 2018
@szledan
Copy link
Member

szledan commented Oct 5, 2018

🎉🍾🖖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants