Skip to content

Commit

Permalink
Further draw indirect commands added
Browse files Browse the repository at this point in the history
* Added further draw_indirect commands

* Bugfix: Post execution handler was not invoked in command_buffer_t::prepare_for_reuse()

* Attempt to fix build.yml

* trying to fix windows-latest builds
  • Loading branch information
johannesugb authored Mar 14, 2024
1 parent a409915 commit 630dc0c
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 13 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
}
# note: if a specific vulkan version (e.g. 1.1.x, or < 1.2.135) needs testing, you can add it here:
# (not that ubuntu-latest (20.04) only supports >= v1.2.148 via apt)
vulkan-sdk: ["latest", "1.2.176"]
vulkan-sdk: ["latest", "1.3.204", "1.3.216"]
vma: ["ON", "OFF"]
exclude: # exclude combinations that are known to fail
- vulkan-sdk: "1.2.176"
- vulkan-sdk: "1.3.204"
vma: "ON"

steps:
Expand Down Expand Up @@ -86,10 +86,10 @@ jobs:
shell: bash
working-directory: ${{ runner.workspace }}/build
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build .
run: cmake --build . --config $BUILD_TYPE

windows:
name: ${{ matrix.config.name }}, VulkanSDK ${{ matrix.vulkan-sdk }}, VMA=${{ matrix.vma }}
name: ${{ matrix.config.name }}, windows-2019, VulkanSDK ${{ matrix.vulkan-sdk }}, VMA=${{ matrix.vma }}
runs-on: windows-2019
env:
vulkan_sdk: "$GITHUB_WORKSPACE/vulkan_sdk/"
Expand All @@ -102,8 +102,8 @@ jobs:
cc: "cl",
cxx: "cl"
}
# note: if a specific vulkan version (e.g. 1.1.x, or < 1.2.135) needs testing, you can add it here:
vulkan-sdk: ["latest", "1.3.216.0", "1.2.198.1"]
# note: if a specific vulkan version needs testing, you can add it here:
vulkan-sdk: ["latest", "1.3.204.1", "1.3.216.0"]
vma: ["ON", "OFF"]
exclude: # exclude combinations that are known to fail
- vulkan-sdk: "1.2.198"
Expand Down Expand Up @@ -146,6 +146,9 @@ jobs:
$env:CC="${{ matrix.config.cc }}"
$env:CXX="${{ matrix.config.cxx }}"
$env:Path += ";${{ env.vulkan_sdk }}\;${{ env.vulkan_sdk }}\Bin\"
$env:VULKAN_SDK="${{ env.vulkan_sdk }}"
$env:Vulkan_LIBRARY="${{ env.vulkan_sdk }}/Bin"
$env:Vulkan_INCLUDE_DIR="${{ env.vulkan_sdk }}/Include"
# apparently checkout@v2 pulls to Auto-Vk/Auto-Vk on windows
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -Davk_LibraryType=STATIC ${{ runner.workspace }}/${{ github.event.repository.name }} -Davk_UseVMA=${{ matrix.vma }} -G "Visual Studio 16 2019" -A x64
Expand All @@ -155,10 +158,10 @@ jobs:
# apparently checkout@v2 pulls to Auto-Vk/Auto-Vk on windows
working-directory: ${{ runner.workspace }}/${{ github.event.repository.name }}/build
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build .
run: cmake --build . --config $BUILD_TYPE

