[Vulkan] Color exponent bias and gamma conversion

This commit is contained in:
Triang3l
2022-06-25 20:35:13 +03:00
parent b1be33004a
commit d30d59883a
6 changed files with 180 additions and 13 deletions

View File

@@ -3267,6 +3267,13 @@ void VulkanCommandProcessor::UpdateSystemConstantValues(
auto pa_cl_vte_cntl = regs.Get<reg::PA_CL_VTE_CNTL>();
int32_t vgt_indx_offset = int32_t(regs[XE_GPU_REG_VGT_INDX_OFFSET].u32);
// Get the color info register values for each render target.
reg::RB_COLOR_INFO color_infos[xenos::kMaxColorRenderTargets];
for (uint32_t i = 0; i < xenos::kMaxColorRenderTargets; ++i) {
color_infos[i] = regs.Get<reg::RB_COLOR_INFO>(
reg::RB_COLOR_INFO::rt_register_indices[i]);
}
bool dirty = false;
// Flags.
@@ -3288,6 +3295,14 @@ void VulkanCommandProcessor::UpdateSystemConstantValues(
if (pa_cl_vte_cntl.vtx_w0_fmt) {
flags |= SpirvShaderTranslator::kSysFlag_WNotReciprocal;
}
// Gamma writing.
// TODO(Triang3l): Gamma as sRGB check.
for (uint32_t i = 0; i < xenos::kMaxColorRenderTargets; ++i) {
if (color_infos[i].color_format ==
xenos::ColorRenderTargetFormat::k_8_8_8_8_GAMMA) {
flags |= SpirvShaderTranslator::kSysFlag_ConvertColor0ToGamma << i;
}
}
dirty |= system_constants_.flags != flags;
system_constants_.flags = flags;
@@ -3356,6 +3371,29 @@ void VulkanCommandProcessor::UpdateSystemConstantValues(
}
}
// Color exponent bias.
for (uint32_t i = 0; i < xenos::kMaxColorRenderTargets; ++i) {
reg::RB_COLOR_INFO color_info = color_infos[i];
// Exponent bias is in bits 20:25 of RB_COLOR_INFO.
int32_t color_exp_bias = color_info.color_exp_bias;
if (render_target_cache_->GetPath() ==
RenderTargetCache::Path::kHostRenderTargets &&
(color_info.color_format == xenos::ColorRenderTargetFormat::k_16_16 &&
!render_target_cache_->IsFixedRG16TruncatedToMinus1To1() ||
color_info.color_format ==
xenos::ColorRenderTargetFormat::k_16_16_16_16 &&
!render_target_cache_->IsFixedRGBA16TruncatedToMinus1To1())) {
// Remap from -32...32 to -1...1 by dividing the output values by 32,
// losing blending correctness, but getting the full range.
color_exp_bias -= 5;
}
float color_exp_bias_scale;
*reinterpret_cast<int32_t*>(&color_exp_bias_scale) =
UINT32_C(0x3F800000) + (color_exp_bias << 23);
dirty |= system_constants_.color_exp_bias[i] != color_exp_bias_scale;
system_constants_.color_exp_bias[i] = color_exp_bias_scale;
}
if (dirty) {
current_graphics_descriptor_set_values_up_to_date_ &=
~(UINT32_C(1) << SpirvShaderTranslator::kDescriptorSetSystemConstants);

View File

@@ -784,11 +784,10 @@ bool VulkanRenderTargetCache::Resolve(const Memory& memory,
bool draw_resolution_scaled = IsDrawResolutionScaled();
draw_util::ResolveInfo resolve_info;
// TODO(Triang3l): Truncation of fixed16 (but not fixed16 as float16) range to
// -1 to 1.
if (!draw_util::GetResolveInfo(
register_file(), memory, trace_writer_, draw_resolution_scale_x(),
draw_resolution_scale_y(), false, false, resolve_info)) {
draw_resolution_scale_y(), IsFixedRG16TruncatedToMinus1To1(),
IsFixedRGBA16TruncatedToMinus1To1(), resolve_info)) {
return false;
}

View File

@@ -128,6 +128,20 @@ class VulkanRenderTargetCache final : public RenderTargetCache {
return last_update_framebuffer_;
}
// Using R16G16[B16A16]_SNORM, which are -1...1, not the needed -32...32.
// Persistent data doesn't depend on this, so can be overriden by per-game
// configuration.
bool IsFixedRG16TruncatedToMinus1To1() const {
// TODO(Triang3l): Not float16 condition.
return GetPath() == Path::kHostRenderTargets &&
!cvars::snorm16_render_target_full_range;
}
bool IsFixedRGBA16TruncatedToMinus1To1() const {
// TODO(Triang3l): Not float16 condition.
return GetPath() == Path::kHostRenderTargets &&
!cvars::snorm16_render_target_full_range;
}
bool depth_float24_round() const { return depth_float24_round_; }
bool msaa_2x_attachments_supported() const {