[GPU] 8-bit PWL gamma RT as linear 16-bit UNorm on the host
With render target HLE, directly store linear values as R16G16B16A16_UNORM without gamma conversion, as this format provides more than enough bits (need at least 11 per component due to the maximum scale being 2^3 in the piecewise linear gamma curve) to represent linear values without precision loss. This makes blending work correctly in linear space, improving quality of transparency, lighting passes, and fixing issues such as transparent parts of impact and footstep decals in 4D5307E6 being bright instead. The new behavior is enabled by default, as it hugely improves the accuracy of emulation of this format, that is pretty commonplace in Xbox 360 games, with likely just a small GPU memory and bandwidth usage increase, compared to the alternatives that were previously available on the HLE RB path. It's currently implemented only on Direct3D 12, as most of the current GPU emulation code is planned to be phased out and redone, and no methods other than 8-bit with pre-conversion were implemented on Vulkan previously. To implement on Vulkan later, same conversion as in the Direct3D 12 implementation will need to be done in ownership transfer and resolve shaders. Currently it's somewhat inconvenient to decouple the conversion functions in `SpirvShaderTranslator` from an instance of the translator due to vector constant usage. Later, simpler SPIR-V generation functions may be added (`spv::Builder` usage in general is overly verbose). The previously default method (8-bit storage with pre-conversion in shaders and incorrect blending) can be re-enabled by setting the "gamma_render_target_as_unorm16" configuration option to `false`. This may be useful if the game, for instance, switches between 8_8_8_8_GAMMA and 8_8_8_8 formats for the same data frequently, as switching will result in EDRAM range ownership transfer data copying now. Also, the old path is preserved for Vulkan devices not supporting R16G16B16A16_UNORM with blending. The other workaround that was available previously, replacing the PWL encoding with host hardware sRGB with linear-space blending in render target management and in texture fetching, was also inherently inaccurate in many ways (especially when games have their own PWL encoding math, like 4541080F that displayed incorrect colors on the loading screen), and required tracking of the encoding needed for ranges in the memory. The sRGB workaround therefore was deleted in this commit, greatly simplifying the code in the parts of render target, texture and memory management and shader generation that were involved in it.
This commit is contained in:
@@ -2203,7 +2203,6 @@ bool D3D12CommandProcessor::IssueDraw(xenos::PrimitiveType primitive_type,
|
||||
if (host_render_targets_used) {
|
||||
bound_depth_and_color_render_target_bits =
|
||||
render_target_cache_->GetLastUpdateBoundRenderTargets(
|
||||
render_target_cache_->gamma_render_target_as_srgb(),
|
||||
bound_depth_and_color_render_target_formats);
|
||||
} else {
|
||||
bound_depth_and_color_render_target_bits = 0;
|
||||
@@ -2496,8 +2495,7 @@ bool D3D12CommandProcessor::IssueDraw(xenos::PrimitiveType primitive_type,
|
||||
// Invalidate textures in memexported memory and watch for changes.
|
||||
for (const draw_util::MemExportRange& memexport_range : memexport_ranges_) {
|
||||
shared_memory_->RangeWrittenByGpu(
|
||||
memexport_range.base_address_dwords << 2, memexport_range.size_bytes,
|
||||
false);
|
||||
memexport_range.base_address_dwords << 2, memexport_range.size_bytes);
|
||||
}
|
||||
if (cvars::d3d12_readback_memexport) {
|
||||
// Read the exported data on the CPU.
|
||||
@@ -3168,7 +3166,8 @@ void D3D12CommandProcessor::UpdateSystemConstantValues(
|
||||
flags |= uint32_t(alpha_test_function)
|
||||
<< DxbcShaderTranslator::kSysFlag_AlphaPassIfLess_Shift;
|
||||
// Gamma writing.
|
||||
if (!render_target_cache_->gamma_render_target_as_srgb()) {
|
||||
if (!(edram_rov_used ||
|
||||
render_target_cache_->gamma_render_target_as_unorm16())) {
|
||||
for (uint32_t i = 0; i < 4; ++i) {
|
||||
if (color_infos[i].color_format ==
|
||||
xenos::ColorRenderTargetFormat::k_8_8_8_8_GAMMA) {
|
||||
@@ -3309,9 +3308,7 @@ void D3D12CommandProcessor::UpdateSystemConstantValues(
|
||||
}
|
||||
|
||||
// Texture signedness / gamma.
|
||||
bool gamma_render_target_as_srgb =
|
||||
render_target_cache_->gamma_render_target_as_srgb();
|
||||
uint32_t textures_resolved = 0;
|
||||
uint32_t textures_resolution_scaled = 0;
|
||||
uint32_t textures_remaining = used_texture_mask;
|
||||
uint32_t texture_index;
|
||||
while (xe::bit_scan_forward(textures_remaining, &texture_index)) {
|
||||
@@ -3327,12 +3324,13 @@ void D3D12CommandProcessor::UpdateSystemConstantValues(
|
||||
dirty |= (texture_signs_uint & texture_signs_mask) != texture_signs_shifted;
|
||||
texture_signs_uint =
|
||||
(texture_signs_uint & ~texture_signs_mask) | texture_signs_shifted;
|
||||
textures_resolved |=
|
||||
uint32_t(texture_cache_->IsActiveTextureResolved(texture_index))
|
||||
textures_resolution_scaled |=
|
||||
uint32_t(texture_cache_->IsActiveTextureResolutionScaled(texture_index))
|
||||
<< texture_index;
|
||||
}
|
||||
dirty |= system_constants_.textures_resolved != textures_resolved;
|
||||
system_constants_.textures_resolved = textures_resolved;
|
||||
dirty |= system_constants_.textures_resolution_scaled !=
|
||||
textures_resolution_scaled;
|
||||
system_constants_.textures_resolution_scaled = textures_resolution_scaled;
|
||||
|
||||
// Log2 of sample count, for alpha to mask and with ROV, for EDRAM address
|
||||
// calculation with MSAA.
|
||||
|
||||
Reference in New Issue
Block a user