Skip to content

Commit

Permalink
Deko3D fix resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Oct 30, 2024
1 parent 220330c commit 67da759
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
34 changes: 17 additions & 17 deletions app/src/streaming/video/Metal/MetalVideoRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ int getBitnessScaleFactor(AVFrame* frame) {

// if (m_MetalLayer.displaySyncEnabled) {
// Pace ourselves by waiting if too many frames are pending presentation
// SDL_LockMutex(m_PresentationMutex);
// if (m_PendingPresentationCount > 2) {
// if (SDL_CondWaitTimeout(m_PresentationCond, m_PresentationMutex, 100) == SDL_MUTEX_TIMEDOUT) {
// SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
// "Presentation wait timed out after 100 ms");
// }
// }
// SDL_UnlockMutex(m_PresentationMutex);
SDL_LockMutex(m_PresentationMutex);
if (m_PendingPresentationCount > 2) {
if (SDL_CondWaitTimeout(m_PresentationCond, m_PresentationMutex, 100) == SDL_MUTEX_TIMEDOUT) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Presentation wait timed out after 100 ms");
}
}
SDL_UnlockMutex(m_PresentationMutex);
// }
}
}}
Expand Down Expand Up @@ -429,15 +429,15 @@ int getBitnessScaleFactor(AVFrame* frame) {

// if (m_MetalLayer.displaySyncEnabled) {
// Queue a completion callback on the drawable to pace our rendering
// SDL_LockMutex(m_PresentationMutex);
// m_PendingPresentationCount++;
// SDL_UnlockMutex(m_PresentationMutex);
// [m_NextDrawable addPresentedHandler:^(id<MTLDrawable>) {
// SDL_LockMutex(m_PresentationMutex);
// m_PendingPresentationCount--;
// SDL_CondSignal(m_PresentationCond);
// SDL_UnlockMutex(m_PresentationMutex);
// }];
SDL_LockMutex(m_PresentationMutex);
m_PendingPresentationCount++;
SDL_UnlockMutex(m_PresentationMutex);
[m_NextDrawable addPresentedHandler:^(id<MTLDrawable>) {
SDL_LockMutex(m_PresentationMutex);
m_PendingPresentationCount--;
SDL_CondSignal(m_PresentationCond);
SDL_UnlockMutex(m_PresentationMutex);
}];
// }

// Flip to the newly rendered buffer
Expand Down
38 changes: 27 additions & 11 deletions app/src/streaming/video/deko3d/DKVideoRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ DKVideoRenderer::~DKVideoRenderer() {
}

void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame) {
// if (m_is_initialized) return;

if ((m_frame_width == frame->width) && (m_frame_height == frame->height) &&
(m_screen_width == width) && (m_screen_height == height))
return;
if (m_is_initialized) return;

brls::Logger::info("{}: {} / {}", __PRETTY_FUNCTION__, width, height);

Expand Down Expand Up @@ -140,14 +136,14 @@ void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame)
dk::ImageLayoutMaker { dev }
.setType(DkImageType_2D)
.setFormat(DkImageFormat_R8_Unorm)
.setDimensions(width, height, 1)
.setDimensions(m_frame_width, m_frame_height, 1)
.setFlags(DkImageFlags_UsageLoadStore | DkImageFlags_Usage2DEngine | DkImageFlags_UsageVideo)
.initialize(lumaMappingLayout);

dk::ImageLayoutMaker { dev }
.setType(DkImageType_2D)
.setFormat(DkImageFormat_RG8_Unorm)
.setDimensions(width / 2, height / 2, 1)
.setDimensions(m_frame_width / 2, m_frame_height / 2, 1)
.setFlags(DkImageFlags_UsageLoadStore | DkImageFlags_Usage2DEngine | DkImageFlags_UsageVideo)
.initialize(chromaMappingLayout);

Expand Down Expand Up @@ -196,15 +192,18 @@ void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame)
m_is_initialized = true;
}

int frames = 0;
uint64_t timeCount = 0;

void DKVideoRenderer::draw(NVGcontext* vg, int width, int height, AVFrame* frame, int imageFormat) {
checkAndInitialize(width, height, frame);

uint64_t before_render = LiGetMillis();

if (!m_video_render_stats.rendered_frames) {
m_video_render_stats.measurement_start_timestamp = LiGetMillis();
m_video_render_stats.measurement_start_timestamp = before_render;
}

uint64_t before_render = LiGetMillis();

dk::RasterizerState rasterizerState;
dk::ColorState colorState;
dk::ColorWriteState colorWriteState;
Expand All @@ -213,6 +212,8 @@ void DKVideoRenderer::draw(NVGcontext* vg, int width, int height, AVFrame* frame
cmdbuf.clear();
cmdbuf.clearColor(0, DkColorMask_RGBA, 0.0f, 0.0f, 0.0f, 0.0f);

// brls::Logger::debug("TIME LOG 1: {}", float(LiGetMillis() - before_render));

// Bind state required for drawing the triangle
cmdbuf.bindShaders(DkStageFlag_GraphicsMask, { vertexShader, fragmentShader });
cmdbuf.bindTextures(DkStage_Fragment, 0, dkMakeTextureHandle(lumaTextureId, 0));
Expand All @@ -225,12 +226,27 @@ void DKVideoRenderer::draw(NVGcontext* vg, int width, int height, AVFrame* frame
cmdbuf.bindVtxAttribState(VertexAttribState);
cmdbuf.bindVtxBufferState(VertexBufferState);

// brls::Logger::debug("TIME LOG 2: {}", float(LiGetMillis() - before_render));

// Draw the triangle
cmdbuf.draw(DkPrimitive_Quads, QuadVertexData.size(), 1, 0, 0);

// brls::Logger::debug("TIME LOG 3: {}", float(LiGetMillis() - before_render));

// Finish off this command list
queue.submitCommands(cmdbuf.finishList());
// queue.waitIdle();
queue.waitIdle();

// brls::Logger::debug("TIME LOG 4: {}", float(LiGetMillis() - before_render));

frames++;
timeCount += LiGetMillis() - before_render;

if (timeCount >= 5000) {
brls::Logger::debug("FPS: {}", frames / 5.0f);
frames = 0;
timeCount -= 5000;
}

m_video_render_stats.total_render_time += LiGetMillis() - before_render;
m_video_render_stats.rendered_frames++;
Expand Down

0 comments on commit 67da759

Please sign in to comment.