Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuoya committed Jul 1, 2021
1 parent 1011c66 commit ee52a9c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/video_core/renderer_opengl/gl_rasterizer.cpp
Expand Up @@ -792,8 +792,8 @@ bool RasterizerOpenGL::Draw(bool accelerate, bool is_indexed) {
framebuffer_info.depth_height = depth_surface->height;
}
} else if (framebuffer_info.depth_attachment != 0) {
if (framebuffer_info.depth_width < surfaces_rect.right ||
framebuffer_info.depth_height < surfaces_rect.top) {
if (framebuffer_info.depth_width < surfaces_rect.right / res_scale ||
framebuffer_info.depth_height < surfaces_rect.top / res_scale) {
// clear both depth and stencil attachment
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, 0, 0);
Expand Down
66 changes: 33 additions & 33 deletions src/video_core/renderer_opengl/renderer_opengl.cpp
Expand Up @@ -36,25 +36,24 @@ namespace OpenGL {
constexpr std::size_t SWAP_CHAIN_SIZE = 6;

struct OGLFrame {
u32 width{}; /// Width of the frame (to detect resize)
u32 height{}; /// Height of the frame
bool color_reloaded = false; /// Texture attachment was recreated (ie: resized)
OGLRenderbuffer color{}; /// Buffer shared between the render/present FBO
OGLFramebuffer render{}; /// FBO created on the render thread
OGLFramebuffer present{}; /// FBO created on the present thread
GLsync render_fence{}; /// Fence created on the render thread
GLsync present_fence{}; /// Fence created on the presentation thread
u32 width; /// Width of the frame (to detect resize)
u32 height; /// Height of the frame
bool color_reloaded; /// Texture attachment was recreated (ie: resized)
OGLRenderbuffer color; /// Buffer shared between the render/present FBO
OGLFramebuffer render; /// FBO created on the render thread
OGLFramebuffer present; /// FBO created on the present thread
GLsync render_fence; /// Fence created on the render thread
GLsync present_fence; /// Fence created on the presentation thread
};

class OGLTextureMailbox {
public:
struct OGLTextureMailbox {
std::mutex swap_chain_lock;
std::condition_variable free_cv;
std::array<OGLFrame, SWAP_CHAIN_SIZE> swap_chain{};
std::queue<OGLFrame*> free_queue;
std::deque<OGLFrame*> present_queue;
OGLFrame* previous_frame = nullptr;
std::chrono::milliseconds elapsed{0};
std::chrono::milliseconds elapsed{};

OGLTextureMailbox() {
if (Settings::values.use_frame_limit) {
Expand Down Expand Up @@ -143,30 +142,31 @@ class OGLTextureMailbox {
}

/// called in present thread
OGLFrame* TryGetPresentFrame() {
if (present_queue.empty()) {
return nullptr;
} else {
std::unique_lock<std::mutex> lock(swap_chain_lock);
OGLFrame* GetPresentFrame() {
std::unique_lock<std::mutex> lock(swap_chain_lock);

// free the previous frame and add it back to the free queue
if (previous_frame) {
free_queue.push(previous_frame);
free_cv.notify_one();
}
// free the previous frame and add it back to the free queue
if (previous_frame) {
free_queue.push(previous_frame);
free_cv.notify_one();
}

// the newest entries are pushed to the front of the queue
previous_frame = present_queue.front();
present_queue.pop_front();

// the newest entries are pushed to the front of the queue
previous_frame = present_queue.front();
if (present_queue.size() > 1) {
// skip frame if pending present frames more than one
free_queue.push(present_queue.front());
present_queue.pop_front();
}

if (present_queue.size() > 1) {
// skip a frame if pendings more than 1
free_queue.push(present_queue.front());
present_queue.pop_front();
}
return previous_frame;
}

return previous_frame;
}
/// called in present thread
bool IsPresentEmpty() const {
return present_queue.empty();
}

/// called in present thread
Expand Down Expand Up @@ -477,12 +477,12 @@ void RendererOpenGL::RenderToMailbox(const Layout::FramebufferLayout& layout) {

/// run in present thread
bool RendererOpenGL::TryPresent() {
auto frame = mailbox->TryGetPresentFrame();
if (!frame) {
LOG_DEBUG(Render_OpenGL, "TryGetPresentFrame returned no frame to present");
if (mailbox->IsPresentEmpty()) {
LOG_DEBUG(Render_OpenGL, "mailbox no frame to present");
return false;
}

auto frame = mailbox->GetPresentFrame();
const auto& layout = render_window.GetFramebufferLayout();

// Clearing before a full overwrite of a fbo can signal to drivers that they can avoid a
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/renderer_opengl/renderer_opengl.h
Expand Up @@ -19,7 +19,7 @@ struct FramebufferLayout;

namespace OpenGL {

class OGLTextureMailbox;
struct OGLTextureMailbox;

/// Structure used for storing information about the textures for each 3DS screen
struct TextureInfo {
Expand Down
3 changes: 1 addition & 2 deletions src/video_core/vertex_loader.cpp
@@ -1,5 +1,4 @@
#include <memory>
#include <boost/range/algorithm/fill.hpp>
#include "common/alignment.h"
#include "common/assert.h"
#include "common/bit_field.h"
Expand All @@ -23,7 +22,7 @@ void VertexLoader::Setup(const PipelineRegs& regs) {
const auto& attribute_config = regs.vertex_attributes;
num_total_attributes = attribute_config.GetNumTotalAttributes();

boost::fill(vertex_attribute_sources, 0xdeadbeef);
vertex_attribute_sources.fill(0xdeadbeef);

for (int i = 0; i < 16; i++) {
vertex_attribute_is_default[i] = attribute_config.IsDefaultAttribute(i);
Expand Down

0 comments on commit ee52a9c

Please sign in to comment.