windows-latest:
name: ${{ matrix.config.name }}, VulkanSDK ${{ matrix.vulkan-sdk }}, VMA=${{ matrix.vma }}
name: ${{ matrix.config.name }}, windows-latest, VulkanSDK ${{ matrix.vulkan-sdk }}, VMA=${{ matrix.vma }}
runs-on: windows-latest
env:
vulkan_sdk: "$GITHUB_WORKSPACE/vulkan_sdk/"
Expand All @@ -171,8 +174,8 @@ jobs:
cc: "cl",
cxx: "cl"
}
# note: if a specific vulkan version (e.g. 1.1.x, or < 1.2.135) needs testing, you can add it here:
vulkan-sdk: ["latest", "1.3.216.0", "1.2.198.1"]
# note: if a specific vulkan version needs testing, you can add it here:
vulkan-sdk: ["latest", "1.3.204.1", "1.3.216.0"]
vma: ["ON", "OFF"]
exclude: # exclude combinations that are known to fail
- vulkan-sdk: "1.2.198"
Expand Down Expand Up @@ -215,6 +218,9 @@ jobs:
$env:CC="${{ matrix.config.cc }}"
$env:CXX="${{ matrix.config.cxx }}"
$env:Path += ";${{ env.vulkan_sdk }}\;${{ env.vulkan_sdk }}\Bin\"
$env:VULKAN_SDK="${{ env.vulkan_sdk }}"
$env:Vulkan_LIBRARY="${{ env.vulkan_sdk }}/Bin"
$env:Vulkan_INCLUDE_DIR="${{ env.vulkan_sdk }}/Include"
# apparently checkout@v2 pulls to Auto-Vk/Auto-Vk on windows
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -Davk_LibraryType=STATIC ${{ runner.workspace }}/${{ github.event.repository.name }} -Davk_UseVMA=${{ matrix.vma }} -G "Visual Studio 17 2022" -A x64
Expand All @@ -224,4 +230,4 @@ jobs:
# apparently checkout@v2 pulls to Auto-Vk/Auto-Vk on windows
working-directory: ${{ runner.workspace }}/${{ github.event.repository.name }}/build
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build .
run: cmake --build . --config $BUILD_TYPE
136 changes: 136 additions & 0 deletions include/avk/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,142 @@ namespace avk
bind_vertex_buffer(aHandlePtr + 1, aOffsetPtr + 1, aRest...);
}

