summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_fence_manager.cpp
blob: 4517ef1507941b712e7df24f27452caf1718d1a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include "common/assert.h"

#include "video_core/renderer_opengl/gl_fence_manager.h"

namespace OpenGL {

GLInnerFence::GLInnerFence(GPUVAddr address, u32 payload)
    : VideoCommon::FenceBase(address, payload), sync_object{} {}

GLInnerFence::~GLInnerFence() = default;

void GLInnerFence::Queue() {
    ASSERT(sync_object.handle == 0);
    sync_object.Create();
}

bool GLInnerFence::IsSignaled() const {
    ASSERT(sync_object.handle != 0);
    GLsizei length;
    GLint sync_status;
    glGetSynciv(sync_object.handle, GL_SYNC_STATUS, sizeof(GLint), &length, &sync_status);
    return sync_status == GL_SIGNALED;
}

void GLInnerFence::Wait() {
    ASSERT(sync_object.handle != 0);
    while (glClientWaitSync(sync_object.handle, 0, 1000) == GL_TIMEOUT_EXPIRED)
        ;
}

FenceManagerOpenGL::FenceManagerOpenGL(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
                               TextureCacheOpenGL& texture_cache)
    : GenericFenceManager(system, rasterizer, texture_cache) {}

Fence FenceManagerOpenGL::CreateFence(GPUVAddr addr, u32 value) {
    return std::make_shared<GLInnerFence>(addr, value);
}

void FenceManagerOpenGL::QueueFence(Fence& fence) {
    fence->Queue();
}

bool FenceManagerOpenGL::IsFenceSignaled(Fence& fence) {
    return fence->IsSignaled();
}

void FenceManagerOpenGL::WaitFence(Fence& fence) {
    fence->Wait();
}

} // namespace OpenGL