4#ifndef QRHIMETAL_ICB_P_H
5#define QRHIMETAL_ICB_P_H
29#include <metal_stdlib>
30using namespace metal;
31
32struct DrawCmd {
33 uint vertexCount;
34 uint instanceCount;
35 uint firstVertex;
36 uint firstInstance;
37};
38
39struct DrawIndexedCmd {
40 uint indexCount;
41 uint instanceCount;
42 uint firstIndex;
43 int baseVertex;
44 uint baseInstance;
45};
46
47struct ICBContainer {
48 command_buffer cmdBuffer [[id(0)]];
49};
50
51// Matches MTLIndirectCommandBufferExecutionRange.
52struct ExecutionRange {
53 uint location;
54 uint length;
55};
56
57static uint prologue(uint gid, uint maxDrawCount, const device uint *countBuf,
58 device ExecutionRange *range)
59{
60 const uint count = min(maxDrawCount, countBuf[0]);
61 if (gid == 0) {
62 range->location = 0u;
63 range->length = count;
64 }
65 return count;
66}
67
68template <typename IndexT>
69static void encodeIndexed(const device char *argsRaw,
70 device ICBContainer *container,
71 uint maxDrawCount,
72 const device IndexT *indexBuffer,
73 uint primType,
74 uint stride,
75 const device uint *countBuf,
76 device ExecutionRange *range,
77 uint gid)
78{
79 const uint count = prologue(gid, maxDrawCount, countBuf, range);
80 if (gid >= maxDrawCount)
81 return;
82
83 const device DrawIndexedCmd &a = *(const device DrawIndexedCmd *)(argsRaw + gid * stride);
84 render_command cmd(container->cmdBuffer, gid);
85 if (gid < count && a.indexCount > 0u) {
86 cmd.draw_indexed_primitives(
87 static_cast<primitive_type>(primType),
88 a.indexCount,
89 indexBuffer + a.firstIndex,
90 a.instanceCount,
91 uint(a.baseVertex),
92 a.baseInstance
93 );
94 } else {
95 cmd.reset();
96 }
97}
98
99kernel void encode_icb(
100 const device char *argsRaw [[buffer(0)]],
101 device ICBContainer *container [[buffer(1)]],
102 constant uint &maxDrawCount [[buffer(2)]],
103 constant uint &primType [[buffer(4)]],
104 constant uint &stride [[buffer(5)]],
105 const device uint *countBuf [[buffer(6)]],
106 device ExecutionRange *range [[buffer(7)]],
107 uint gid [[thread_position_in_grid]])
108{
109 const uint count = prologue(gid, maxDrawCount, countBuf, range);
110 if (gid >= maxDrawCount)
111 return;
112
113 const device DrawCmd &a = *(const device DrawCmd *)(argsRaw + gid * stride);
114 render_command cmd(container->cmdBuffer, gid);
115 if (gid < count && a.vertexCount > 0u) {
116 cmd.draw_primitives(
117 static_cast<primitive_type>(primType),
118 a.firstVertex,
119 a.vertexCount,
120 a.instanceCount,
121 a.firstInstance
122 );
123 } else {
124 cmd.reset();
125 }
126}
127
128kernel void encode_icb_indexed_u32(
129 const device char *argsRaw [[buffer(0)]],
130 device ICBContainer *container [[buffer(1)]],
131 constant uint &maxDrawCount [[buffer(2)]],
132 const device uint *indexBuffer [[buffer(3)]],
133 constant uint &primType [[buffer(4)]],
134 constant uint &stride [[buffer(5)]],
135 const device uint *countBuf [[buffer(6)]],
136 device ExecutionRange *range [[buffer(7)]],
137 uint gid [[thread_position_in_grid]])
138{
139 encodeIndexed(argsRaw, container, maxDrawCount, indexBuffer, primType, stride,
140 countBuf, range, gid);
141}
142
143kernel void encode_icb_indexed_u16(
144 const device char *argsRaw [[buffer(0)]],
145 device ICBContainer *container [[buffer(1)]],
146 constant uint &maxDrawCount [[buffer(2)]],
147 const device ushort *indexBuffer [[buffer(3)]],
148 constant uint &primType [[buffer(4)]],
149 constant uint &stride [[buffer(5)]],
150 const device uint *countBuf [[buffer(6)]],
151 device ExecutionRange *range [[buffer(7)]],
152 uint gid [[thread_position_in_grid]])
153{
154 encodeIndexed(argsRaw, container, maxDrawCount, indexBuffer, primType, stride,
155 countBuf, range, gid);
156}
157)";
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
Combined button and popup list for selecting options.
Int aligned(Int v, Int byteAlign)
\variable QRhiVulkanQueueSubmitParams::waitSemaphoreCount
id< MTLTexture > viewForLevel(int level)
id< MTLTexture > perLevelViews[QRhi::MAX_MIP_LEVELS]
id< MTLBuffer > stagingBuf[QMTL_FRAMES_IN_FLIGHT]
QMetalTextureData(QMetalTexture *t)
~QMetalTextureRenderTarget()
float devicePixelRatio() const override
QMetalRenderTargetData * d
QMetalTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags)
bool create() override
Creates the corresponding native graphics resources.
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
int sampleCount() const override
QSize pixelSize() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QMetalTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, Flags flags)
bool prepareCreate(QSize *adjustedSize=nullptr)
NativeTexture nativeTexture() override
bool create() override
Creates the corresponding native graphics resources.
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool createFrom(NativeTexture src) override
Similar to create(), except that no new native textures are created.
\variable QRhiIndirectDrawCommand::vertexCount
id< MTLComputePipelineState > pipelineState
id< MTLDepthStencilState > depthStencilState
std::array< id< MTLComputePipelineState >, 3 > tessVertexComputeState
id< MTLRasterizationRateMap > rateMap
id< MTLSamplerState > samplerState
id< MTLBuffer > argBuffer
id< MTLBuffer > stagingBuffers[QMTL_FRAMES_IN_FLIGHT]
id< MTLComputePipelineState > tessTessControlComputeState
id< MTLIndirectCommandBuffer > icb
id< MTLRenderPipelineState > pipelineState
id< MTLBuffer > buffers[QMTL_FRAMES_IN_FLIGHT]
id< MTLTexture > views[QRhi::MAX_MIP_LEVELS]
QRhiReadbackDescription desc
QRhiReadbackResult * result
QRhiTexture::Format format
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
float maxPotentialColorComponentValue
LuminanceBehavior luminanceBehavior
float maxColorComponentValue
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h