rsx: Add support for non-projective shadow sampling

- Fixes missing shadows in persona 5

vk: Enable polygon depth bias a.k.a polygonOffset
- Fixes shadow acne in persona 5
This commit is contained in:
kd-11 2017-09-18 20:58:51 +03:00
parent 3836b40bf7
commit 6b96a2022a
8 changed files with 37 additions and 2 deletions

View File

@ -519,6 +519,12 @@ bool FragmentProgramDecompiler::handle_tex_srb(u32 opcode)
SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE1D));
return true;
case rsx::texture_dimension_extended::texture_dimension_2d:
if (DstExpectsSca() && (m_prog.shadow_textures & (1 << dst.tex_num)))
{
m_shadow_sampled_textures |= (1 << dst.tex_num);
SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SHADOW2D) + ".r", false); //No swizzle mask on shadow lookup
return true;
}
if (m_prog.redirected_textures & (1 << dst.tex_num))
SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_DEPTH_RGBA));
else
@ -547,7 +553,7 @@ bool FragmentProgramDecompiler::handle_tex_srb(u32 opcode)
if (DstExpectsSca() && (m_prog.shadow_textures & (1 << dst.tex_num)))
{
m_shadow_sampled_textures |= (1 << dst.tex_num);
SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_PROJ) + ".r", false); //No swizzle mask on shadow lookup
SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SHADOW2D_PROJ) + ".r", false); //No swizzle mask on shadow lookup
}
else
SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_PROJ));

View File

@ -25,6 +25,8 @@ enum class FUNCTION {
FUNCTION_TEXTURE_SAMPLE2D_PROJ,
FUNCTION_TEXTURE_SAMPLE2D_LOD,
FUNCTION_TEXTURE_SAMPLE2D_GRAD,
FUNCTION_TEXTURE_SHADOW2D,
FUNCTION_TEXTURE_SHADOW2D_PROJ,
FUNCTION_TEXTURE_SAMPLECUBE,
FUNCTION_TEXTURE_SAMPLECUBE_PROJ,
FUNCTION_TEXTURE_SAMPLECUBE_LOD,

View File

@ -52,6 +52,8 @@ std::string getFunctionImp(FUNCTION f)
return "$t.SampleLevel($tsampler, $0.x, $1)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE1D_GRAD:
return "$t.SampleGrad($tsampler, $0.x, $1, $2)";
case FUNCTION::FUNCTION_TEXTURE_SHADOW2D: //TODO
case FUNCTION::FUNCTION_TEXTURE_SHADOW2D_PROJ:
case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D:
return "$t.Sample($tsampler, $0.xy * $t_scale)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_PROJ:

View File

@ -44,6 +44,10 @@ namespace gl
return "textureLod($t, $0.xy * $t_coord_scale, $1.x)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_GRAD:
return "textureGrad($t, $0.xy * $t_coord_scale , $1.xy, $2.xy)";
case FUNCTION::FUNCTION_TEXTURE_SHADOW2D:
return "texture($t, $0.xyz)";
case FUNCTION::FUNCTION_TEXTURE_SHADOW2D_PROJ:
return "textureProj($t, $0, $1.x)"; // Note: $1.x is bias
case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE:
return "texture($t, $0.xyz)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE_PROJ:

View File

@ -264,6 +264,8 @@ void GLGSRender::begin()
gl_state.enable(rsx::method_registers.poly_offset_line_enabled(), GL_POLYGON_OFFSET_LINE);
gl_state.enable(rsx::method_registers.poly_offset_fill_enabled(), GL_POLYGON_OFFSET_FILL);
//offset_bias is the constant factor, multiplied by the implementation factor R
//offst_scale is the slope factor, multiplied by the triangle slope factor M
gl_state.polygon_offset(rsx::method_registers.poly_offset_scale(), rsx::method_registers.poly_offset_bias());
if (gl_state.enable(rsx::method_registers.cull_face_enabled(), GL_CULL_FACE))

View File

@ -48,6 +48,10 @@ namespace vk
return "textureLod($t, $0.xy * texture_parameters[$_i].xy, $1.x)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_GRAD:
return "textureGrad($t, $0.xy * texture_parameters[$_i].xy, $1.xy, $2.xy)"; // Note: $1.x is bias
case FUNCTION::FUNCTION_TEXTURE_SHADOW2D:
return "texture($t, $0.xyz)";
case FUNCTION::FUNCTION_TEXTURE_SHADOW2D_PROJ:
return "textureProj($t, $0, $1.x)"; // Note: $1.x is bias
case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE:
return "texture($t, $0.xyz)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE_PROJ:

View File

@ -909,6 +909,18 @@ void VKGSRender::begin()
vkCmdSetLineWidth(*m_current_command_buffer, actual_line_width);
if (rsx::method_registers.poly_offset_fill_enabled())
{
//offset_bias is the constant factor, multiplied by the implementation factor R
//offst_scale is the slope factor, multiplied by the triangle slope factor M
vkCmdSetDepthBias(*m_current_command_buffer, rsx::method_registers.poly_offset_bias(), 0.f, rsx::method_registers.poly_offset_scale());
}
else
{
//Zero bias value - disables depth bias
vkCmdSetDepthBias(*m_current_command_buffer, 0.f, 0.f, 0.f);
}
//TODO: Set up other render-state parameters into the program pipeline
std::chrono::time_point<steady_clock> stop = steady_clock::now();
@ -1837,7 +1849,9 @@ bool VKGSRender::check_program_status()
properties.rs.polygonMode = VK_POLYGON_MODE_FILL;
properties.rs.depthClampEnable = VK_FALSE;
properties.rs.rasterizerDiscardEnable = VK_FALSE;
properties.rs.depthBiasEnable = VK_FALSE;
//Disabled by setting factors to 0 as needed
properties.rs.depthBiasEnable = VK_TRUE;
if (rsx::method_registers.cull_face_enabled())
properties.rs.cullMode = vk::get_cull_face(rsx::method_registers.cull_face_mode());

View File

@ -122,6 +122,7 @@ struct VKTraits
dynamic_state_descriptors[dynamic_state_info.dynamicStateCount++] = VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK;
dynamic_state_descriptors[dynamic_state_info.dynamicStateCount++] = VK_DYNAMIC_STATE_STENCIL_WRITE_MASK;
dynamic_state_descriptors[dynamic_state_info.dynamicStateCount++] = VK_DYNAMIC_STATE_STENCIL_REFERENCE;
dynamic_state_descriptors[dynamic_state_info.dynamicStateCount++] = VK_DYNAMIC_STATE_DEPTH_BIAS;
dynamic_state_info.pDynamicStates = dynamic_state_descriptors;
VkPipelineVertexInputStateCreateInfo vi = { VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO };