Skip to content

Commit

Permalink
Subpass not required for depth prepass and jump flood seeding.
Browse files Browse the repository at this point in the history
  • Loading branch information
stripe2933 authored and LEE KYOUNGHEON committed Dec 28, 2024
1 parent 86e749c commit 74e5d7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
18 changes: 7 additions & 11 deletions impl/vulkan/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,33 +132,29 @@ auto vk_gltf_viewer::vulkan::Frame::update(const ExecutionTask &task) -> UpdateR
};

const auto depthPrepassCriteriaGetter = [&](const gltf::AssetPrimitiveInfo &primitiveInfo) {
CommandSeparationCriteria result {
.subpass = 0U,
CommandSeparationCriteriaNoShading result{
.pipeline = *sharedData.depthRenderer,
.indexType = primitiveInfo.indexInfo.transform([](const auto &info) { return info.type; }),
.indexType = primitiveInfo.indexInfo.transform([](const auto& info) { return info.type; }),
.cullMode = vk::CullModeFlagBits::eBack,
};

if (primitiveInfo.materialIndex) {
const fastgltf::Material &material = task.gltf->asset.materials[*primitiveInfo.materialIndex];
result.subpass = material.alphaMode == fastgltf::AlphaMode::Blend;
const fastgltf::Material& material = task.gltf->asset.materials[*primitiveInfo.materialIndex];
result.pipeline = sharedData.getDepthPrepassRenderer(material.alphaMode);
result.cullMode = material.doubleSided ? vk::CullModeFlagBits::eNone : vk::CullModeFlagBits::eBack;
}
return result;
};
};

const auto jumpFloodSeedCriteriaGetter = [&](const gltf::AssetPrimitiveInfo &primitiveInfo) {
CommandSeparationCriteria result {
.subpass = 0U,
const auto jumpFloodSeedCriteriaGetter = [&](const gltf::AssetPrimitiveInfo& primitiveInfo) {
CommandSeparationCriteriaNoShading result {
.pipeline = *sharedData.jumpFloodSeedRenderer,
.indexType = primitiveInfo.indexInfo.transform([](const auto &info) { return info.type; }),
.cullMode = vk::CullModeFlagBits::eBack,
};

if (primitiveInfo.materialIndex) {
const fastgltf::Material &material = task.gltf->asset.materials[*primitiveInfo.materialIndex];
result.subpass = material.alphaMode == fastgltf::AlphaMode::Blend;
result.pipeline = sharedData.getJumpFloodSeedRenderer(material.alphaMode);
result.cullMode = material.doubleSided ? vk::CullModeFlagBits::eNone : vk::CullModeFlagBits::eBack;
}
Expand Down Expand Up @@ -604,7 +600,7 @@ auto vk_gltf_viewer::vulkan::Frame::recordScenePrepassCommands(vk::CommandBuffer
bool pushConstantBound = false;
} resourceBindingState{};

const auto drawPrimitives = [&](const CriteriaSeparatedIndirectDrawCommands &indirectDrawCommandBuffers) {
const auto drawPrimitives = [&](const auto &indirectDrawCommandBuffers) {
for (const auto &[criteria, indirectDrawCommandBuffer] : indirectDrawCommandBuffers) {
if (resourceBindingState.pipeline != criteria.pipeline) {
cb.bindPipeline(vk::PipelineBindPoint::eGraphics, resourceBindingState.pipeline = criteria.pipeline);
Expand Down
19 changes: 14 additions & 5 deletions interface/vulkan/Frame.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ struct std::less<CommandSeparationCriteria> {
[[nodiscard]] bool operator()(std::uint32_t lhs, const CommandSeparationCriteria &rhs) const noexcept { return lhs < rhs.subpass; }
};

struct CommandSeparationCriteriaNoShading {
vk::Pipeline pipeline;
std::optional<vk::IndexType> indexType;
vk::CullModeFlagBits cullMode;

[[nodiscard]] std::strong_ordering operator<=>(const CommandSeparationCriteriaNoShading&) const noexcept = default;
};

namespace vk_gltf_viewer::vulkan {
export class Frame {
public:
Expand Down Expand Up @@ -143,7 +151,8 @@ namespace vk_gltf_viewer::vulkan {
[[nodiscard]] vk::Semaphore getSwapchainImageReadySemaphore() const noexcept { return *compositionFinishSema; }

private:
using CriteriaSeparatedIndirectDrawCommands = std::map<CommandSeparationCriteria, std::variant<buffer::IndirectDrawCommands<false>, buffer::IndirectDrawCommands<true>>>;
template <typename Criteria>
using CriteriaSeparatedIndirectDrawCommands = std::map<Criteria, std::variant<buffer::IndirectDrawCommands<false>, buffer::IndirectDrawCommands<true>>>;

class PassthruResources {
public:
Expand Down Expand Up @@ -174,20 +183,20 @@ namespace vk_gltf_viewer::vulkan {

struct RenderingNodes {
std::unordered_set<std::uint16_t> indices;
CriteriaSeparatedIndirectDrawCommands indirectDrawCommandBuffers;
CriteriaSeparatedIndirectDrawCommands depthPrepassIndirectDrawCommandBuffers;
CriteriaSeparatedIndirectDrawCommands<CommandSeparationCriteria> indirectDrawCommandBuffers;
CriteriaSeparatedIndirectDrawCommands<CommandSeparationCriteriaNoShading> depthPrepassIndirectDrawCommandBuffers;
};

struct SelectedNodes {
std::unordered_set<std::uint16_t> indices;
CriteriaSeparatedIndirectDrawCommands jumpFloodSeedIndirectDrawCommandBuffers;
CriteriaSeparatedIndirectDrawCommands<CommandSeparationCriteriaNoShading> jumpFloodSeedIndirectDrawCommandBuffers;
glm::vec4 outlineColor;
float outlineThickness;
};

struct HoveringNode {
std::uint16_t index;
CriteriaSeparatedIndirectDrawCommands jumpFloodSeedIndirectDrawCommandBuffers;
CriteriaSeparatedIndirectDrawCommands<CommandSeparationCriteriaNoShading> jumpFloodSeedIndirectDrawCommandBuffers;
glm::vec4 outlineColor;
float outlineThickness;
};
Expand Down

0 comments on commit 74e5d7c

Please sign in to comment.