mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-10 00:41:26 +12:00
Merge pull request #1318 from vlj/gl
Gl: Use common code for fragment constants.
This commit is contained in:
commit
cdcef4c8ee
4 changed files with 30 additions and 36 deletions
|
@ -382,13 +382,4 @@ public:
|
||||||
offset += 4 * sizeof(u32);
|
offset += 4 * sizeof(u32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<size_t> &getFragmentConstantOffsetsCache(const RSXFragmentProgram *fragmentShader) const
|
|
||||||
{
|
|
||||||
typename binary2FS::const_iterator It = m_cacheFS.find(vm::base(fragmentShader->addr));
|
|
||||||
if (It != m_cacheFS.end())
|
|
||||||
return It->second.FragmentConstantOffsetCache;
|
|
||||||
LOG_ERROR(RSX, "Can't retrieve constant offset cache");
|
|
||||||
return dummyFragmentConstantCache;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,14 +28,14 @@ std::string GLFragmentDecompilerThread::compareFunction(COMPARE f, const std::st
|
||||||
|
|
||||||
void GLFragmentDecompilerThread::insertHeader(std::stringstream & OS)
|
void GLFragmentDecompilerThread::insertHeader(std::stringstream & OS)
|
||||||
{
|
{
|
||||||
OS << "#version 140" << std::endl;
|
OS << "#version 420" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLFragmentDecompilerThread::insertIntputs(std::stringstream & OS)
|
void GLFragmentDecompilerThread::insertIntputs(std::stringstream & OS)
|
||||||
{
|
{
|
||||||
for (ParamType PT : m_parr.params[PF_PARAM_IN])
|
for (const ParamType& PT : m_parr.params[PF_PARAM_IN])
|
||||||
{
|
{
|
||||||
for (ParamItem PI : PT.items)
|
for (const ParamItem& PI : PT.items)
|
||||||
OS << "in " << PT.type << " " << PI.name << ";" << std::endl;
|
OS << "in " << PT.type << " " << PI.name << ";" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,22 +59,27 @@ void GLFragmentDecompilerThread::insertOutputs(std::stringstream & OS)
|
||||||
|
|
||||||
void GLFragmentDecompilerThread::insertConstants(std::stringstream & OS)
|
void GLFragmentDecompilerThread::insertConstants(std::stringstream & OS)
|
||||||
{
|
{
|
||||||
for (ParamType PT : m_parr.params[PF_PARAM_UNIFORM])
|
for (const ParamType& PT : m_parr.params[PF_PARAM_UNIFORM])
|
||||||
{
|
{
|
||||||
if (PT.type != "sampler2D")
|
if (PT.type != "sampler2D")
|
||||||
continue;
|
continue;
|
||||||
for (ParamItem PI : PT.items)
|
for (const ParamItem& PI : PT.items)
|
||||||
OS << "uniform " << PT.type << " " << PI.name << ";" << std::endl;
|
OS << "uniform " << PT.type << " " << PI.name << ";" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ParamType PT : m_parr.params[PF_PARAM_UNIFORM])
|
OS << "layout(std140, binding = 2) uniform FragmentConstantsBuffer" << std::endl;
|
||||||
|
OS << "{" << std::endl;
|
||||||
|
for (const ParamType& PT : m_parr.params[PF_PARAM_UNIFORM])
|
||||||
{
|
{
|
||||||
if (PT.type == "sampler2D")
|
if (PT.type == "sampler2D")
|
||||||
continue;
|
continue;
|
||||||
for (ParamItem PI : PT.items)
|
for (const ParamItem& PI : PT.items)
|
||||||
OS << "uniform " << PT.type << " " << PI.name << ";" << std::endl;
|
OS << " " << PT.type << " " << PI.name << ";" << std::endl;
|
||||||
}
|
}
|
||||||
|
// A dummy value otherwise it's invalid to create an empty uniform buffer
|
||||||
|
OS << " vec4 void_value;" << std::endl;
|
||||||
|
OS << "};" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLFragmentDecompilerThread::insertMainStart(std::stringstream & OS)
|
void GLFragmentDecompilerThread::insertMainStart(std::stringstream & OS)
|
||||||
|
@ -82,9 +87,9 @@ void GLFragmentDecompilerThread::insertMainStart(std::stringstream & OS)
|
||||||
OS << "void main ()" << std::endl;
|
OS << "void main ()" << std::endl;
|
||||||
OS << "{" << std::endl;
|
OS << "{" << std::endl;
|
||||||
|
|
||||||
for (ParamType PT : m_parr.params[PF_PARAM_NONE])
|
for (const ParamType& PT : m_parr.params[PF_PARAM_NONE])
|
||||||
{
|
{
|
||||||
for (ParamItem PI : PT.items)
|
for (const ParamItem& PI : PT.items)
|
||||||
{
|
{
|
||||||
OS << " " << PT.type << " " << PI.name;
|
OS << " " << PT.type << " " << PI.name;
|
||||||
if (!PI.value.empty())
|
if (!PI.value.empty())
|
||||||
|
@ -153,7 +158,7 @@ void GLFragmentProgram::Decompile(RSXFragmentProgram& prog)
|
||||||
decompiler.Task();
|
decompiler.Task();
|
||||||
for (const ParamType& PT : decompiler.m_parr.params[PF_PARAM_UNIFORM])
|
for (const ParamType& PT : decompiler.m_parr.params[PF_PARAM_UNIFORM])
|
||||||
{
|
{
|
||||||
for (const ParamItem PI : PT.items)
|
for (const ParamItem& PI : PT.items)
|
||||||
{
|
{
|
||||||
if (PT.type == "sampler2D")
|
if (PT.type == "sampler2D")
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -586,11 +586,11 @@ void GLGSRender::begin()
|
||||||
__glcheck glDepthMask(rsx::method_registers[NV4097_SET_DEPTH_MASK]);
|
__glcheck glDepthMask(rsx::method_registers[NV4097_SET_DEPTH_MASK]);
|
||||||
__glcheck glStencilMask(rsx::method_registers[NV4097_SET_STENCIL_MASK]);
|
__glcheck glStencilMask(rsx::method_registers[NV4097_SET_STENCIL_MASK]);
|
||||||
|
|
||||||
//int viewport_x = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] & 0xffff);
|
int viewport_x = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] & 0xffff);
|
||||||
//int viewport_y = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] & 0xffff);
|
int viewport_y = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] & 0xffff);
|
||||||
//int viewport_w = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] >> 16);
|
int viewport_w = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] >> 16);
|
||||||
//int viewport_h = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] >> 16);
|
int viewport_h = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] >> 16);
|
||||||
//glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
|
glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
|
||||||
|
|
||||||
//scissor test is always enabled
|
//scissor test is always enabled
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
@ -1065,9 +1065,11 @@ void GLGSRender::oninit_thread()
|
||||||
m_ebo.create();
|
m_ebo.create();
|
||||||
m_scale_offset_buffer.create(16 * sizeof(float));
|
m_scale_offset_buffer.create(16 * sizeof(float));
|
||||||
m_vertex_constants_buffer.create(512 * 4 * sizeof(float));
|
m_vertex_constants_buffer.create(512 * 4 * sizeof(float));
|
||||||
|
m_fragment_constants_buffer.create();
|
||||||
|
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_scale_offset_buffer.id());
|
glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_scale_offset_buffer.id());
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, m_vertex_constants_buffer.id());
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, m_vertex_constants_buffer.id());
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 2, m_fragment_constants_buffer.id());
|
||||||
|
|
||||||
m_vao.array_buffer = m_vbo;
|
m_vao.array_buffer = m_vbo;
|
||||||
m_vao.element_array_buffer = m_ebo;
|
m_vao.element_array_buffer = m_ebo;
|
||||||
|
@ -1275,17 +1277,12 @@ bool GLGSRender::load_program()
|
||||||
fill_vertex_program_constants_data(buffer);
|
fill_vertex_program_constants_data(buffer);
|
||||||
glUnmapBuffer(GL_UNIFORM_BUFFER);
|
glUnmapBuffer(GL_UNIFORM_BUFFER);
|
||||||
|
|
||||||
for (u32 constant_offset : m_prog_buffer.getFragmentConstantOffsetsCache(&fragment_program))
|
glBindBuffer(GL_UNIFORM_BUFFER, m_fragment_constants_buffer.id());
|
||||||
{
|
size_t buffer_size = m_prog_buffer.get_fragment_constants_buffer_size(&fragment_program);
|
||||||
auto data = vm::ps3::_ptr<u32>(fragment_program.addr + constant_offset);
|
glBufferData(GL_UNIFORM_BUFFER, buffer_size, nullptr, GL_STATIC_DRAW);
|
||||||
|
buffer = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
|
||||||
u32 c0 = (data[0] >> 16 | data[0] << 16);
|
m_prog_buffer.fill_fragment_constans_buffer(buffer, &fragment_program);
|
||||||
u32 c1 = (data[1] >> 16 | data[1] << 16);
|
glUnmapBuffer(GL_UNIFORM_BUFFER);
|
||||||
u32 c2 = (data[2] >> 16 | data[2] << 16);
|
|
||||||
u32 c3 = (data[3] >> 16 | data[3] << 16);
|
|
||||||
|
|
||||||
m_program->uniforms["fc" + std::to_string(constant_offset)] = color4f{ (f32&)c0, (f32&)c1, (f32&)c2, (f32&)c3 };
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ private:
|
||||||
|
|
||||||
gl::buffer m_scale_offset_buffer;
|
gl::buffer m_scale_offset_buffer;
|
||||||
gl::buffer m_vertex_constants_buffer;
|
gl::buffer m_vertex_constants_buffer;
|
||||||
|
gl::buffer m_fragment_constants_buffer;
|
||||||
|
|
||||||
gl::buffer m_vbo;
|
gl::buffer m_vbo;
|
||||||
gl::buffer m_ebo;
|
gl::buffer m_ebo;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue