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

Event Pipelines #487

Merged
merged 9 commits into from
Jul 29, 2022
Merged

Conversation

TomAtkinsonArm
Copy link
Contributor

@TomAtkinsonArm TomAtkinsonArm commented Jul 8, 2022

Description

Builds on-top of #485.

The Event Bus allows for communication between components and the firing of one off events. It does not allow for a Sample to continually fire and react to a given sequence of events.

Pipelines aim to allow stages to continually run without the need for an Event Observer to submit the event manually. This allows a sample to have a very compact view of its execution flow. Samples can now have completely different execution flows.

Example

// hello world

struct Context{
    // ... Global Vulkan Handles
};

struct FrameContext {
    // ... per frame Vulkan handles
};

class FrameManager : public EventObserver {
    // ... React to window updates, recreate the Swapchain, recreate frame data
};

std::shared_ptr<ExitOnEscape> exit_on_escape() {
    // ... default exit behaviour defined some where else in the project
    static std::shared_ptr<ExitOnEscape> observer = std::make_shared<ExitOnEscape>();
    return observer;
}

// ... project defined update stage
struct UpdateEvent {
    float delta_time;
};

class Update : public TypedPipelineStage<UpdateEvent>;

// ... project defined draw stage
struct DrawEvent {
    CommandPool& pool;
};

class Draw : public TypedPipelineStage<DrawEvent>;

void sample_main(void* platform_context) {
    auto window = windows::_default(platform_context, "Hello Triangle");

    Context context{};

    // ... init Vulkan stuff

    auto frame_manager = std::make_shared<FrameManager>(context);
    
    EventPipeline pipeline;

    pipeline
      .attach(window)
      .attach(frame_manager)
      .attach(exit_on_escape())
      .then(std::make_shared<Update>())
      .then(std::make_shared<Draw>());

    // ... step pipeline
    while(true) {
        // process will eventually have error handling
        // its likely that this statement will be
        // return pipeline.run();
        // where run() internally has a loop and return on error or close
        pipeline.process(); 
    }
}

@SaschaWillems
Copy link
Collaborator

Technically this looks great, but I'm not sure if we want to use the term pipeline for this. I fear that people could get confused with having graphics pipelines and also pipelines for event related stuff?

@TomAtkinsonArm
Copy link
Contributor Author

Technically this looks great, but I'm not sure if we want to use the term pipeline for this. I fear that people could get confused with having graphics pipelines and also pipelines for event related stuff?

@SaschaWillems EventPipeline?

@TomAtkinsonArm TomAtkinsonArm changed the title Pipelines Event Pipelines Jul 8, 2022
@TomAtkinsonArm
Copy link
Contributor Author

Rebased on events_bus

@SaschaWillems
Copy link
Collaborator

Yes, I'm fine with EventPipeline. That's a clear distinction between this and Vulkan's pipeline. The PR looks fine to me, but just as with the event bus PR I can't seem to find or run the tests for this in VS2019.

@TomAtkinsonArm
Copy link
Contributor Author

The PR looks fine to me, but just as with the event bus PR I can't seem to find or run the tests for this in VS2019.

Try ctest --output-on-failure --test-dir=<build/folder> also configure using -DVKB_BUILD_TESTS=ON

@SaschaWillems
Copy link
Collaborator

Tried running that, but it just tells me that no tests were found. Even when building with -DVKB_BUILD_TESTS=ON. Maybe we can take a look at this in today's call.

@TomAtkinsonArm
Copy link
Contributor Author

In the CI we use:

cmake -H"." -B"build/windows" -DVKB_BUILD_TESTS=ON
cmake --build "build/windows" --target vkb_tests --config Debug --parallel
ctest --output-on-failure --test-dir "build/windows" -C Debug

This also works locally for me

@TomAtkinsonArm
Copy link
Contributor Author

TomAtkinsonArm commented Jul 26, 2022

Rebased @SaschaWillems @asuessenbach is this ready to be approved?

@TomAtkinsonArm
Copy link
Contributor Author

Comments resolved, merging for now. The concept will evolve over time and more than likely be replaced in the near future if it does not fit its desired use case.

@TomAtkinsonArm TomAtkinsonArm merged commit 9d34506 into KhronosGroup:framework/v2.0 Jul 29, 2022
TomAtkinsonArm added a commit to TomAtkinsonArm/Vulkan-Samples that referenced this pull request Jul 29, 2022
* event bus

* response to feedback

* add assert

* assert

* added observer expiration test

* add pipelines

* stages with custom fields

* Pipeline -> EventPipeline

* add comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework This is relevant to the framework
Projects
No open projects
Framework Improvements
Open For Review
Development

Successfully merging this pull request may close these issues.

None yet

3 participants