Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
88295fb
Use dynamic viewport and scissor by default
AnyOldName3 Aug 23, 2024
71d1f0c
Track viewport with State
AnyOldName3 Sep 18, 2024
072a38a
Prune headers
AnyOldName3 Sep 18, 2024
158e450
Merge branch 'master' into dynamic-viewport
robertosfield Jan 31, 2025
49964be
Merge branch 'master' into dynamic-viewport
robertosfield Feb 1, 2025
de4fb7d
Merge branch 'master' into dynamic-viewport
robertosfield Feb 3, 2025
8551902
Merge branch 'master' into dynamic-viewport
robertosfield Feb 4, 2025
84afc90
Merge branch 'master' into dynamic-viewport
robertosfield Feb 6, 2025
4cc5c36
Experimental ViewportState with built in support for vkCmdSetViewport…
robertosfield Feb 8, 2025
742468a
Merge branch 'master' into dynamic-viewport2
robertosfield Feb 8, 2025
644ed28
Removed no longer required code.
robertosfield Feb 8, 2025
266560e
Removed passing ViewportState to compile traversal.
robertosfield Feb 8, 2025
9d17041
Simplified CompileManager and CompileTraversal removing ViewportState…
robertosfield Feb 8, 2025
da2d31e
Added support for shading GraphicsPipelineImplementation.
robertosfield Feb 10, 2025
48b3f75
Ran clang-format
robertosfield Feb 10, 2025
b7aa444
Changed local variable name to avoid cppcheck shadowing wrning
robertosfield Feb 10, 2025
fc79e31
cppcheck fixes
robertosfield Feb 10, 2025
b6e9800
Bumped version for dynamic ViewportState work.
robertosfield Feb 10, 2025
654f24f
cppcheck warning fixes
robertosfield Feb 10, 2025
ccacf18
cppcheck warning fix.
robertosfield Feb 10, 2025
8b248aa
Fixed typo
robertosfield Feb 10, 2025
a29be81
Added assignment of ViewportState to pre-render Cameras.
robertosfield Feb 10, 2025
83ff107
Added push/pop of RenderGraph's area as ViewportState to enble render…
robertosfield Feb 11, 2025
462d86a
Ran clang-format
robertosfield Feb 11, 2025
12862b1
Added compile with ViewportState.
robertosfield Feb 11, 2025
7742fb5
Added ViewportState to RenderGraph.
robertosfield Feb 11, 2025
69d5e45
Ran clang-format.
robertosfield Feb 11, 2025
74fd897
Updated built-in ShaderSet.
robertosfield Feb 11, 2025
1fac176
Fixed Visitor/ConstVisitor support for GraphicsPipelineStates
robertosfield Feb 11, 2025
8a98209
Revert "Simplified CompileManager and CompileTraversal removing Viewp…
robertosfield Feb 12, 2025
fdf06f5
Revert "Removed passing ViewportState to compile traversal."
robertosfield Feb 12, 2025
68efcf5
Upped the ViewportState::slot to 8 to make it less likely that it'll …
robertosfield Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.7)

