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_intf.hpp"
8#include "gfx_surface_vulkan_intf.hpp"
9#include "gfx_device_vulkan_impl.hpp"
10#include "draw_context_intf.hpp"
11#include "../macros.hpp"
12#include <vulkan/vulkan.hpp>
13
14hi_export_module(hikogui.GFX : gfx_pipeline_tone_mapper_impl);
15
16hi_export namespace hi { inline namespace v1 {
17
18inline void gfx_pipeline_tone_mapper::draw_in_command_buffer(vk::CommandBuffer commandBuffer, draw_context const& context)
19{
20 gfx_pipeline::draw_in_command_buffer(commandBuffer, context);
21
22 hi_axiom_not_null(device());
23 device()->tone_mapper_pipeline->drawInCommandBuffer(commandBuffer);
24
25 _push_constants.saturation = context.saturation;
26 commandBuffer.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, sizeof(push_constants), &_push_constants);
27
28 device()->cmdBeginDebugUtilsLabelEXT(commandBuffer, "tone mapping");
29 commandBuffer.draw(3, 1, 0, 0);
30 device()->cmdEndDebugUtilsLabelEXT(commandBuffer);
31}
32
33inline std::vector<vk::PipelineShaderStageCreateInfo> gfx_pipeline_tone_mapper::createShaderStages() const
34{
35 hi_axiom_not_null(device());
36 return device()->tone_mapper_pipeline->shaderStages;
37}
38
39inline std::vector<vk::DescriptorSetLayoutBinding> gfx_pipeline_tone_mapper::createDescriptorSetLayoutBindings() const
40{
41 return {
42 {0, // binding
43 vk::DescriptorType::eInputAttachment,
44 1, // descriptorCount
45 vk::ShaderStageFlagBits::eFragment}};
46}
47
48inline std::vector<vk::WriteDescriptorSet> gfx_pipeline_tone_mapper::createWriteDescriptorSet() const
49{
50 return {{
51 descriptorSet,
52 0, // destBinding
53 0, // arrayElement
54 1, // descriptorCount
55 vk::DescriptorType::eInputAttachment,
56 &surface->colorDescriptorImageInfos[0],
57 nullptr, // bufferInfo
58 nullptr // texelBufferView
59 }};
60}
61
62inline size_t gfx_pipeline_tone_mapper::getDescriptorSetVersion() const
63{
64 return 1;
65}
66
67inline std::vector<vk::PushConstantRange> gfx_pipeline_tone_mapper::createPushConstantRanges() const
68{
69 return push_constants::pushConstantRanges();
70}
71
72inline vk::PipelineDepthStencilStateCreateInfo gfx_pipeline_tone_mapper::getPipelineDepthStencilStateCreateInfo() const
73{
74 // No depth buffering in the Tone Mapper
75 return {
76 vk::PipelineDepthStencilStateCreateFlags(),
77 VK_FALSE, // depthTestEnable;
78 VK_FALSE, // depthWriteEnable;
79 vk::CompareOp::eAlways, // depthCompareOp
80 VK_FALSE, // depthBoundsTestEnable
81 VK_FALSE, // stencilTestEnable,
82 vk::StencilOpState(), // front
83 vk::StencilOpState(), // back
84 0.0f, // minDepthBounds
85 1.0f, // maxDepthBounds
86 };
87}
88
89inline gfx_pipeline_tone_mapper::device_shared::device_shared(gfx_device const &device) : device(device)
90{
91 buildShaders();
92}
93
94inline gfx_pipeline_tone_mapper::device_shared::~device_shared() {}
95
96inline void gfx_pipeline_tone_mapper::device_shared::destroy(gfx_device const *vulkanDevice)
97{
98 hi_assert_not_null(vulkanDevice);
99
100 teardownShaders(vulkanDevice);
101}
102
103inline void gfx_pipeline_tone_mapper::device_shared::drawInCommandBuffer(vk::CommandBuffer const &commandBuffer)
104{
105 commandBuffer.bindIndexBuffer(device.quadIndexBuffer, 0, vk::IndexType::eUint16);
106}
107
108inline void gfx_pipeline_tone_mapper::device_shared::buildShaders()
109{
110 vertexShaderModule = device.loadShader(URL("resource:tone_mapper_vulkan.vert.spv"));
111 fragmentShaderModule = device.loadShader(URL("resource:tone_mapper_vulkan.frag.spv"));
112
113 shaderStages = {
114 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main"},
115 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main"}};
116}
117
118inline void gfx_pipeline_tone_mapper::device_shared::teardownShaders(gfx_device const*vulkanDevice)
119{
120 hi_assert_not_null(vulkanDevice);
121
122 vulkanDevice->destroy(vertexShaderModule);
123 vulkanDevice->destroy(fragmentShaderModule);
124}
125
126}} // namespace hi::inline v1::gfx_pipeline_tone_mapper
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Universal Resource Locator.
Definition URL.hpp:58