7#include "gfx_pipeline_alpha_vulkan.hpp"
8#include "gfx_device_vulkan_impl.hpp"
9#include "../macros.hpp"
11namespace hi {
inline namespace v1 {
15inline std::vector<vk::PipelineColorBlendAttachmentState> gfx_pipeline_alpha::getPipelineColorBlendAttachmentStates()
const
19 vk::BlendFactor::eOne,
20 vk::BlendFactor::eZero,
22 vk::BlendFactor::eOne,
23 vk::BlendFactor::eZero,
25 vk::ColorComponentFlagBits::eA}};
28inline void gfx_pipeline_alpha::draw_in_command_buffer(vk::CommandBuffer commandBuffer,
draw_context const& context)
30 gfx_pipeline::draw_in_command_buffer(commandBuffer, context);
32 hi_axiom_not_null(device());
33 device()->flushAllocation(vertexBufferAllocation, 0, vertexBufferData.size() *
sizeof(
vertex));
35 std::vector<vk::Buffer> tmpvertexBuffers = {vertexBuffer};
36 std::vector<vk::DeviceSize> tmpOffsets = {0};
37 hi_assert(tmpvertexBuffers.
size() == tmpOffsets.
size());
39 device()->alpha_pipeline->drawInCommandBuffer(commandBuffer);
41 commandBuffer.bindVertexBuffers(0, tmpvertexBuffers, tmpOffsets);
44 pushConstants.viewportScale = scale2{2.0f / extent.width, 2.0f / extent.height};
45 commandBuffer.pushConstants(
47 vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
52 hilet numberOfRectangles = vertexBufferData.size() / 4;
53 hilet numberOfTriangles = numberOfRectangles * 2;
55 device()->cmdBeginDebugUtilsLabelEXT(commandBuffer,
"draw alpha overlays");
57 device()->cmdEndDebugUtilsLabelEXT(commandBuffer);
60inline std::vector<vk::PipelineShaderStageCreateInfo> gfx_pipeline_alpha::createShaderStages()
const
62 hi_axiom_not_null(device());
63 return device()->alpha_pipeline->shaderStages;
66inline std::vector<vk::DescriptorSetLayoutBinding> gfx_pipeline_alpha::createDescriptorSetLayoutBindings()
const
71inline std::vector<vk::WriteDescriptorSet> gfx_pipeline_alpha::createWriteDescriptorSet()
const
76inline size_t gfx_pipeline_alpha::getDescriptorSetVersion()
const
81inline std::vector<vk::PushConstantRange> gfx_pipeline_alpha::createPushConstantRanges()
const
83 return push_constants::pushConstantRanges();
86inline vk::VertexInputBindingDescription gfx_pipeline_alpha::createVertexInputBindingDescription()
const
88 return vertex::inputBindingDescription();
91inline std::vector<vk::VertexInputAttributeDescription> gfx_pipeline_alpha::createVertexInputAttributeDescriptions()
const
93 return vertex::inputAttributeDescriptions();
96inline void gfx_pipeline_alpha::build_vertex_buffers()
98 using vertexIndexType = uint16_t;
99 constexpr ssize_t numberOfVertices = 1 << (
sizeof(vertexIndexType) * CHAR_BIT);
101 vk::BufferCreateInfo
const bufferCreateInfo = {
102 vk::BufferCreateFlags(),
103 sizeof(
vertex) * numberOfVertices,
104 vk::BufferUsageFlagBits::eVertexBuffer,
105 vk::SharingMode::eExclusive};
106 VmaAllocationCreateInfo allocationCreateInfo = {};
107 allocationCreateInfo.flags = VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT;
108 allocationCreateInfo.pUserData =
const_cast<char *
>(
"alpha-pipeline vertex buffer");
109 allocationCreateInfo.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
111 hi_axiom_not_null(device());
112 std::tie(vertexBuffer, vertexBufferAllocation) = device()->createBuffer(bufferCreateInfo, allocationCreateInfo);
113 device()->setDebugUtilsObjectNameEXT(vertexBuffer,
"alpha-pipeline vertex buffer");
114 vertexBufferData = device()->mapMemory<
vertex>(vertexBufferAllocation);
117inline void gfx_pipeline_alpha::teardown_vertex_buffers()
119 hi_axiom_not_null(device());
120 device()->unmapMemory(vertexBufferAllocation);
121 device()->destroyBuffer(vertexBuffer, vertexBufferAllocation);
124inline gfx_pipeline_alpha::device_shared::device_shared(gfx_device
const& device) : device(device)
129inline gfx_pipeline_alpha::device_shared::~device_shared() {}
133 hi_assert_not_null(vulkanDevice);
134 teardownShaders(vulkanDevice);
137inline void gfx_pipeline_alpha::device_shared::drawInCommandBuffer(vk::CommandBuffer
const& commandBuffer)
139 commandBuffer.bindIndexBuffer(device.quadIndexBuffer, 0, vk::IndexType::eUint16);
142inline void gfx_pipeline_alpha::device_shared::place_vertices(vector_span<vertex>& vertices,
aarectangle clipping_rectangle, quad box,
float alpha)
144 hilet clipping_rectangle_ = sfloat_rgba32{clipping_rectangle};
146 vertices.emplace_back(box.p0, clipping_rectangle_, alpha);
147 vertices.emplace_back(box.p1, clipping_rectangle_, alpha);
148 vertices.emplace_back(box.p2, clipping_rectangle_, alpha);
149 vertices.emplace_back(box.p3, clipping_rectangle_, alpha);
152inline void gfx_pipeline_alpha::device_shared::buildShaders()
154 vertexShaderModule = device.loadShader(URL(
"resource:shaders/alpha.vert.spv"));
155 device.setDebugUtilsObjectNameEXT(vertexShaderModule,
"alpha-pipeline vertex shader");
157 fragmentShaderModule = device.loadShader(URL(
"resource:shaders/alpha.frag.spv"));
158 device.setDebugUtilsObjectNameEXT(vertexShaderModule,
"alpha-pipeline fragment shader");
161 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule,
"main"},
162 {vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule,
"main"}};
165inline void gfx_pipeline_alpha::device_shared::teardownShaders(gfx_device
const*vulkanDevice)
167 hi_assert_not_null(vulkanDevice);
168 vulkanDevice->destroy(vertexShaderModule);
169 vulkanDevice->destroy(fragmentShaderModule);
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
std::ptrdiff_t ssize_t
Signed size/index into an array.
Definition misc.hpp:33
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:208
Definition gfx_pipeline_alpha_vulkan.hpp:22
Definition gfx_pipeline_alpha_vulkan.hpp:56
void destroy(gfx_device const *vulkanDevice)
Definition gfx_pipeline_alpha_vulkan_impl.hpp:131