From 39facaa1acdb1295c62ab28614a41ee1191f1e27 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Fri, 26 Mar 2021 17:39:04 +0100 Subject: [PATCH] Vulkan can handle FMT_R11G11B10F textures --- .../lighting/ambient_lighting_IBL.ps.hlsl | 3 -- neo/renderer/Image_load.cpp | 2 +- neo/renderer/RenderBackend.cpp | 5 ++- neo/renderer/RenderProgs_embedded.h | 3 -- neo/renderer/Vulkan/Image_VK.cpp | 42 +++++++++++++++++-- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl b/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl index 5fce3734..3cd84546 100644 --- a/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl +++ b/base/renderprogs/builtin/lighting/ambient_lighting_IBL.ps.hlsl @@ -150,11 +150,8 @@ void main( PS_IN fragment, out PS_OUT result ) float2 screenTexCoord = fragment.position.xy * rpWindowCoord.xy; float ao = 1.0; - -#if !defined( USE_VULKAN ) ao = tex2D( samp4, screenTexCoord ).r; //diffuseColor.rgb *= ao; -#endif // evaluate diffuse IBL diff --git a/neo/renderer/Image_load.cpp b/neo/renderer/Image_load.cpp index 1c861377..928ae1f0 100644 --- a/neo/renderer/Image_load.cpp +++ b/neo/renderer/Image_load.cpp @@ -78,7 +78,7 @@ int BitsForFormat( textureFormat_t format ) case FMT_R32F: return 32; case FMT_R11G11B10F: - return 8; + return 32; // RB end case FMT_DEPTH: return 32; diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index b112b9de..302ee04b 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -1353,15 +1353,18 @@ void idRenderBackend::DrawSingleInteraction( drawInteraction_t* din, bool useFas globalImages->brdfLutImage->Bind(); GL_SelectTexture( INTERACTION_TEXUNIT_PROJECTION ); +#if defined( USE_VULKAN ) + globalImages->whiteImage->Bind(); +#else if( !r_useSSAO.GetBool() ) { globalImages->whiteImage->Bind(); - //globalImages->brdfLutImage->Bind(); } else { globalImages->ambientOcclusionImage[0]->Bind(); } +#endif // TODO bind the 3 closest probes GL_SelectTexture( INTERACTION_TEXUNIT_AMBIENT_CUBE1 ); diff --git a/neo/renderer/RenderProgs_embedded.h b/neo/renderer/RenderProgs_embedded.h index 076655dc..12e72388 100644 --- a/neo/renderer/RenderProgs_embedded.h +++ b/neo/renderer/RenderProgs_embedded.h @@ -4625,11 +4625,8 @@ static const cgShaderDef_t cg_renderprogs[] = " float2 screenTexCoord = fragment.position.xy * rpWindowCoord.xy;\n" "\n" " float ao = 1.0;\n" - "\n" - "#if !defined( USE_VULKAN )\n" " ao = tex2D( samp4, screenTexCoord ).r;\n" " //diffuseColor.rgb *= ao;\n" - "#endif\n" "\n" " // evaluate diffuse IBL\n" "\n" diff --git a/neo/renderer/Vulkan/Image_VK.cpp b/neo/renderer/Vulkan/Image_VK.cpp index d8be85e8..2ec73d1f 100644 --- a/neo/renderer/Vulkan/Image_VK.cpp +++ b/neo/renderer/Vulkan/Image_VK.cpp @@ -3,7 +3,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. -Copyright (C) 2013-2018 Robert Beckebans +Copyright (C) 2013-2021 Robert Beckebans Copyright (C) 2016-2017 Dustin Land This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -30,6 +30,8 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop #include "precompiled.h" +//#include "../../libs/mesa/format_r11g11b10f.h" + /* ================================================================================================ Contains the Image implementation for Vulkan @@ -166,14 +168,12 @@ static VkComponentMapping VK_GetComponentMappingFromTextureFormat( const texture componentMapping.a = VK_COMPONENT_SWIZZLE_R; break; - /* case FMT_R11G11B10F: componentMapping.r = VK_COMPONENT_SWIZZLE_R; componentMapping.g = VK_COMPONENT_SWIZZLE_G; componentMapping.b = VK_COMPONENT_SWIZZLE_B; componentMapping.a = VK_COMPONENT_SWIZZLE_ONE; break; - */ default: componentMapping.r = VK_COMPONENT_SWIZZLE_R; @@ -678,6 +678,42 @@ void idImage::SubImageUpload( int mipLevel, int x, int y, int z, int width, int data[ i + 1 ] = imgData[ i ]; } } +#if 0 + else if( opts.format == FMT_R11G11B10F ) + { + // convert R11G11B10F to RGBA8 for testing + + byte* imgData = ( byte* )pic; + for( int i = 0; i < size; i += 4 ) + { + // unpack RGBA8 to 3 floats + union + { + uint32 i; + byte b[4]; + } tmp; + + tmp.b[0] = imgData[ i + 0 ]; + tmp.b[1] = imgData[ i + 1 ]; + tmp.b[2] = imgData[ i + 2 ]; + tmp.b[3] = imgData[ i + 3 ]; + + float hdr[3]; + r11g11b10f_to_float3( tmp.i, hdr ); + + // tonemap + hdr[0] = hdr[0] / ( hdr[0] + 1.0f ); + hdr[1] = hdr[1] / ( hdr[1] + 1.0f ); + hdr[2] = hdr[2] / ( hdr[2] + 1.0f ); + + // tonemapped to LDR + data[ i + 0 ] = byte( hdr[0] * 255 ); + data[ i + 1 ] = byte( hdr[1] * 255 ); + data[ i + 2 ] = byte( hdr[2] * 255 ); + data[ i + 3 ] = 255; + } + } +#endif else { memcpy( data, pic, size );