MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / run

Method run

Source/Engine/Video/Video.cpp:66–133  ·  view source on GitHub ↗

[GPUTask]

Source from the content-addressed store, hash-verified

64protected:
65 // [GPUTask]
66 Result run(GPUTasksContext* context) override
67 {
68 if (!_player || _player->VideoFrameMemory.IsInvalid())
69 return Result::MissingResources;
70 GPUTexture* frame = _player->Frame;
71 if (!frame->IsAllocated())
72 return Result::MissingResources;
73 PROFILE_CPU();
74 PROFILE_MEM(Video);
75 ZoneText(_player->DebugUrl, _player->DebugUrlLen);
76
77 if (PixelFormatExtensions::IsVideo(_player->Format))
78 {
79 // Allocate compressed frame uploading texture
80 if (!_player->FrameUpload)
81 _player->FrameUpload = GPUDevice::Instance->CreateBuffer(TEXT("VideoFrameUpload"));
82 auto desc = GPUBufferDescription::Buffer(_player->VideoFrameMemory.Length(), GPUBufferFlags::ShaderResource, PixelFormat::R32_UInt, nullptr, 4, GPUResourceUsage::Dynamic);
83 // TODO: add support for Transient textures (single frame data upload)
84 if (_player->FrameUpload->GetDescription() != desc)
85 {
86 if (_player->FrameUpload->Init(desc))
87 return Result::Failed;
88 }
89
90 // Upload compressed texture data
91 context->GPU->UpdateBuffer(_player->FrameUpload, _player->VideoFrameMemory.Get(), _player->VideoFrameMemory.Length());
92
93 // Decompress data into RGBA texture
94 auto cb = GPUDevice::Instance->QuadShader->GetCB(0);
95 QuadShaderData cbData;
96 cbData.Color = Float4((float)_player->VideoFrameWidth, (float)_player->VideoFrameHeight, 0, 0);
97 context->GPU->UpdateCB(cb, &cbData);
98 context->GPU->BindCB(0, cb);
99 context->GPU->SetViewportAndScissors((float)_player->Width, (float)_player->Height);
100 context->GPU->SetRenderTarget(frame->View());
101 context->GPU->BindSR(0, _player->FrameUpload->View());
102 GPUPipelineState* pso;
103 switch (_player->Format)
104 {
105 case PixelFormat::YUY2:
106 pso = GPUDevice::Instance->GetDecodeYUY2PS();
107 break;
108 case PixelFormat::NV12:
109 pso = GPUDevice::Instance->GetDecodeNV12PS();
110 break;
111 default:
112 return Result::Failed;
113 }
114 context->GPU->SetState(pso);
115 context->GPU->DrawFullscreenTriangle();
116 }
117 else if (frame->Format() == _player->Format)
118 {
119 // Raw texture data upload
120 uint32 rowPitch, slicePitch;
121 frame->ComputePitch(0, rowPitch, slicePitch);
122 context->GPU->UpdateTexture(frame, 0, 0, _player->VideoFrameMemory.Get(), rowPitch, slicePitch);
123 }

Callers

nothing calls this directly

Calls 15

Float4Class · 0.85
IsAllocatedMethod · 0.80
GetDecodeYUY2PSMethod · 0.80
GetDecodeNV12PSMethod · 0.80
FormatMethod · 0.80
BufferClass · 0.50
ToStringFunction · 0.50
IsInvalidMethod · 0.45
CreateBufferMethod · 0.45
LengthMethod · 0.45
GetDescriptionMethod · 0.45

Tested by

no test coverage detected