project(vsg
VERSION 1.1.10
VERSION 1.1.11
DESCRIPTION "VulkanSceneGraph library"
LANGUAGES CXX
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/cppcheck-suppression-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ useStlAlgorithm:*/src/vsg/nodes/VertexIndexDraw.cpp
useStlAlgorithm:*/src/vsg/nodes/Switch.cpp
useStlAlgorithm:*/src/vsg/nodes/LOD.cpp
useStlAlgorithm:*/src/vsg/state/DescriptorBuffer.cpp
useStlAlgorithm:*/src/vsg/state/GraphicsPipeline.cpp
useStlAlgorithm:*/src/vsg/state/PipelineLayout.cpp
useStlAlgorithm:*/src/vsg/state/StateSwitch.cpp
useStlAlgorithm:*/src/vsg/state/ViewDependentState.cpp
Expand Down Expand Up @@ -60,7 +61,6 @@ useStlAlgorithm:*/src/vsg/io/Path.cpp
useStlAlgorithm:*/src/vsg/utils/PolytopeIntersector.cpp
useStlAlgorithm:*/src/vsg/vk/PhysicalDevice.cpp


// suppress the warning about valid C++17 if (init; condition) usage
syntaxError:*/include/vsg/core/Inherit.h
syntaxError:*/src/vsg/io/AsciiOutput.cpp
Expand Down
5 changes: 4 additions & 1 deletion include/vsg/app/RenderGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ namespace vsg
/// Get the Extent2D of the attached Framebuffer or Window.
VkExtent2D getExtent() const;

/// RenderArea settings for VkRenderPassBeginInfo.renderArea passed to the vkCmdBeginRenderPass, usually matches the ViewportState's scissor
/// RenderArea settings for VkRenderPassBeginInfo.renderArea passed to the vkCmdBeginRenderPass
VkRect2D renderArea;

// Default ViewportState to use for graphics pipelines under this RenderGraph, this be will synced with the renderArea.
ref_ptr<ViewportState> viewportState;

/// RenderPass to use passed to the vkCmdBeginRenderPass in place of the framebuffer's or window's renderPass. renderPass must be compatible with the render pass used to create the window or framebuffer.
ref_ptr<RenderPass> renderPass;

Expand Down
3 changes: 1 addition & 2 deletions include/vsg/app/WindowResizeHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace vsg

/// Utility class for updating a scene graph when a View's camera ViewportState has been updated so that associated GraphicsPipelines in the
/// scene graph can be recompiled and correctly reflect the new ViewportState.
/// As viewport size and scissor is dynamic by default, this is only necessary when opting out of that or when the viewport count has changed.
class VSG_DECLSPEC UpdateGraphicsPipelines : public Inherit<Visitor, UpdateGraphicsPipelines>
{
public:
Expand All @@ -43,7 +44,6 @@ namespace vsg
class VSG_DECLSPEC WindowResizeHandler : public Inherit<Visitor, WindowResizeHandler>
{
public:
ref_ptr<Context> context;
VkRect2D renderArea;
VkExtent2D previous_extent;
VkExtent2D new_extent;
Expand All @@ -63,7 +63,6 @@ namespace vsg
/// return true if the object was visited
bool visit(const Object* object, uint32_t index = 0);

void apply(BindGraphicsPipeline& bindPipeline) override;
void apply(Object& object) override;
void apply(ClearAttachments& clearAttachments) override;
void apply(View& view) override;
Expand Down
8 changes: 4 additions & 4 deletions include/vsg/io/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ namespace vsg

inline std::istream& operator>>(std::istream& input, CoordinateSpace& coordinateSpace)
{
std::string value;
input >> value;
std::string str;
input >> str;

if (value == "LINEAR")
if (str == "LINEAR")
coordinateSpace = CoordinateSpace::LINEAR;
else if (value == "sRGB")
else if (str == "sRGB")
coordinateSpace = CoordinateSpace::sRGB;
else
coordinateSpace = CoordinateSpace::NO_PREFERENCE;
Expand Down
1 change: 1 addition & 0 deletions include/vsg/state/DynamicState.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace vsg
{

/// DynamicState encapsulates VkPipelineDynamicStateCreateInfo settings passed when setting up GraphicsPipeline
/// By default, viewport and scissor are set to dynamic
class VSG_DECLSPEC DynamicState : public Inherit<GraphicsPipelineState, DynamicState>
{
public:
Expand Down
4 changes: 3 additions & 1 deletion include/vsg/state/GraphicsPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace vsg
/// Base class for setting up the various pipeline states with the VkGraphicsPipelineCreateInfo
/// Subclasses are ColorBlendState, DepthStencilState, DynamicState, InputAssemblyState,
/// MultisampleState, RasterizationState, TessellationState, VertexInputState and ViewportState.
class VSG_DECLSPEC GraphicsPipelineState : public Inherit<Object, GraphicsPipelineState>
class VSG_DECLSPEC GraphicsPipelineState : public Inherit<StateCommand, GraphicsPipelineState>
{
public:
GraphicsPipelineState() {}
Expand All @@ -36,6 +36,7 @@ namespace vsg
Mask mask = MASK_ALL;

virtual void apply(Context& context, VkGraphicsPipelineCreateInfo& pipelineInfo) const = 0;
void record(CommandBuffer&) const override {};

public:
int compare(const Object& rhs) const override;
Expand Down Expand Up @@ -95,6 +96,7 @@ namespace vsg

virtual ~Implementation();

GraphicsPipelineStates _pipelineStates;
VkPipeline _pipeline;

ref_ptr<Device> _device;
Expand Down
3 changes: 3 additions & 0 deletions include/vsg/state/ViewportState.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ namespace vsg
void write(Output& output) const override;
void apply(Context& context, VkGraphicsPipelineCreateInfo& pipelineInfo) const override;

/// enable ViewportState to be recorded via vkCmdSetScissor and vkCmdSetViewport
void record(CommandBuffer& commandBuffer) const override;

protected:
virtual ~ViewportState();
};
Expand Down
1 change: 1 addition & 0 deletions include/vsg/vk/ResourceRequirements.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace vsg
void apply(const DescriptorImage& descriptorImage) override;
void apply(const PagedLOD& plod) override;
void apply(const Light& light) override;
void apply(const RenderGraph& rg) override;
void apply(const View& view) override;
void apply(const DepthSorted& depthSorted) override;
void apply(const Layer& layer) override;
Expand Down
30 changes: 30 additions & 0 deletions include/vsg/vk/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,36 @@ namespace vsg
}
}

inline void push(const StateCommands& commands)
{
for (auto& command : commands)
{
stateStacks[command->slot].push(command);
}
dirty = true;
}

inline void pop(const StateCommands& commands)
{
for (const auto& command : commands)
{
stateStacks[command->slot].pop();
}
dirty = true;
}

inline void push(ref_ptr<StateCommand> command)
{
stateStacks[command->slot].push(command);
dirty = true;
}

inline void pop(ref_ptr<StateCommand> command)
{
stateStacks[command->slot].pop();
dirty = true;
}

inline void pushFrustum()
{
_frustumStack.push(Frustum(_frustumProjected, modelviewMatrixStack.top()));
Expand Down
12 changes: 3 additions & 9 deletions src/vsg/app/CompileTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,9 @@ void CompileTraversal::apply(RenderGraph& renderGraph)
auto previousDefaultPipelineStates = context->defaultPipelineStates;
auto previousOverridePipelineStates = context->overridePipelineStates;

mergeGraphicsPipelineStates(context->mask, context->defaultPipelineStates, renderGraph.viewportState);

context->renderPass = renderGraph.getRenderPass();
if (renderGraph.window)
{
mergeGraphicsPipelineStates(context->mask, context->defaultPipelineStates, ViewportState::create(renderGraph.window->extent2D()));
}
else if (renderGraph.framebuffer)
{
mergeGraphicsPipelineStates(context->mask, context->defaultPipelineStates, ViewportState::create(renderGraph.framebuffer->extent2D()));
}

if (context->renderPass)
{
Expand Down Expand Up @@ -438,7 +432,7 @@ void CompileTraversal::apply(View& view)
}

// assign view specific pipeline states
if (view.camera && view.camera->viewportState) mergeGraphicsPipelineStates(context->mask, context->defaultPipelineStates, view.camera->viewportState);
mergeGraphicsPipelineStates(context->mask, context->defaultPipelineStates, view.camera->viewportState);
mergeGraphicsPipelineStates(context->mask, context->overridePipelineStates, view.overridePipelineStates);

view.traverse(*this);
Expand Down
53 changes: 29 additions & 24 deletions src/vsg/app/RecordTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,19 +484,11 @@ void RecordTraversal::apply(const StateGroup& stateGroup)

//debug("Visiting StateGroup");

for (auto& command : stateGroup.stateCommands)
{
_state->stateStacks[command->slot].push(command);
}
_state->dirty = true;
_state->push(stateGroup.stateCommands);

stateGroup.traverse(*this);

for (const auto& command : stateGroup.stateCommands)
{
_state->stateStacks[command->slot].pop();
}
_state->dirty = true;
_state->pop(stateGroup.stateCommands);
}

void RecordTraversal::apply(const Commands& commands)
Expand Down Expand Up @@ -575,27 +567,40 @@ void RecordTraversal::apply(const View& view)
_state->inheritViewForLODScaling = (view.features & INHERIT_VIEWPOINT) != 0;
_state->setProjectionAndViewMatrix(view.camera->projectionMatrix->transform(), view.camera->viewMatrix->transform());

if (_viewDependentState && _viewDependentState->viewportData && view.camera->viewportState)
if (const auto& viewportState = view.camera->viewportState)
{
auto& viewportData = _viewDependentState->viewportData;
auto& viewports = view.camera->viewportState->viewports;
_state->push(viewportState);

auto dest_itr = viewportData->begin();
for (auto src_itr = viewports.begin();
dest_itr != viewportData->end() && src_itr != viewports.end();
++dest_itr, ++src_itr)
if (_viewDependentState)
{
auto& dest_viewport = *dest_itr;
vec4 src_viewport(src_itr->x, src_itr->y, src_itr->width, src_itr->height);
if (dest_viewport != src_viewport)
auto& viewportData = _viewDependentState->viewportData;
if (viewportData)
{
dest_viewport = src_viewport;
viewportData->dirty();
auto& viewports = viewportState->viewports;
auto dest_itr = viewportData->begin();
for (auto src_itr = viewports.begin();
dest_itr != viewportData->end() && src_itr != viewports.end();
++dest_itr, ++src_itr)
{
auto& dest_viewport = *dest_itr;
vec4 src_viewport(src_itr->x, src_itr->y, src_itr->width, src_itr->height);
if (dest_viewport != src_viewport)
{
dest_viewport = src_viewport;
viewportData->dirty();
}
}
}
}
}

view.traverse(*this);
view.traverse(*this);

_state->pop(viewportState);
}
else
{
view.traverse(*this);
}
}
else
{
Expand Down
30 changes: 12 additions & 18 deletions src/vsg/app/RenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
using namespace vsg;

RenderGraph::RenderGraph() :
viewportState(ViewportState::create()),
windowResizeHandler(WindowResizeHandler::create())
{
}

RenderGraph::RenderGraph(ref_ptr<Window> in_window, ref_ptr<View> in_view) :
window(in_window),
windowResizeHandler(WindowResizeHandler::create())
RenderGraph()
{
window = in_window;

if (in_view)
{
Expand All @@ -48,6 +49,8 @@ RenderGraph::RenderGraph(ref_ptr<Window> in_window, ref_ptr<View> in_view) :
renderArea.extent = window->extent2D();
}

viewportState->set(renderArea.offset.x, renderArea.offset.y, renderArea.extent.width, renderArea.extent.height);

// set up the clearValues based on the RenderPass's attachments.
setClearValues(window->clearColor(), VkClearDepthStencilValue{0.0f, 0});
}
Expand Down Expand Up @@ -144,9 +147,15 @@ void RenderGraph::accept(RecordTraversal& recordTraversal) const
VkCommandBuffer vk_commandBuffer = *(recordTraversal.getState()->_commandBuffer);
vkCmdBeginRenderPass(vk_commandBuffer, &renderPassInfo, contents);

// sync the viewportState and push
viewportState->set(renderArea.offset.x, renderArea.offset.y, renderArea.extent.width, renderArea.extent.height);
recordTraversal.getState()->push(viewportState);

// traverse the subgraph to place commands into the command buffer.
traverse(recordTraversal);

recordTraversal.getState()->pop(viewportState);

vkCmdEndRenderPass(vk_commandBuffer);
}

Expand All @@ -155,30 +164,15 @@ void RenderGraph::resized()
if (!windowResizeHandler) return;
if (!window && !framebuffer) return;

auto activeRenderPass = getRenderPass();
if (!activeRenderPass) return;

auto device = activeRenderPass->device;

if (!windowResizeHandler->context) windowResizeHandler->context = vsg::Context::create(device);
if (!getRenderPass()) return;

auto extent = getExtent();

windowResizeHandler->context->commandPool = nullptr;
windowResizeHandler->context->renderPass = activeRenderPass;
windowResizeHandler->renderArea = renderArea;
windowResizeHandler->previous_extent = previous_extent;
windowResizeHandler->new_extent = extent;
windowResizeHandler->visited.clear();

if (activeRenderPass->maxSamples != VK_SAMPLE_COUNT_1_BIT)
{
windowResizeHandler->context->overridePipelineStates.emplace_back(vsg::MultisampleState::create(activeRenderPass->maxSamples));
}

// make sure the device is idle before we recreate any Vulkan objects
vkDeviceWaitIdle(*(device));

traverse(*windowResizeHandler);

windowResizeHandler->scale_rect(renderArea);
Expand Down
Loading
Loading