MayaFlux 1.0.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 */
30struct MAYAFLUX_API TextureAccess {
31 const void* data_ptr = nullptr;
32 size_t byte_count = 0;
33 GpuDataFormat format = GpuDataFormat::VEC4_F32;
34
35 /**
36 * @brief Bytes per texel for this format.
37 */
38 [[nodiscard]] size_t bytes_per_texel() const noexcept
39 {
41 }
42
43 /**
44 * @brief Number of channels (components per texel).
45 */
46 [[nodiscard]] uint32_t channel_count() const noexcept;
47
48 /**
49 * @brief True when data_ptr points into conversion_buffer rather than
50 * the original variant storage (i.e. a vec3 promotion occurred).
51 */
52 [[nodiscard]] bool was_promoted() const noexcept
53 {
54 return !conversion_buffer.empty();
55 }
56
57 /**
58 * @brief Promotion buffer. Non-empty only for vec3 → vec4 promotion.
59 * Keeps promoted data alive for the lifetime of this struct.
60 */
61 std::vector<std::byte> conversion_buffer;
62};
63
64/**
65 * @brief Extract a TextureAccess from a DataVariant.
66 * @param variant Source data.
67 * @return Populated TextureAccess, or std::nullopt on incompatible type.
68 *
69 * DataVariant active type → GpuDataFormat mapping:
70 * vector<uint8_t> → UINT8
71 * vector<uint16_t> → UINT16
72 * vector<uint32_t> → UINT32
73 * vector<float> → FLOAT32
74 * vector<double> → FLOAT32 (narrowed, warned)
75 * vector<complex<float>> → VEC2_F32 (identical layout to glm::vec2)
76 * vector<glm::vec2> → VEC2_F32
77 * vector<glm::vec3> → VEC4_F32 (W=0 promotion, warned)
78 * vector<glm::vec4> → VEC4_F32
79 * vector<complex<double>> → std::nullopt (logged error)
80 * vector<glm::mat4> → std::nullopt (logged error)
81 */
82[[nodiscard]] MAYAFLUX_API std::optional<TextureAccess>
83as_texture_access(const DataVariant& variant);
84
85} // namespace MayaFlux::Kakshya
bool format
size_t gpu_data_format_bytes(GpuDataFormat fmt) noexcept
Byte size of one element of a GpuDataFormat.
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:70
GpuDataFormat
GPU data formats with explicit precision levels.
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.
Memory-compatible view of a DataVariant for texel upload.