/** Draw vertices with vertex buffer bindings starting at BUFFER-BINDING #0 top to the number of total buffers passed -1.
* "BUFFER-BINDING" means that it corresponds to the binding specified in `input_binding_location_data::from_buffer_at_binding`.
* There can be no gaps between buffer bindings.
* @param aFurtherBuffers Multiple const-references to buffers, or tuples of const-references to buffers + offsets.
* First case: Pass const buffer_t& types!
* Second case: Pass tuples of type std::tuple<const buffer_t&, size_t>!
* Hint: std::forward_as_tuple might be useful to get that reference into a std::tuple.
* Example: avk::buffer myVertexBuffer;
* auto myTuple = std::forward_as_tuple(myVertexBuffer.get(), size_t{0});
*/
template <typename... Bfrs>
action_type_command draw_vertices_indirect(const buffer_t& aParametersBuffer, vk::DeviceSize aParametersOffset, uint32_t aParametersStride, uint32_t aDrawCount, const Bfrs&... aFurtherBuffers)
{
constexpr size_t N = sizeof...(aFurtherBuffers);

if constexpr (N == 0) {
return action_type_command{
avk::sync::sync_hint {
{{ // DESTINATION dependencies for previous commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eInputAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentRead | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}},
{{ // SOURCE dependencies for subsequent commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}}
},
{}, // no resource-specific sync hints
[
lParametersBufferHandle = aParametersBuffer.handle(), aParametersOffset, aParametersStride, aDrawCount
](avk::command_buffer_t& cb) {
cb.handle().drawIndirect(lParametersBufferHandle, aParametersOffset, aDrawCount, aParametersStride);
}
};
}
else {
std::array<vk::Buffer, N> handles;
std::array<vk::DeviceSize, N> offsets;
bind_vertex_buffer(&handles[0], &offsets[0], aFurtherBuffers...);

return action_type_command{
avk::sync::sync_hint {
{{ // DESTINATION dependencies for previous commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eInputAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentRead | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}},
{{ // SOURCE dependencies for subsequent commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}}
},
{}, // no resource-specific sync hints
[
lBindingCount = static_cast<uint32_t>(N),
lParametersBufferHandle = aParametersBuffer.handle(), aParametersOffset, aParametersStride, aDrawCount,
handles, offsets
](avk::command_buffer_t& cb) {
cb.handle().bindVertexBuffers(
0u, // TODO: Should the first binding really always be 0?
static_cast<uint32_t>(N), handles.data(), offsets.data()
);
cb.handle().drawIndirect(lParametersBufferHandle, aParametersOffset, aDrawCount, aParametersStride);
}
};
}
}

/** Draw vertices with vertex buffer bindings starting at BUFFER-BINDING #0 top to the number of total buffers passed -1.
* "BUFFER-BINDING" means that it corresponds to the binding specified in `input_binding_location_data::from_buffer_at_binding`.
* There can be no gaps between buffer bindings.
* @param aFurtherBuffers Multiple const-references to buffers, or tuples of const-references to buffers + offsets.
* First case: Pass const buffer_t& types!
* Second case: Pass tuples of type std::tuple<const buffer_t&, size_t>!
* Hint: std::forward_as_tuple might be useful to get that reference into a std::tuple.
* Example: avk::buffer myVertexBuffer;
* auto myTuple = std::forward_as_tuple(myVertexBuffer.get(), size_t{0});
*/
template <typename... Bfrs>
action_type_command draw_vertices_indirect_count(const buffer_t& aParametersBuffer, vk::DeviceSize aParametersOffset, uint32_t aParametersStride, const buffer_t& aDrawCountBuffer, vk::DeviceSize aDrawCountOffset, uint32_t aMaxNumberOfDraws, const Bfrs&... aFurtherBuffers)
{
constexpr size_t N = sizeof...(aFurtherBuffers);

if constexpr (N == 0) {
return action_type_command{
avk::sync::sync_hint {
{{ // DESTINATION dependencies for previous commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eInputAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentRead | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}},
{{ // SOURCE dependencies for subsequent commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}}
},
{}, // no resource-specific sync hints
[
lParametersBufferHandle = aParametersBuffer.handle(), aParametersOffset, aParametersStride,
lDrawCountBufferHandle = aDrawCountBuffer.handle(), aDrawCountOffset, aMaxNumberOfDraws
](avk::command_buffer_t& cb) {
cb.handle().drawIndirectCount(lParametersBufferHandle, aParametersOffset, lDrawCountBufferHandle, aDrawCountOffset, aMaxNumberOfDraws, aParametersStride);
}
};
}
else {
std::array<vk::Buffer, N> handles;
std::array<vk::DeviceSize, N> offsets;
bind_vertex_buffer(&handles[0], &offsets[0], aFurtherBuffers...);

return action_type_command{
avk::sync::sync_hint {
{{ // DESTINATION dependencies for previous commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eInputAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentRead | vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentRead | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}},
{{ // SOURCE dependencies for subsequent commands:
vk::PipelineStageFlagBits2KHR::eAllGraphics,
vk::AccessFlagBits2KHR::eColorAttachmentWrite | vk::AccessFlagBits2KHR::eDepthStencilAttachmentWrite
}}
},
{}, // no resource-specific sync hints
[
lBindingCount = static_cast<uint32_t>(N),
lParametersBufferHandle = aParametersBuffer.handle(), aParametersOffset, aParametersStride,
lDrawCountBufferHandle = aDrawCountBuffer.handle(), aDrawCountOffset, aMaxNumberOfDraws,
handles, offsets
](avk::command_buffer_t& cb) {
cb.handle().bindVertexBuffers(
0u, // TODO: Should the first binding really always be 0?
static_cast<uint32_t>(N), handles.data(), offsets.data()
);
cb.handle().drawIndirectCount(lParametersBufferHandle, aParametersOffset, lDrawCountBufferHandle, aDrawCountOffset, aMaxNumberOfDraws, aParametersStride);
}
};
}
}

/** Draw vertices with vertex buffer bindings starting at BUFFER-BINDING #0 top to the number of total buffers passed -1.
* "BUFFER-BINDING" means that it corresponds to the binding specified in `input_binding_location_data::from_buffer_at_binding`.
* There can be no gaps between buffer bindings.
Expand Down
7 changes: 5 additions & 2 deletions src/avk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2856,12 +2856,15 @@ namespace avk
void command_buffer_t::prepare_for_reuse()
{
if (mPostExecutionHandler.has_value()) {
// Clear post-execution handler
// If there is a post-execution handler => call it now:
invoke_post_execution_handler();
// Clear post-execution handler:
mPostExecutionHandler.reset();
}
if (mCustomDeleter.has_value() && *mCustomDeleter) {
// If there is a custom deleter => call it now
// If there is a custom deleter => call it now:
(*mCustomDeleter)();
// Clear custom deleter:
mCustomDeleter.reset();
}
mLifetimeHandledResources.clear();
Expand Down

0 comments on commit 630dc0c

Please sign in to comment.