Loading...
Searching...
No Matches
RhiIndirectCompat.hpp
1#pragma once
2
29#include <QtGui/private/qrhi_p.h>
30
31#include <type_traits>
32
33namespace score::gfx
34{
35namespace detail
36{
37template <typename CB, typename = void>
38struct rhi_has_indirect_count : std::false_type
39{
40};
41template <typename CB>
43 CB, std::void_t<decltype(std::declval<CB&>().drawIndexedIndirectCount(
44 static_cast<QRhiBuffer*>(nullptr), 0u,
45 static_cast<QRhiBuffer*>(nullptr), 0u, 0u, 0u))>> : std::true_type
46{
47};
48
49template <typename CB, typename = void>
50struct rhi_has_dispatch_indirect : std::false_type
51{
52};
53template <typename CB>
55 CB, std::void_t<decltype(std::declval<CB&>().dispatchIndirect(
56 static_cast<QRhiBuffer*>(nullptr), 0u))>> : std::true_type
57{
58};
59
60// Feature-enum probes. The enumerators are named through a dependent type so
61// the code is well-formed when they do not exist.
62template <typename R, typename = void>
64{
65 static bool supported(R&) noexcept { return false; }
66};
67template <typename R>
68struct rhi_feature_indirect_count<R, std::void_t<decltype(R::DrawIndirectCount)>>
69{
70 static bool supported(R& rhi) noexcept
71 {
72 return rhi.isFeatureSupported(R::DrawIndirectCount);
73 }
74};
75
76template <typename R, typename = void>
78{
79 static bool supported(R&) noexcept { return false; }
80};
81template <typename R>
82struct rhi_feature_dispatch_indirect<R, std::void_t<decltype(R::DispatchIndirect)>>
83{
84 static bool supported(R& rhi) noexcept
85 {
86 return rhi.isFeatureSupported(R::DispatchIndirect);
87 }
88};
89}
90
91#if defined(SCORE_GFX_SIMULATE_QT612)
92inline constexpr bool rhiHasDrawIndirectCount = false;
93inline constexpr bool rhiHasDispatchIndirect = false;
94#else
95inline constexpr bool rhiHasDrawIndirectCount
97inline constexpr bool rhiHasDispatchIndirect
99#endif
100
103template <typename R = QRhi>
104inline bool rhiSupportsDrawIndirectCount(R& rhi) noexcept
105{
106 if constexpr(rhiHasDrawIndirectCount)
108 else
109 return false;
110}
111
113template <typename R = QRhi>
114inline bool rhiSupportsDispatchIndirect(R& rhi) noexcept
115{
116 if constexpr(rhiHasDispatchIndirect)
118 else
119 return false;
120}
121
125template <typename CB = QRhiCommandBuffer>
127 CB& cb, bool indexed, QRhiBuffer* indirectBuffer, quint32 indirectOffset,
128 QRhiBuffer* countBuffer, quint32 countOffset, quint32 maxDrawCount,
129 quint32 stride) noexcept
130{
131 if constexpr(rhiHasDrawIndirectCount)
132 {
133 if(indexed)
134 cb.drawIndexedIndirectCount(
135 indirectBuffer, indirectOffset, countBuffer, countOffset,
136 maxDrawCount, stride);
137 else
138 cb.drawIndirectCount(
139 indirectBuffer, indirectOffset, countBuffer, countOffset,
140 maxDrawCount, stride);
141 return true;
142 }
143 else
144 {
145 (void)cb;
146 return false;
147 }
148}
149
152template <typename CB = QRhiCommandBuffer>
154 CB& cb, QRhiBuffer* argsBuffer, quint32 argsOffset) noexcept
155{
156 if constexpr(rhiHasDispatchIndirect)
157 {
158 cb.dispatchIndirect(argsBuffer, argsOffset);
159 return true;
160 }
161 else
162 {
163 (void)cb;
164 return false;
165 }
166}
167}
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
bool drawIndirectCountCompat(CB &cb, bool indexed, QRhiBuffer *indirectBuffer, quint32 indirectOffset, QRhiBuffer *countBuffer, quint32 countOffset, quint32 maxDrawCount, quint32 stride) noexcept
Definition RhiIndirectCompat.hpp:126
bool dispatchIndirectCompat(CB &cb, QRhiBuffer *argsBuffer, quint32 argsOffset) noexcept
Definition RhiIndirectCompat.hpp:153
bool rhiSupportsDrawIndirectCount(R &rhi) noexcept
Definition RhiIndirectCompat.hpp:104
bool rhiSupportsDispatchIndirect(R &rhi) noexcept
QRhi::DispatchIndirect reported by the device; same convention as above.
Definition RhiIndirectCompat.hpp:114
STL namespace.
Definition RhiIndirectCompat.hpp:78
Definition RhiIndirectCompat.hpp:64
Definition RhiIndirectCompat.hpp:51
Definition RhiIndirectCompat.hpp:39