HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gfx_pipeline_tone_mapper_vulkan_impl.hpp
1// Copyright Take Vos 2020-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "gfx_pipeline_tone_mapper_vulkan.hpp"
8#include "gfx_surface_vulkan.hpp"
9#include "gfx_device_vulkan_impl.hpp"
10#include "draw_context.hpp"
11#include "../macros.hpp"
12
13namespace hi { inline namespace v1 {
14
15inline void gfx_pipeline_tone_mapper::draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context const& context)
16{
17 gfx_pipeline::draw_in_command_buffer(commandBuffer, context);
18
19 hi_axiom_not_null(device());
20 device()->tone_mapper_pipeline->drawInCommandBuffer(commandBuffer);
21
22 _push_constants.saturation = context.saturation;
23 commandBuffer.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, sizeof(push_constants), &_push_constants);
24
25 device()->cmdBeginDebugUtilsLabelEXT(commandBuffer, "tone mapping");
26 commandBuffer.draw(3, 1, 0, 0);
27 device()->cmdEndDebugUtilsLabelEXT(commandBuffer);
28}
29
30inline std::vector<vk::PipelineShaderStageCreateInfo> gfx_pipeline_tone_mapper::createShaderStages() const
31{
32 hi_axiom_not_null(device());
33 return device()->tone_mapper_pipeline->shaderStages;
34}
35
36inline std::vector<vk::DescriptorSetLayoutBinding> gfx_pipeline_tone_mapper::createDescriptorSetLayoutBindings() const
37{
38 return {
39 {0, // binding
40 vk::DescriptorType::eInputAttachment,
41 1, // descriptorCount
42 vk::ShaderStageFlagBits::eFragment}};
43}
44
45inline std::vector<vk::WriteDescriptorSet> gfx_pipeline_tone_mapper::createWriteDescriptorSet() const
46{
47 return {{
48 descriptorSet,
49 0, // destBinding
50 0, // arrayElement
51 1, // descriptorCount
52 vk::DescriptorType::eInputAttachment,
53 &surface->colorDescriptorImageInfos[0],
54 nullptr, // bufferInfo
55 nullptr // texelBufferView
56 }};
57}
58
59inline size_t gfx_pipeline_tone_mapper::getDescriptorSetVersion() const
60{
61 return 1;
62}
63
64inline std::vector<vk::PushConstantRange> gfx_pipeline_tone_mapper::createPushConstantRanges() const
65{
66 return push_constants::pushConstantRanges();
67}
68
69inline vk::PipelineDepthStencilStateCreateInfo gfx_pipeline_tone_mapper::getPipelineDepthStencilStateCreateInfo() const
70{
71 // No depth buffering in the Tone Mapper
72 return {
73 vk::PipelineDepthStencilStateCreateFlags(),
74 VK_FALSE, // depthTestEnable;
75 VK_FALSE, // depthWriteEnable;
76 vk::CompareOp::eAlways, // depthCompareOp
77 VK_FALSE, // depthBoundsTestEnable
78 VK_FALSE, // stencilTestEnable,
79 vk::StencilOpState(), // front
80 vk::StencilOpState(), // back
81 0.0f, // minDepthBounds
82 1.0f, // maxDepthBounds
83 };
84}
85
86inline gfx_pipeline_tone_mapper::device_shared::device_shared(gfx_device const &device) : device(device)
87{
88 buildShaders();
89}
90
91inline gfx_pipeline_tone_mapper::device_shared::~device_shared() {}
92
93inline void gfx_pipeline_tone_mapper::device_shared::destroy(gfx_device const *vulkanDevice)
94{
95 hi_assert_not_null(vulkanDevice);
96
97 teardownShaders(vulkanDevice);
98}
99
100inline void gfx_pipeline_tone_mapper::device_shared::drawInCommandBuffer(vk::CommandBuffer const &commandBuffer)
101{
102 commandBuffer.bindIndexBuffer(device.quadIndexBuffer, 0, vk::IndexType::eUint16);
103}
104
105inline void gfx_pipeline_tone_mapper::device_shared::buildShaders()
106{
107 vertexShaderModule = device.loadShader(URL("resource:shaders/tone_mapper.vert.spv"));
108 fragmentShaderModule = device.loadShader(URL("resource:shaders/tone_mapper.frag.spv"));
109
110 shaderStages = {
111 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main"},
112 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main"}};
113}
114
115inline void gfx_pipeline_tone_mapper::device_shared::teardownShaders(gfx_device const*vulkanDevice)
116{
117 hi_assert_not_null(vulkanDevice);
118
119 vulkanDevice->destroy(vertexShaderModule);
120 vulkanDevice->destroy(fragmentShaderModule);
121}
122
123}} // namespace hi::inline v1::gfx_pipeline_tone_mapper
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Universal Resource Locator.
Definition URL.hpp:51