vk/gl: Enable alpha test in shaders (#1743)

This commit is contained in:
kd-11 2016-06-05 20:31:23 +03:00 committed by Ivan
parent 9710044134
commit c4102f3b18
6 changed files with 77 additions and 2 deletions

View File

@ -35,6 +35,8 @@ void GLFragmentDecompilerThread::insertHeader(std::stringstream & OS)
OS << " mat4 scaleOffsetMat;\n";
OS << " float fog_param0;\n";
OS << " float fog_param1;\n";
OS << " uint alpha_test;\n";
OS << " float alpha_ref;\n";
OS << "};\n";
}
@ -205,10 +207,14 @@ void GLFragmentDecompilerThread::insertMainEnd(std::stringstream & OS)
{ "ocol3", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r4" : "h8" },
};
std::string first_output_name;
for (int i = 0; i < sizeof(table) / sizeof(*table); ++i)
{
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", table[i].second))
{
OS << " " << table[i].first << " = " << table[i].second << ";" << std::endl;
if (first_output_name.empty()) first_output_name = table[i].first;
}
}
if (m_ctrl & CELL_GCM_SHADER_CONTROL_DEPTH_EXPORT)
@ -223,6 +229,30 @@ void GLFragmentDecompilerThread::insertMainEnd(std::stringstream & OS)
}
}
if (!first_output_name.empty())
{
switch (m_prog.alpha_func)
{
case rsx::comparaison_function::equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a != alpha_ref) discard;\n";
break;
case rsx::comparaison_function::not_equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a == alpha_ref) discard;\n";
break;
case rsx::comparaison_function::less_or_equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a > alpha_ref) discard;\n";
break;
case rsx::comparaison_function::less:
OS << " if (bool(alpha_test) && " << first_output_name << ".a >= alpha_ref) discard;\n";
break;
case rsx::comparaison_function::greater:
OS << " if (bool(alpha_test) && " << first_output_name << ".a <= alpha_ref) discard;\n";
break;
case rsx::comparaison_function::greater_or_equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a < alpha_ref) discard;\n";
break;
}
}
OS << "}" << std::endl;
}

View File

@ -377,7 +377,7 @@ void GLGSRender::on_init_thread()
m_vao.create();
m_vbo.create();
m_ebo.create();
m_scale_offset_buffer.create(18 * sizeof(float));
m_scale_offset_buffer.create(32 * sizeof(float));
m_vertex_constants_buffer.create(512 * 4 * sizeof(float));
m_fragment_constants_buffer.create();
@ -585,11 +585,17 @@ bool GLGSRender::load_program()
if (fragment_constants_sz > max_buffer_sz)
max_buffer_sz = fragment_constants_sz;
u32 is_alpha_tested = !!(rsx::method_registers[NV4097_SET_ALPHA_TEST_ENABLE]);
u8 alpha_ref_raw = (u8)(rsx::method_registers[NV4097_SET_ALPHA_REF] & 0xFF);
float alpha_ref = alpha_ref_raw / 255.f;
std::vector<u8> client_side_buf(max_buffer_sz);
fill_scale_offset_data(client_side_buf.data(), false);
memcpy(client_side_buf.data() + 16 * sizeof(float), &rsx::method_registers[NV4097_SET_FOG_PARAMS], sizeof(float));
memcpy(client_side_buf.data() + 17 * sizeof(float), &rsx::method_registers[NV4097_SET_FOG_PARAMS + 1], sizeof(float));
memcpy(client_side_buf.data() + 18 * sizeof(float), &is_alpha_tested, sizeof(u32));
memcpy(client_side_buf.data() + 19 * sizeof(float), &alpha_ref, sizeof(float));
m_scale_offset_buffer.data(m_scale_offset_buffer.size(), nullptr);
m_scale_offset_buffer.sub_data(0, m_scale_offset_buffer.size(), client_side_buf.data());

View File

