Loading...
Searching...
No Matches
score::gfx::P216PackedEncoder Struct Reference

GPU RGBA -> p216, as ONE texture holding the whole framestore. More...

Inheritance diagram for score::gfx::P216PackedEncoder:
score::gfx::GPUVideoEncoder

Detailed Description

GPU RGBA -> p216, as ONE texture holding the whole framestore.

P216Encoder produces the same bytes in two plane textures, which is the right shape for a consumer that wants planes. A consumer that wants the framestore – NDI's p_data, a capture card's frame buffer – then has to concatenate them, because a QRhi readback lands in its own allocation per plane. At 1080p that is 8.3 MB of memcpy per frame for nothing.

P216's two planes are the same size: 2*width bytes per row, height rows each. So the whole framestore is exactly an RGBA8 texture of (width/2) x (2*height) – luma rows on top, interleaved chroma below – and one readback of it IS the framestore, in order, ready to send.

It is UYVYEncoder's trick (an RGBA8 target at half width whose texels are the wire bytes) applied one dimension further. The cost is that the shader writes bytes rather than samples: each RGBA8 texel carries two 16-bit values, little endian, which is what both P216 and every consumer of it expect.

Requires width % 2 == 0. Feed an RGBA16F source texture if the extra bits should mean anything; from an 8-bit scene this produces valid P216 whose values are 8-bit quantities scaled into 16-bit words.

Public Member Functions

void init (QRhi &rhi, const RenderState &state, QRhiTexture *inputRGBA, int width, int height, const QString &colorConversion) override
 
void exec (QRhi &rhi, QRhiCommandBuffer &cb) override
 
int planeCount () const override
 Number of readback planes (1 for UYVY, 2 for NV12, 3 for I420).
 
const QRhiReadbackResult & readback (int) const override
 Get the readback result for a given plane. Valid after endOffscreenFrame.
 
QRhiTexture * outputTexture () const noexcept override
 
void setReadbackEnabled (bool e) noexcept override
 
void release () override
 Release all GPU resources.
 

Public Attributes

QRhiTexture * m_outTexture {}
 
QRhiTextureRenderTarget * m_renderTarget {}
 
QRhiRenderPassDescriptor * m_rpDesc {}
 
QRhiSampler * m_sampler {}
 
QRhiShaderResourceBindings * m_srb {}
 
QRhiGraphicsPipeline * m_pipeline {}
 
QRhiReadbackResult m_readback {}
 
int m_width {}
 
int m_height {}
 
bool m_readbackEnabled {true}
 

Static Public Attributes

static constexpr const char * frag
 
- Static Public Attributes inherited from score::gfx::GPUVideoEncoder
static constexpr const char * vertex_shader
 
static constexpr const char * rgb_to_yuv_glsl
 
static constexpr const char * y_flip_glsl
 Fragment shader Y-flip: on GL, flip v_texcoord.y. On Metal/HLSL, no flip.
 

Member Function Documentation

◆ exec()

void score::gfx::P216PackedEncoder::exec ( QRhi &  rhi,
QRhiCommandBuffer &  cb 
)
inlineoverridevirtual

Execute the conversion pass. Call inside beginOffscreenFrame/endOffscreenFrame. Renders the conversion shader and schedules GPU->CPU readback(s).

Implements score::gfx::GPUVideoEncoder.

◆ init()

void score::gfx::P216PackedEncoder::init ( QRhi &  rhi,
const RenderState &  state,
QRhiTexture *  inputRGBA,
int  width,
int  height,
const QString &  colorConversion 
)
inlineoverridevirtual

Create render targets, textures, samplers, and the graphics pipeline.

Parameters
rhiThe QRhi instance.
stateThe render state (for shader compilation).
inputRGBAThe scene RGBA texture to read from.
widthSource width in pixels.
heightSource height in pixels.
colorConversionGLSL code from colorMatrixOut() defining convert_from_rgb(). If empty, defaults to BT.709 full range.

Implements score::gfx::GPUVideoEncoder.

◆ outputTexture()

QRhiTexture * score::gfx::P216PackedEncoder::outputTexture ( ) const
inlineoverridevirtualnoexcept

The single output texture (RGBA8, format-dependent dimensions) for single-plane encoders, so vendor-neutral code (CpuStagedVideoOutput's DVP download) can copy it straight to sysmem instead of using readback(). Default nullptr (multi-plane encoders) => callers must use readback().

Reimplemented from score::gfx::GPUVideoEncoder.

◆ planeCount()

int score::gfx::P216PackedEncoder::planeCount ( ) const
inlineoverridevirtual

Number of readback planes (1 for UYVY, 2 for NV12, 3 for I420).

Implements score::gfx::GPUVideoEncoder.

◆ readback()

const QRhiReadbackResult & score::gfx::P216PackedEncoder::readback ( int  plane) const
inlineoverridevirtual

Get the readback result for a given plane. Valid after endOffscreenFrame.

Implements score::gfx::GPUVideoEncoder.

◆ release()

void score::gfx::P216PackedEncoder::release ( )
inlineoverridevirtual

Release all GPU resources.

Implements score::gfx::GPUVideoEncoder.

◆ setReadbackEnabled()

void score::gfx::P216PackedEncoder::setReadbackEnabled ( bool  )
inlineoverridevirtualnoexcept

Enable/disable the GPU->CPU readback scheduled in exec(). Default enabled (readback runs). Disable when a GPU-direct download reads outputTexture() directly, so exec() doesn't also pay the readback (no double transfer).

Reimplemented from score::gfx::GPUVideoEncoder.


The documentation for this struct was generated from the following file: