MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextureAccess.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "NDData.hpp"
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @struct TextureAccess
9 * @brief Memory-compatible view of a DataVariant for texel upload.
10 *
11 * Analogous to VertexLayout: describes what the data IS in memory terms —
12 * pointer, byte count, and the GpuDataFormat that faithfully represents it —
13 * with no knowledge of Vulkan format enumerants or Portal types.
14 * The Portal layer maps GpuDataFormat to ImageFormat or vk::Format.
15 *
16 * For types that map directly (vec2, vec4, float, uint8_t, complex<float>)
17 * data_ptr points into the variant's own storage — zero copy.
18 *
19 * For glm::vec3, which has no universally-supported 3-channel float sampled
20 * image format in Vulkan, the variant is promoted to VEC4_F32 with W=0.
21 * In this case conversion_buffer holds the promoted data and data_ptr
22 * points into it. The promotion is logged as a warning.
23 *
24 * Rejected types (as_texture_access returns std::nullopt, logs error):
25 * vector<complex<double>> RG64F is not a sampled image format in Vulkan.
26 * vector<glm::mat4> Ambiguous layout; caller must unpack to vec4 first.
27 * VEC2_F64 / VEC3_F64 / VEC4_F64 variants do not exist in DataVariant —
28 * included in GpuDataFormat for buffer use only.
29 */
31 const void* data_ptr = nullptr;
32 size_t byte_count = 0;
34
35 /**
36 * @brief Bytes per texel for this format.
37 */
38 [[nodiscard]] size_t bytes_per_texel() const noexcept;
39
40 /**
41 * @brief Number of channels (components per texel).
42 */
43 [[nodiscard]] uint32_t channel_count() const noexcept;
44
45 /**
46 * @brief True when data_ptr points into conversion_buffer rather than
47 * the original variant storage (i.e. a vec3 promotion occurred).
48 */
49 [[nodiscard]] bool was_promoted() const noexcept
50 {
51 return !conversion_buffer.empty();
52 }
53
54 /**
55 * @brief Promotion buffer. Non-empty only for vec3 → vec4 promotion.
56 * Keeps promoted data alive for the lifetime of this struct.
57 */
58 std::vector<std::byte> conversion_buffer;
59};
60
61/**
62 * @brief Extract a TextureAccess from a DataVariant.
63 * @param variant Source data.
64 * @return Populated TextureAccess, or std::nullopt on incompatible type.
65 *
66 * DataVariant active type → GpuDataFormat mapping:
67 * vector<uint8_t> → UINT8
68 * vector<uint16_t> → UINT16
69 * vector<uint32_t> → UINT32
70 * vector<float> → FLOAT32
71 * vector<double> → FLOAT32 (narrowed, warned)
72 * vector<complex<float>> → VEC2_F32 (identical layout to glm::vec2)
73 * vector<glm::vec2> → VEC2_F32
74 * vector<glm::vec3> → VEC4_F32 (W=0 promotion, warned)
75 * vector<glm::vec4> → VEC4_F32
76 * vector<complex<double>> → std::nullopt (logged error)
77 * vector<glm::mat4> → std::nullopt (logged error)
78 */
79[[nodiscard]] MAYAFLUX_API std::optional<TextureAccess>
80as_texture_access(const DataVariant& variant);
81
82} // namespace MayaFlux::Kakshya
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:76
GpuDataFormat
GPU data formats with explicit precision levels.
Definition NDData.hpp:11
std::optional< TextureAccess > as_texture_access(const DataVariant &variant)
Extract a TextureAccess from a DataVariant.
std::vector< std::byte > conversion_buffer
Promotion buffer.
size_t bytes_per_texel() const noexcept
Bytes per texel for this format.
uint32_t channel_count() const noexcept
Number of channels (components per texel).
bool was_promoted() const noexcept
True when data_ptr points into conversion_buffer rather than the original variant storage (i....
Memory-compatible view of a DataVariant for texel upload.