@ -35,6 +35,8 @@ void GLVertexDecompilerThread::insertHeader(std::stringstream &OS)
OS << " mat4 scaleOffsetMat;" << std::endl;
OS << " float fog_param0;\n";
OS << " float fog_param1;\n";
OS << " uint alpha_test;\n";
OS << " float alpha_ref;\n";
OS << "};" << std::endl;
}

View File

@ -37,6 +37,8 @@ void VKFragmentDecompilerThread::insertHeader(std::stringstream & OS)
OS << " mat4 scaleOffsetMat;" << std::endl;
OS << " float fog_param0;" << std::endl;
OS << " float fog_param1;" << std::endl;
OS << " uint alpha_test;" << std::endl;
OS << " float alpha_ref;" << std::endl;
OS << "};" << std::endl << std::endl;
vk::glsl::program_input in;
@ -219,10 +221,14 @@ void VKFragmentDecompilerThread::insertMainEnd(std::stringstream & OS)
{ "ocol3", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r4" : "h8" },
};
std::string first_output_name;
for (int i = 0; i < sizeof(table) / sizeof(*table); ++i)
{
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", table[i].second))
{
OS << " " << table[i].first << " = " << table[i].second << ";" << std::endl;
if (first_output_name.empty()) first_output_name = table[i].first;
}
}
if (m_ctrl & CELL_GCM_SHADER_CONTROL_DEPTH_EXPORT)
@ -237,6 +243,30 @@ void VKFragmentDecompilerThread::insertMainEnd(std::stringstream & OS)
}
}
if (!first_output_name.empty())
{
switch (m_prog.alpha_func)
{
case rsx::comparaison_function::equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a != alpha_ref) discard;\n";
break;
case rsx::comparaison_function::not_equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a == alpha_ref) discard;\n";
break;
case rsx::comparaison_function::less_or_equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a > alpha_ref) discard;\n";
break;
case rsx::comparaison_function::less:
OS << " if (bool(alpha_test) && " << first_output_name << ".a >= alpha_ref) discard;\n";
break;
case rsx::comparaison_function::greater:
OS << " if (bool(alpha_test) && " << first_output_name << ".a <= alpha_ref) discard;\n";
break;
case rsx::comparaison_function::greater_or_equal:
OS << " if (bool(alpha_test) && " << first_output_name << ".a < alpha_ref) discard;\n";
break;
}
}
OS << "}" << std::endl;
}

View File

@ -934,9 +934,14 @@ bool VKGSRender::load_program()
stream_vector((char*)buf + 48, 0, 0, 0, (u32&)one);
}
memset((char*)buf+64, 0, 8);
u32 is_alpha_tested = !!(rsx::method_registers[NV4097_SET_ALPHA_TEST_ENABLE]);
u8 alpha_ref_raw = (u8)(rsx::method_registers[NV4097_SET_ALPHA_REF] & 0xFF);
float alpha_ref = alpha_ref_raw / 255.f;
memcpy((char*)buf + 64, &rsx::method_registers[NV4097_SET_FOG_PARAMS], sizeof(float));
memcpy((char*)buf + 68, &rsx::method_registers[NV4097_SET_FOG_PARAMS + 1], sizeof(float));
memcpy((char*)buf + 72, &is_alpha_tested, sizeof(u32));
memcpy((char*)buf + 76, &alpha_ref, sizeof(float));
m_uniform_buffer_ring_info.unmap();
const size_t vertex_constants_offset = m_uniform_buffer_ring_info.alloc<256>(512 * 4 * sizeof(float));

View File

@ -35,6 +35,8 @@ void VKVertexDecompilerThread::insertHeader(std::stringstream &OS)
OS << " mat4 scaleOffsetMat;" << std::endl;
OS << " float fog_param0;\n";
OS << " float fog_param1;\n";
OS << " uint alpha_test;\n";
OS << " float alpha_ref;\n";
OS << "};" << std::endl;
vk::glsl::program_input in;