Skip to content

Commit

Permalink
PE + Executors
Browse files Browse the repository at this point in the history
  • Loading branch information
martty committed Dec 27, 2023
1 parent bd83d1b commit e22f52a
Show file tree
Hide file tree
Showing 31 changed files with 1,190 additions and 1,484 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ target_sources(vuk PRIVATE
src/DeviceVkResource.cpp
src/BufferAllocator.cpp
src/DeviceLinearResource.cpp
)
src/runtime/vk/VulkanQueueExecutor.cpp)

target_include_directories(vuk PUBLIC ext/plf_colony)
add_subdirectory(ext/robin-hood-hashing)
Expand Down Expand Up @@ -195,8 +195,8 @@ if(VUK_BUILD_TESTS)

include(doctest_force_link_static_lib_in_target) # until we can use cmake 3.24
add_executable(vuk-tests src/tests/Test.cpp
#src/tests/commands.cpp
#src/tests/renderpass.cpp
src/tests/commands.cpp
src/tests/renderpass.cpp
src/tests/arrays.cpp
)
#target_compile_features(vuk-tests PRIVATE cxx_std_17)
Expand Down
6 changes: 3 additions & 3 deletions examples/01_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace {
},
// Code ran every frame
.render =
[](vuk::ExampleRunner& runner, vuk::Allocator& frame_allocator, vuk::TypedFuture<vuk::Image> target) {
[](vuk::ExampleRunner& runner, vuk::Allocator& frame_allocator, vuk::TypedFuture<vuk::ImageAttachment> target) {
// The framework provides us with an image to render to in "target"
// We attach this to the rendergraph named as "01_triangle"
// The rendergraph is composed of passes (vuk::Pass)
// Each pass declares which resources are used
// And it provides a callback which is executed when this pass is being ran
auto pass = vuk::make_pass("01_triangle", [](vuk::CommandBuffer& command_buffer, vuk::IA<vuk::eColorWrite, decltype([](){})> color_rt) {
auto pass = vuk::make_pass("01_triangle", [](vuk::CommandBuffer& command_buffer, VUK_IA(vuk::eColorWrite) color_rt) {
command_buffer.set_viewport(0, vuk::Rect2D::framebuffer());
// Set the scissor area to cover the entire framebuffer
command_buffer.set_scissor(0, vuk::Rect2D::framebuffer());
Expand All @@ -42,7 +42,7 @@ namespace {
.set_color_blend(color_rt, {}) // Set the default color blend state
.bind_graphics_pipeline("triangle") // Recall pipeline for "triangle" and bind
.draw(3, 1, 0, 0); // Draw 3 vertices
return std::make_tuple(color_rt);
return color_rt;
});

auto drawn = pass(std::move(target));
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()
FetchContent_Declare(
vk-bootstrap
GIT_REPOSITORY https://github.com/charles-lunarg/vk-bootstrap
GIT_TAG 8e61b2d81c3f5f84339735085ff5651f71bbe1e7
GIT_TAG 3ad0388f1b68dbf99746a2fab8c3115c8fa887bb
)
FetchContent_MakeAvailable(vk-bootstrap)

Expand Down
40 changes: 18 additions & 22 deletions examples/example_runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "vuk/RenderGraph.hpp"
#include "vuk/SampledImage.hpp"
#include "vuk/resources/DeviceFrameResource.hpp"
#include "vuk/runtime/ThisThreadExecutor.hpp"
#include <VkBootstrap.h>
#include <filesystem>
#include <functional>
Expand Down Expand Up @@ -48,7 +49,7 @@ namespace vuk {
std::optional<DeviceSuperFrameResource> superframe_resource;
std::optional<Allocator> superframe_allocator;
bool suspend = false;
vuk::SwapchainRef swapchain;
std::optional<vuk::Swapchain> swapchain;
GLFWwindow* window;
VkSurfaceKHR surface;
vkb::Instance vkbinstance;
Expand All @@ -74,7 +75,7 @@ namespace vuk {
futures.emplace_back(std::move(fut));
}

plf::colony<vuk::SampledImage> sampled_images;
std::vector<TypedFuture<ImageAttachment>> sampled_images;
std::vector<Example*> examples;

ExampleRunner();
Expand All @@ -99,12 +100,9 @@ namespace vuk {
if (width == 0 && height == 0) {
runner.suspend = true;
} else {
runner.superframe_allocator->deallocate(std::span{ &runner.swapchain->swapchain, 1 });
runner.superframe_allocator->deallocate(runner.swapchain->image_views);
runner.context->remove_swapchain(runner.swapchain);
runner.swapchain = runner.context->add_swapchain(util::make_swapchain(runner.vkbdevice, runner.swapchain->swapchain));
for (auto& iv : runner.swapchain->image_views) {
runner.context->set_name(iv.payload, "Swapchain ImageView");
runner.swapchain = util::make_swapchain(*runner.superframe_allocator, runner.vkbdevice, runner.swapchain);
for (auto& iv : runner.swapchain->images) {
runner.context->set_name(iv.image_view.payload, "Swapchain ImageView");
}
runner.suspend = false;
}
Expand Down Expand Up @@ -137,8 +135,8 @@ namespace vuk {
tracy_cpool.reset();
present_ready.reset();
render_complete.reset();
imgui_data.font_texture.view.reset();
imgui_data.font_texture.image.reset();
imgui_data.font_image.reset();
imgui_data.font_image_view.reset();
superframe_resource.reset();
context.reset();
auto vkDestroySurfaceKHR = (PFN_vkDestroySurfaceKHR)vkbinstance.fp_vkGetInstanceProcAddr(vkbinstance.instance, "vkDestroySurfaceKHR");
Expand Down Expand Up @@ -245,23 +243,21 @@ namespace vuk {
transfer_queue = vkbdevice.get_queue(vkb::QueueType::transfer).value();
auto transfer_queue_family_index = vkbdevice.get_queue_index(vkb::QueueType::transfer).value();
device = vkbdevice.device;
ContextCreateParameters::FunctionPointers fps;
vuk::rtvk::FunctionPointers fps;
fps.vkGetInstanceProcAddr = vkbinstance.fp_vkGetInstanceProcAddr;
fps.vkGetDeviceProcAddr = vkbinstance.fp_vkGetDeviceProcAddr;
context.emplace(ContextCreateParameters{ instance,
device,
physical_device,
graphics_queue,
graphics_queue_family_index,
VK_NULL_HANDLE,
VK_QUEUE_FAMILY_IGNORED,
transfer_queue,
transfer_queue_family_index,
fps });
fps.load_pfns(instance, device, true);
std::vector<std::unique_ptr<Executor>> executors;

executors.push_back(rtvk::create_vkqueue_executor(fps, device, graphics_queue, graphics_queue_family_index, DomainFlagBits::eGraphicsQueue));
executors.push_back(rtvk::create_vkqueue_executor(fps, device, transfer_queue, transfer_queue_family_index, DomainFlagBits::eTransferQueue));
executors.push_back(std::make_unique<ThisThreadExecutor>());

context.emplace(ContextCreateParameters{ instance, device, physical_device, std::move(executors), fps });
const unsigned num_inflight_frames = 3;
superframe_resource.emplace(*context, num_inflight_frames);
superframe_allocator.emplace(*superframe_resource);
swapchain = context->add_swapchain(util::make_swapchain(vkbdevice, {}));
swapchain = util::make_swapchain(*superframe_allocator, vkbdevice, {});
present_ready = vuk::Unique<std::array<VkSemaphore, 3>>(*superframe_allocator);
render_complete = vuk::Unique<std::array<VkSemaphore, 3>>(*superframe_allocator);

Expand Down
15 changes: 7 additions & 8 deletions examples/example_runner_single.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "example_runner.hpp"

vuk::SwapchainRenderBundle bundle;

void vuk::ExampleRunner::render() {
Compiler compiler;
// the examples can all enqueue upload tasks via enqueue_setup. for simplicity, we submit and wait for all the upload tasks before moving on to the render
Expand All @@ -25,16 +23,15 @@ void vuk::ExampleRunner::render() {
// optional
Allocator frame_allocator(frame_resource);
// create a rendergraph we will use to prepare a swapchain image for the example to render into
auto imported_swapchain = import_swapchain(bundle);
auto imported_swapchain = declare_swapchain(*swapchain);
// acquire an image on the swapchain
auto swapchain_image = acquire_next_image("swapchain image", imported_swapchain);
auto swapchain_image = acquire_next_image("swp_img", std::move(imported_swapchain));

// clear the swapchain image
TypedFuture<ImageAttachment> cleared_image_to_render_into = clear_image(swapchain_image, vuk::ClearColor{ 0.3f, 0.5f, 0.3f, 1.0f });
TypedFuture<ImageAttachment> cleared_image_to_render_into = clear_image(std::move(swapchain_image), vuk::ClearColor{ 0.3f, 0.5f, 0.3f, 1.0f });
// invoke the render method of the example with the cleared image
TypedFuture<ImageAttachment> example_result = examples[0]->render(*this, frame_allocator, std::move(cleared_image_to_render_into));


// set up some profiling callbacks for our example Tracy integration
vuk::ProfilingCallbacks cbs;
cbs.user_data = &get_runner();
Expand Down Expand Up @@ -72,8 +69,10 @@ void vuk::ExampleRunner::render() {

// compile the RG that contains all the rendering of the example
// submit and present the results to the swapchain we imported previously
present_one(example_result, { .callbacks = cbs });

auto entire_thing = enqueue_presentation(std::move(example_result));

entire_thing.wait(frame_allocator, compiler, { .callbacks = cbs });

// update window title with FPS
if (++num_frames == 16) {
auto new_time = get_time();
Expand Down
Loading

0 comments on commit e22f52a

Please sign in to comment.