MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
UVFieldProcessor.cpp
Go to the documentation of this file.
2
4
9
10namespace MayaFlux::Buffers {
11
13 : ComputeProcessor("uv_field.comp.spv", 64)
14{
16
17 m_config.bindings["vertices"] = ShaderBinding(0, 0, vk::DescriptorType::eStorageBuffer);
18
19 m_config.bindings["tex_sampler"] = ShaderBinding(0, 1, vk::DescriptorType::eCombinedImageSampler);
20}
21
22// =============================================================================
23// Projection configuration
24// =============================================================================
25
27{
28 m_pc.mode = static_cast<uint32_t>(mode);
29}
30
31void UVFieldProcessor::set_origin(const glm::vec3& origin)
32{
33 m_pc.param_origin = origin;
34}
35
36void UVFieldProcessor::set_axis(const glm::vec3& axis)
37{
38 m_pc.param_axis = axis;
39}
40
45
47{
48 m_pc.param_aux = aux;
49}
50
51// =============================================================================
52// Texture source
53// =============================================================================
54
56 std::shared_ptr<Core::VKImage> image,
58{
59 m_texture = std::move(image);
60 m_sampler_config = config;
61 m_sampler = nullptr;
62 m_pc.write_colour = m_texture ? 1U : 0U;
64}
65
67{
68 m_texture = nullptr;
69 m_sampler = nullptr;
72}
73
74// =============================================================================
75// ShaderProcessor hooks
76// =============================================================================
77
78void UVFieldProcessor::on_attach(const std::shared_ptr<Buffer>& buffer)
79{
81
82 auto vk_buf = std::dynamic_pointer_cast<VKBuffer>(buffer);
83 if (!vk_buf) {
85 "UVFieldProcessor requires a VKBuffer");
86 return;
87 }
88
89 bind_buffer("vertices", vk_buf);
90
92 "UVFieldProcessor attached ({} bytes)", vk_buf->get_size_bytes());
93}
94
96{
97 if (m_descriptor_set_ids.empty()) {
98 return;
99 }
100
101 auto& foundry = Portal::Graphics::get_shader_foundry();
102
103 if (!m_texture)
104 return;
105
106 if (!m_sampler) {
108 m_sampler = forge.get_or_create(m_sampler_config);
109 }
110
111 if (!m_sampler) {
113 "UVFieldProcessor: sampler creation failed, texture will not be sampled");
114 return;
115 }
116
117 foundry.update_descriptor_image(
119 1,
120 m_texture->get_image_view(),
121 m_sampler,
122 vk::ImageLayout::eShaderReadOnlyOptimal);
123
125 "UVFieldProcessor: texture descriptor written (binding 1, view={:p}, sampler={:p})",
126 static_cast<void*>(static_cast<VkImageView>(m_texture->get_image_view())),
127 static_cast<void*>(static_cast<VkSampler>(m_sampler)));
128}
129
132 const std::shared_ptr<VKBuffer>& buffer)
133{
134 if (!buffer) {
135 return false;
136 }
137
138 m_pc.vertex_count = static_cast<uint32_t>(buffer->get_size_bytes() / sizeof(Kakshya::MeshVertex));
139 if (m_pc.vertex_count == 0) {
140 return false;
141 }
142
144 "UVFieldProcessor dispatch: {} vertices, mode={}, write_colour={}, has_texture={}",
146
148 return true;
149}
150
151} // namespace MayaFlux::Buffers
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:64
float scale
virtual void on_attach(const std::shared_ptr< Buffer > &)
Called when this processor is attached to a buffer.
Specialized ShaderProcessor for Compute Pipelines.
void set_push_constant_data(const T &data)
Update push constant data (type-safe)
void bind_buffer(const std::string &descriptor_name, const std::shared_ptr< VKBuffer > &buffer)
Bind a VKBuffer to a named shader descriptor.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
void clear_texture()
Remove the texture source.
void set_texture(std::shared_ptr< Core::VKImage > image, const Portal::Graphics::SamplerConfig &config={})
Bind a texture to sample colour from at computed UV coordinates.
void set_axis(const glm::vec3 &axis)
Set projection axis.
Portal::Graphics::SamplerConfig m_sampler_config
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before each process callback.
void set_scale(float scale)
Set UV scale.
void set_origin(const glm::vec3 &origin)
Set world-space origin of the projection.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
std::shared_ptr< Core::VKImage > m_texture
void set_projection(UVProjectionMode mode)
Set projection mode.
void on_descriptors_created() override
Called after descriptor sets are created.
void set_aux(float aux)
Set auxiliary projection parameter.
UVProjectionMode
Projection mode encoded in push constants for uv_field.comp.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Describes how a VKBuffer binds to a shader descriptor.
std::unordered_map< std::string, ShaderBinding > bindings
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)