Loading...
Searching...
No Matches
GPUBufferScatter.hpp
1#pragma once
2#include <Gfx/Graph/RenderState.hpp>
3
4#include <private/qrhi_p.h>
5
6#include <score_plugin_gfx_export.h>
7
8namespace score::gfx
9{
10
29{
30public:
32 enum class SourceFormat : uint32_t
33 {
34 Float32 = 0,
35 Unorm8 = 1,
36 Half = 2,
37 Uint32 = 3,
38 Sint32 = 4,
39 };
41 enum class DestinationKind : uint32_t
42 {
43 Float = 0,
44 Uint = 1,
45 Int = 2,
46 };
47
48 struct Params
49 {
50 QRhiBuffer* staging{}; // Source SSBO (raw CPU data, uploaded as-is)
51 QRhiBuffer* output{}; // Destination SSBO (format-converted result)
52 uint32_t element_count{};
53 uint32_t src_components{}; // Components per source element (1-4)
54 uint32_t dst_components{}; // Components per destination element (1-4)
55 uint32_t src_stride_bytes{}; // Stride between source elements, in bytes
56 uint32_t src_offset_bytes{}; // Offset of the first element in the source, in bytes
57 uint32_t dst_stride_floats{}; // Stride between destination elements (in words, 0 = dst_components)
58 SourceFormat src_format{SourceFormat::Float32};
59 DestinationKind dst_kind{DestinationKind::Float};
60 };
61
67 SCORE_PLUGIN_GFX_TEST_EXPORT static void scatterOnCpu(
68 const Params& p, const char* src, int64_t src_size, char* dst, int64_t dst_size);
69
70 bool init(RenderState& state);
71 void release();
72
75 {
76 QRhiShaderResourceBindings* srb{};
77 QRhiBuffer* paramsUBO{};
78 };
79 PreparedOp prepare(QRhi& rhi, const Params& p);
80
82 void updateParams(QRhiResourceUpdateBatch& res, const PreparedOp& op, const Params& p);
83
85 void dispatch(QRhiCommandBuffer& cb, const PreparedOp& op, const Params& p);
86
87 static constexpr int LocalSize = 256;
88
93 {
94 int x{};
95 int y{};
96 int z{};
97 };
98
99private:
104 DispatchDims computeDispatchDims(uint32_t element_count) const;
105
106 QRhiComputePipeline* m_pipeline{};
107 QShader m_shader;
108 int m_maxWorkgroupsPerDim{65535};
109};
110
111} // namespace score::gfx
GPU-side buffer format conversion (scatter).
Definition GPUBufferScatter.hpp:29
static void scatterOnCpu(const Params &p, const char *src, int64_t src_size, char *dst, int64_t dst_size)
The scatter on the CPU, for a backend without compute: decodes p.element_count elements of src (src_s...
Definition GPUBufferScatter.cpp:327
void updateParams(QRhiResourceUpdateBatch &res, const PreparedOp &op, const Params &p)
Update params UBO and SRB. Call BEFORE beginComputePass (needs a live batch).
Definition GPUBufferScatter.cpp:258
void dispatch(QRhiCommandBuffer &cb, const PreparedOp &op, const Params &p)
Dispatch the scatter. Must be called inside beginComputePass/endComputePass.
Definition GPUBufferScatter.cpp:307
DestinationKind
What the destination component holds: float, uint or int.
Definition GPUBufferScatter.hpp:42
SourceFormat
How a source component is stored.
Definition GPUBufferScatter.hpp:33
@ Unorm8
0..255 read as 0..1 (the byte value for an integer destination)
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Definition GPUBufferScatter.hpp:93
Definition GPUBufferScatter.hpp:49
Create or update an SRB+UBO for a specific scatter operation.
Definition GPUBufferScatter.hpp:75
Global state associated to a rendering context.
Definition RenderState.hpp:40