Skip to content

Commit

Permalink
WIP: Deko3D
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Nov 9, 2024
1 parent d4326a8 commit 98b009e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
26 changes: 12 additions & 14 deletions app/src/streaming/video/deko3d/DKVideoRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame)
this->queue = vctx->getQueue();

// Create the memory pools
pool_images.emplace(dev, DkMemBlockFlags_GpuCached | DkMemBlockFlags_Image, 16*1024*1024);
// pool_images.emplace(dev, DkMemBlockFlags_GpuCached | DkMemBlockFlags_Image, 16*1024*1024);
pool_code.emplace(dev, DkMemBlockFlags_CpuUncached | DkMemBlockFlags_GpuCached | DkMemBlockFlags_Code, 128*1024);
pool_data.emplace(dev, DkMemBlockFlags_CpuUncached | DkMemBlockFlags_GpuCached, 1*1024*1024);

Expand All @@ -132,33 +132,28 @@ void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame)


// Load the transform buffer
transformUniformBuffer = pool_data->allocate(sizeof(Transformation), DK_UNIFORM_BUF_ALIGNMENT);
auto transformState = reinterpret_cast<Transformation *>(transformUniformBuffer.getCpuAddr());
transformUniformBuffer = pool_code->allocate(sizeof(Transformation), DK_UNIFORM_BUF_ALIGNMENT);

bool colorFull = frame->color_range == AVCOL_RANGE_JPEG;

transformState->offset = gl_color_offset(colorFull);
transformState->yuvmat = gl_color_matrix(frame->colorspace, colorFull);
Transformation transformState;
transformState.offset = {0,0.5f,0.5f};// gl_color_offset(colorFull);
transformState.yuvmat = gl_color_matrix(frame->colorspace, colorFull);

float frameAspect = ((float)m_frame_height / (float)m_frame_width);
float screenAspect = ((float)m_screen_height / (float)m_screen_width);

if (frameAspect > screenAspect) {
float multiplier = frameAspect / screenAspect;
transformState->uv_data = { 0.5f - 0.5f * (1.0f / multiplier),
transformState.uv_data = { 0.5f - 0.5f * (1.0f / multiplier),
0.0f, multiplier, 1.0f };
} else {
float multiplier = screenAspect / frameAspect;
transformState->uv_data = { 0.0f,
transformState.uv_data = { 0.0f,
0.5f - 0.5f * (1.0f / multiplier), 1.0f, multiplier };
}


// cmdbuf.pushConstants(
// transformUniformBuffer.getGpuAddr(), transformUniformBuffer.getSize(),
// 0, sizeof(transformState), &transformState);


// Allocate image indexes for planes
lumaTextureId = vctx->allocateImageIndex();
chromaTextureId = vctx->allocateImageIndex();
Expand Down Expand Up @@ -214,7 +209,10 @@ void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame)
cmdbuf.bindShaders(DkStageFlag_GraphicsMask, { vertexShader, fragmentShader });
cmdbuf.bindTextures(DkStage_Fragment, 0, dkMakeTextureHandle(lumaTextureId, 0));
cmdbuf.bindTextures(DkStage_Fragment, 1, dkMakeTextureHandle(chromaTextureId, 0));
cmdbuf.bindUniformBuffer(DkStage_Fragment, 2, transformUniformBuffer.getGpuAddr(), transformUniformBuffer.getSize());
cmdbuf.bindUniformBuffer(DkStage_Fragment, 0, transformUniformBuffer.getGpuAddr(), transformUniformBuffer.getSize());
cmdbuf.pushConstants(
transformUniformBuffer.getGpuAddr(), transformUniformBuffer.getSize(),
0, sizeof(transformState), &transformState);
cmdbuf.bindRasterizerState(rasterizerState);
cmdbuf.bindColorState(colorState);
cmdbuf.bindColorWriteState(colorWriteState);
Expand Down Expand Up @@ -242,7 +240,7 @@ void DKVideoRenderer::draw(NVGcontext* vg, int width, int height, AVFrame* frame
}

// Finish off this command list
queue = vctx->getQueue();
// queue = vctx->getQueue();
queue.submitCommands(cmdlist);
queue.waitIdle();

Expand Down
2 changes: 1 addition & 1 deletion app/src/streaming/video/deko3d/DKVideoRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DKVideoRenderer : public IVideoRenderer {
dk::Device dev;
dk::Queue queue;

std::optional<CMemPool> pool_images;
// std::optional<CMemPool> pool_images;
std::optional<CMemPool> pool_code;
std::optional<CMemPool> pool_data;

Expand Down
6 changes: 3 additions & 3 deletions app/src/streaming/video/deko3d/texture_fsh.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ layout (location = 0) out vec4 outColor;
layout (binding = 0) uniform sampler2D plane0;
layout (binding = 1) uniform sampler2D plane1;

layout (std140, binding = 2) uniform Transformation
layout (std140, binding = 0) uniform Transformation
{
mat3 yuvmat;
vec3 offset;
Expand All @@ -32,8 +32,8 @@ void main()
float r, g, b, yt, ut, vt;

yt = texture2D(plane0, vTextureCoord).r;
ut = texture2D(plane1, vTextureCoord).r - 0.5;
vt = texture2D(plane1, vTextureCoord).g - 0.5;
ut = texture2D(plane1, vTextureCoord).r - 0.5;// - u.offset.y;
vt = texture2D(plane1, vTextureCoord).g - 0.5;// - u.offset.z;

r = yt + 1.13983*vt;
g = yt - 0.39465*ut - 0.58060*vt;
Expand Down

0 comments on commit 98b009e

Please sign in to comment.