@@ -319,50 +319,41 @@ void vhCmdBackendState::BE_UpdateBuffer( vhBackendBuffer& bbuf, uint64_t offset,
319319 }
320320}
321321
322- nvrhi::FramebufferHandle vhCmdBackendState::BE_GetFrameBuffer ( const std::vector< vhTexture >& colours, vhTexture depth, int mip, int layer )
322+ nvrhi::FramebufferHandle vhCmdBackendState::BE_GetFrameBuffer ( const std::vector< vhState::RenderTarget >& colourAttachment, const vhState::RenderTarget& depthAttachment )
323323{
324- // TODO: ################ Finish implementation ################
325- // TODO: THIS IS UNTESTED!! Use this at graphics render time in future.
326-
327- // Combine all inputs into a hash key
328- uint64_t hashInput[32 ]; // Enough for color attachments + depth + mip/layer
329- int i = 0 ;
330- for ( auto c : colours ) hashInput[i++] = ( uint64_t ) c;
331- hashInput[i++] = ( uint64_t ) depth;
332- hashInput[i++] = ( uint32_t ) mip | ( ( uint32_t ) layer << 16 );
333-
334- uint64_t key = komihash ( hashInput, i * sizeof ( uint64_t ), 0 );
335-
336- if ( backendFramebuffers.find ( key ) == backendFramebuffers.end () )
324+ nvrhi::FramebufferDesc desc;
325+ for ( const auto & rt : colourAttachment )
337326 {
338- nvrhi::FramebufferDesc desc;
339- for ( auto texture : colours )
327+ if ( rt.texture == VRHI_INVALID_HANDLE ) continue ;
328+ auto it = backendTextures.find ( rt.texture );
329+ if ( it != backendTextures.end () && it->second ->handle )
340330 {
341- auto it = backendTextures. find ( texture ) ;
342- if ( it != backendTextures. end () && it->second ->handle )
343- {
344- desc. addColorAttachment ( nvrhi::FramebufferAttachment ( it-> second -> handle )
345- . setArraySlice ( layer )
346- . setMipLevel ( mip ) );
347- }
331+ nvrhi::FramebufferAttachment att ;
332+ att. setTexture ( it->second ->handle );
333+ att. setArraySlice ( rt. arrayLayer );
334+ att. setMipLevel ( rt. mipLevel );
335+ att. setFormat ( rt. formatOverride );
336+ att. setReadOnly ( rt. readOnly );
337+ desc. addColorAttachment ( att );
348338 }
339+ }
349340
350- if ( depth != VRHI_INVALID_HANDLE )
341+ if ( depthAttachment.texture != VRHI_INVALID_HANDLE )
342+ {
343+ auto it = backendTextures.find ( depthAttachment.texture );
344+ if ( it != backendTextures.end () && it->second ->handle )
351345 {
352- auto it = backendTextures. find ( depth ) ;
353- if ( it != backendTextures. end () && it->second ->handle )
354- {
355- desc. setDepthAttachment ( nvrhi::FramebufferAttachment ( it-> second -> handle )
356- . setArraySlice ( layer )
357- . setMipLevel ( mip ) );
358- }
346+ nvrhi::FramebufferAttachment att ;
347+ att. setTexture ( it->second ->handle );
348+ att. setArraySlice ( depthAttachment. arrayLayer );
349+ att. setMipLevel ( depthAttachment. mipLevel );
350+ att. setFormat ( depthAttachment. formatOverride );
351+ att. setReadOnly ( depthAttachment. readOnly );
352+ desc. setDepthAttachment ( att );
359353 }
360-
361- std::lock_guard< std::mutex > lock ( g_nvRHIStateMutex );
362- backendFramebuffers[key] = g_vhDevice->createFramebuffer ( desc );
363354 }
364355
365- return backendFramebuffers[key] ;
356+ return vhFBOCacheGet ( desc ) ;
366357}
367358
368359bool vhCmdBackendState::BE_PresubmitCommon_PipelineDesc (
@@ -1172,7 +1163,6 @@ void vhCmdBackendState::shutdown()
11721163 backendTextures.clear ();
11731164 backendBuffers.clear ();
11741165 backendShaders.clear ();
1175- backendFramebuffers.clear ();
11761166
11771167 // Clear static caches
11781168 s_layoutToShader.clear ();
@@ -1209,8 +1199,7 @@ void vhCmdBackendState::Handle_vhResetTexture( VIDL_vhResetTexture* cmd )
12091199void vhCmdBackendState::Handle_vhResizeCleanup ( VIDL_vhResizeCleanup* cmd )
12101200{
12111201 BE_CmdRAII cmdRAII ( cmd );
1212- std::lock_guard< std::mutex > lock ( g_nvRHIStateMutex );
1213- backendFramebuffers.clear ();
1202+ vhFBOCacheReset ();
12141203}
12151204
12161205void vhCmdBackendState::Handle_vhDestroyTexture ( VIDL_vhDestroyTexture* cmd )
0 commit comments