Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsx/decompiler: Bugfixes and improvements #7957

Merged
merged 3 commits into from Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp
Expand Up @@ -906,7 +906,7 @@ bool FragmentProgramDecompiler::handle_sct_scb(u32 opcode)

// SCB-only ops
case RSX_FP_OPCODE_COS: SetDst("cos($0.xxxx)"); return true;
case RSX_FP_OPCODE_DST: SetDst("distance($0, $1).xxxx", OPFLAGS::src_cast_f32); return true;
case RSX_FP_OPCODE_DST: SetDst("$Ty(1.0, $0.y * $1.y, $0.z, $1.w)", OPFLAGS::op_extern); return true;
case RSX_FP_OPCODE_REFL: SetDst(getFunction(FUNCTION::FUNCTION_REFL), OPFLAGS::op_extern); return true;
case RSX_FP_OPCODE_EX2: SetDst("exp2($0.xxxx)"); return true;
case RSX_FP_OPCODE_FLR: SetDst("floor($0)"); return true;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp
Expand Up @@ -574,7 +574,7 @@ std::string VertexProgramDecompiler::Decompile()
case RSX_VEC_OPCODE_DP3: SetDSTVec(getFunction(FUNCTION::FUNCTION_DP3)); break;
case RSX_VEC_OPCODE_DPH: SetDSTVec(getFunction(FUNCTION::FUNCTION_DPH)); break;
case RSX_VEC_OPCODE_DP4: SetDSTVec(getFunction(FUNCTION::FUNCTION_DP4)); break;
case RSX_VEC_OPCODE_DST: SetDSTVec("vec4(distance($0, $1))"); break;
case RSX_VEC_OPCODE_DST: SetDSTVec("vec4(1.0, $0.y * $1.y, $0.z, $1.w)"); break;
case RSX_VEC_OPCODE_MIN: SetDSTVec("min($0, $1)"); break;
case RSX_VEC_OPCODE_MAX: SetDSTVec("max($0, $1)"); break;
case RSX_VEC_OPCODE_SLT: SetDSTVec(getFloatTypeName(4) + "(" + compareFunction(COMPARE::FUNCTION_SLT, "$0", "$1") + ")"); break;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/GL/GLCompute.h
Expand Up @@ -50,7 +50,7 @@ namespace gl

m_program.create();
m_program.attach(m_shader);
m_program.make();
m_program.link();

compiled = true;
}
Expand Down
16 changes: 7 additions & 9 deletions rpcs3/Emu/RSX/GL/GLGSRender.cpp
Expand Up @@ -76,6 +76,7 @@ void GLGSRender::on_init_thread()

// Bind primary context to main RSX thread
m_frame->set_current(m_context);
gl::set_primary_context_thread();

zcull_ctrl.reset(static_cast<::rsx::reports::ZCULL_control*>(this));

Expand Down Expand Up @@ -625,6 +626,11 @@ bool GLGSRender::load_program()
}
}
}
else
{
verify(HERE), m_program;
m_program->sync();
}

return m_program != nullptr;
}
Expand Down Expand Up @@ -946,13 +952,5 @@ void GLGSRender::on_decompiler_exit()

bool GLGSRender::on_decompiler_task()
{
const auto result = m_prog_buffer.async_update(8);
if (result.second)
{
// TODO: Proper synchronization with renderer
// Finish works well enough for now but it is not a proper soulution
glFinish();
}

return result.first;
return m_prog_buffer.async_update(8).first;
}
12 changes: 12 additions & 0 deletions rpcs3/Emu/RSX/GL/GLHelpers.cpp
Expand Up @@ -11,6 +11,18 @@ namespace gl
capabilities g_driver_caps;
const fbo screen{};

thread_local bool tls_primary_context_thread = false;

void set_primary_context_thread()
{
tls_primary_context_thread = true;
}

bool is_primary_context_thread()
{
return tls_primary_context_thread;
}

GLenum draw_mode(rsx::primitive_type in)
{
switch (in)
Expand Down
32 changes: 27 additions & 5 deletions rpcs3/Emu/RSX/GL/GLHelpers.h
Expand Up @@ -86,6 +86,9 @@ namespace gl
bool is_primitive_native(rsx::primitive_type in);
GLenum draw_mode(rsx::primitive_type in);

void set_primary_context_thread();
bool is_primary_context_thread();

// Texture helpers
std::array<GLenum, 4> apply_swizzle_remap(const std::array<GLenum, 4>& swizzle_remap, const std::pair<std::array<u8, 4>, std::array<u8, 4>>& decoded_remap);

Expand Down Expand Up @@ -391,6 +394,12 @@ namespace gl

return signaled;
}

void server_wait_sync() const
{
verify(HERE), m_value != nullptr;
glWaitSync(m_value, 0, GL_TIMEOUT_IGNORED);
}
};

template<typename Type, uint BindId, uint GetStateId>
Expand Down Expand Up @@ -2533,6 +2542,7 @@ namespace gl
class program
{
GLuint m_id = 0;
fence m_fence;

public:
class uniform_t
Expand Down Expand Up @@ -2717,6 +2727,15 @@ namespace gl

rsx_log.fatal("Linkage failed: %s", error_msg);
}
else
{
m_fence.create();

if (!is_primary_context_thread())
{
glFlush();
}
}
}

void validate()
Expand All @@ -2743,11 +2762,6 @@ namespace gl
}
}

void make()
{
link();
}

uint id() const
{
return m_id;
Expand All @@ -2764,6 +2778,14 @@ namespace gl
return m_id != 0;
}

void sync()
{
if (!m_fence.check_signaled())
{
m_fence.server_wait_sync();
}
}

explicit operator bool() const
{
return created();
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/GL/GLOverlays.h
Expand Up @@ -66,7 +66,7 @@ namespace gl
program_handle.create();
program_handle.attach(vs);
program_handle.attach(fs);
program_handle.make();
program_handle.link();

fbo.create();

Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/RSX/GL/GLProcTable.h
Expand Up @@ -217,6 +217,7 @@ OPENGL_PROC(PFNGLBUFFERSTORAGEPROC, BufferStorage);
// ARB_sync
OPENGL_PROC(PFNGLFENCESYNCPROC, FenceSync);
OPENGL_PROC(PFNGLCLIENTWAITSYNCPROC, ClientWaitSync);
OPENGL_PROC(PFNGLWAITSYNCPROC, WaitSync);
OPENGL_PROC(PFNGLGETSYNCIVPROC, GetSynciv);
OPENGL_PROC(PFNGLDELETESYNCPROC, DeleteSync);

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/GL/GLProgramBuffer.h
Expand Up @@ -42,7 +42,7 @@ struct GLTraits
.bind_fragment_data_location("ocol1", 1)
.bind_fragment_data_location("ocol2", 2)
.bind_fragment_data_location("ocol3", 3)
.make();
.link();

// Progam locations are guaranteed to not change after linking
// Texture locations are simply bound to the TIUs so this can be done once
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/GL/GLTextOut.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "stdafx.h"
#include "GLHelpers.h"
Expand Down Expand Up @@ -63,7 +63,7 @@ namespace gl
m_program.create();
m_program.attach(m_vs);
m_program.attach(m_fs);
m_program.make();
m_program.link();
}

void load_program(float scale_x, float scale_y, float *offsets, size_t nb_offsets, color4f color)
Expand Down