diff --git a/WickedEngine/shaders/ShaderInterop_Renderer.h b/WickedEngine/shaders/ShaderInterop_Renderer.h index e63e87c9c9..ceb1edd022 100644 --- a/WickedEngine/shaders/ShaderInterop_Renderer.h +++ b/WickedEngine/shaders/ShaderInterop_Renderer.h @@ -1022,7 +1022,8 @@ struct ShaderCamera uint4 scissor; // scissor in physical coordinates (left,top,right,bottom) range: [0, internal_resolution] float4 scissor_uv; // scissor in screen UV coordinates (left,top,right,bottom) range: [0, 1] - uint3 entity_culling_tilecount; + uint2 entity_culling_tilecount; + uint entity_culling_tile_bucket_count_flat; // tilecount.x * tilecount.y * SHADER_ENTITY_TILE_BUCKET_COUNT (the total number of uint buckets for the whole screen) uint sample_count; uint2 visibility_tilecount; @@ -1037,9 +1038,9 @@ struct ShaderCamera int texture_velocity_index; int texture_normal_index; int texture_roughness_index; - int buffer_entitytiles_opaque_index; + int buffer_entitytiles_index; - int buffer_entitytiles_transparent_index; + int padding; int texture_reflection_index; int texture_reflection_depth_index; int texture_refraction_index; @@ -1093,6 +1094,7 @@ struct ShaderCamera scissor = {}; scissor_uv = {}; entity_culling_tilecount = {}; + entity_culling_tile_bucket_count_flat = 0; sample_count = {}; visibility_tilecount = {}; visibility_tilecount_flat = {}; @@ -1105,8 +1107,7 @@ struct ShaderCamera texture_velocity_index = -1; texture_normal_index = -1; texture_roughness_index = -1; - buffer_entitytiles_opaque_index = -1; - buffer_entitytiles_transparent_index = -1; + buffer_entitytiles_index = -1; texture_reflection_index = -1; texture_refraction_index = -1; texture_waterriples_index = -1; diff --git a/WickedEngine/shaders/globals.hlsli b/WickedEngine/shaders/globals.hlsli index 7a972513d8..d7f768c797 100644 --- a/WickedEngine/shaders/globals.hlsli +++ b/WickedEngine/shaders/globals.hlsli @@ -281,9 +281,9 @@ inline ShaderMaterial load_material(uint materialIndex) uint load_entitytile(uint tileIndex) { #ifdef TRANSPARENT - return bindless_structured_uint[GetCamera().buffer_entitytiles_transparent_index][tileIndex]; + return bindless_structured_uint[GetCamera().buffer_entitytiles_index][GetCamera().entity_culling_tile_bucket_count_flat + tileIndex]; #else - return bindless_structured_uint[GetCamera().buffer_entitytiles_opaque_index][tileIndex]; + return bindless_structured_uint[GetCamera().buffer_entitytiles_index][tileIndex]; #endif // TRANSPARENT } inline ShaderEntity load_entity(uint entityIndex) diff --git a/WickedEngine/shaders/lightCullingCS.hlsl b/WickedEngine/shaders/lightCullingCS.hlsl index dc3ff68190..7f2b6ea733 100644 --- a/WickedEngine/shaders/lightCullingCS.hlsl +++ b/WickedEngine/shaders/lightCullingCS.hlsl @@ -6,8 +6,7 @@ StructuredBuffer in_Frustums : register(t0); -RWStructuredBuffer EntityTiles_Transparent : register(u0); -RWStructuredBuffer EntityTiles_Opaque : register(u1); +RWStructuredBuffer entityTiles : register(u0); // Group shared variables. groupshared uint uMinDepth; @@ -328,8 +327,8 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : // Each thread will export one bucket from LDS to global memory: for (i = groupIndex; i < SHADER_ENTITY_TILE_BUCKET_COUNT; i += TILED_CULLING_THREADSIZE * TILED_CULLING_THREADSIZE) { - EntityTiles_Opaque[tileBucketsAddress + i] = tile_opaque[i]; - EntityTiles_Transparent[tileBucketsAddress + i] = tile_transparent[i]; + entityTiles[tileBucketsAddress + i] = tile_opaque[i]; + entityTiles[GetCamera().entity_culling_tile_bucket_count_flat + tileBucketsAddress + i] = tile_transparent[i]; } #ifdef DEBUG_TILEDLIGHTCULLING diff --git a/WickedEngine/wiRenderPath3D.cpp b/WickedEngine/wiRenderPath3D.cpp index bf583175da..4e7e38eaef 100644 --- a/WickedEngine/wiRenderPath3D.cpp +++ b/WickedEngine/wiRenderPath3D.cpp @@ -635,8 +635,7 @@ namespace wi camera->texture_velocity_index = device->GetDescriptorIndex(&rtVelocity, SubresourceType::SRV); camera->texture_normal_index = device->GetDescriptorIndex(&visibilityResources.texture_normals, SubresourceType::SRV); camera->texture_roughness_index = device->GetDescriptorIndex(&visibilityResources.texture_roughness, SubresourceType::SRV); - camera->buffer_entitytiles_opaque_index = device->GetDescriptorIndex(&tiledLightResources.entityTiles_Opaque, SubresourceType::SRV); - camera->buffer_entitytiles_transparent_index = device->GetDescriptorIndex(&tiledLightResources.entityTiles_Transparent, SubresourceType::SRV); + camera->buffer_entitytiles_index = device->GetDescriptorIndex(&tiledLightResources.entityTiles, SubresourceType::SRV); camera->texture_reflection_index = device->GetDescriptorIndex(&rtReflection, SubresourceType::SRV); camera->texture_reflection_depth_index = device->GetDescriptorIndex(&depthBuffer_Reflection, SubresourceType::SRV); camera->texture_refraction_index = device->GetDescriptorIndex(&rtSceneCopy, SubresourceType::SRV); @@ -670,8 +669,7 @@ namespace wi camera_reflection.texture_velocity_index = -1; camera_reflection.texture_normal_index = -1; camera_reflection.texture_roughness_index = -1; - camera_reflection.buffer_entitytiles_opaque_index = device->GetDescriptorIndex(&tiledLightResources_planarReflection.entityTiles_Opaque, SubresourceType::SRV); - camera_reflection.buffer_entitytiles_transparent_index = device->GetDescriptorIndex(&tiledLightResources_planarReflection.entityTiles_Transparent, SubresourceType::SRV); + camera_reflection.buffer_entitytiles_index = device->GetDescriptorIndex(&tiledLightResources_planarReflection.entityTiles, SubresourceType::SRV); camera_reflection.texture_reflection_index = -1; camera_reflection.texture_reflection_depth_index = -1; camera_reflection.texture_refraction_index = -1; @@ -990,7 +988,7 @@ namespace wi { wi::renderer::Postprocess_ScreenSpaceShadow( screenspaceshadowResources, - tiledLightResources.entityTiles_Opaque, + tiledLightResources.entityTiles, rtLinearDepth, rtShadow, cmd, @@ -1004,7 +1002,7 @@ namespace wi wi::renderer::Postprocess_RTShadow( rtshadowResources, *scene, - tiledLightResources.entityTiles_Opaque, + tiledLightResources.entityTiles, rtLinearDepth, rtShadow, cmd diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index d17ee3cbde..f2d569ec23 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -8834,15 +8834,12 @@ void CreateTiledLightResources(TiledLightResources& res, XMUINT2 resolution) { GPUBufferDesc bd; bd.stride = sizeof(uint); - bd.size = res.tileCount.x * res.tileCount.y * bd.stride * SHADER_ENTITY_TILE_BUCKET_COUNT; + bd.size = res.tileCount.x * res.tileCount.y * bd.stride * SHADER_ENTITY_TILE_BUCKET_COUNT * 2; // *2: opaque and transparent arrays bd.usage = Usage::DEFAULT; bd.bind_flags = BindFlag::UNORDERED_ACCESS | BindFlag::SHADER_RESOURCE; bd.misc_flags = ResourceMiscFlag::BUFFER_STRUCTURED; - device->CreateBuffer(&bd, nullptr, &res.entityTiles_Opaque); - device->CreateBuffer(&bd, nullptr, &res.entityTiles_Transparent); - - device->SetName(&res.entityTiles_Opaque, "entityTiles_Opaque"); - device->SetName(&res.entityTiles_Transparent, "entityTiles_Transparent"); + device->CreateBuffer(&bd, nullptr, &res.entityTiles); + device->SetName(&res.entityTiles, "entityTiles"); } } void ComputeTiledLightCulling( @@ -8858,8 +8855,7 @@ void ComputeTiledLightCulling( { GPUBarrier barriers[] = { GPUBarrier::Buffer(&res.tileFrustums, ResourceState::SHADER_RESOURCE, ResourceState::UNORDERED_ACCESS), - GPUBarrier::Buffer(&res.entityTiles_Transparent, ResourceState::SHADER_RESOURCE, ResourceState::UNORDERED_ACCESS), - GPUBarrier::Buffer(&res.entityTiles_Opaque, ResourceState::SHADER_RESOURCE, ResourceState::UNORDERED_ACCESS), + GPUBarrier::Buffer(&res.entityTiles, ResourceState::SHADER_RESOURCE, ResourceState::UNORDERED_ACCESS), }; device->Barrier(barriers, arraysize(barriers), cmd); } @@ -8872,13 +8868,11 @@ void ComputeTiledLightCulling( { device->EventBegin("Tiled Entity Clear Only", cmd); device->ClearUAV(&res.tileFrustums, 0, cmd); - device->ClearUAV(&res.entityTiles_Transparent, 0, cmd); - device->ClearUAV(&res.entityTiles_Opaque, 0, cmd); + device->ClearUAV(&res.entityTiles, 0, cmd); { GPUBarrier barriers[] = { GPUBarrier::Buffer(&res.tileFrustums, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE), - GPUBarrier::Buffer(&res.entityTiles_Transparent, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE), - GPUBarrier::Buffer(&res.entityTiles_Opaque, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE), + GPUBarrier::Buffer(&res.entityTiles, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE), }; device->Barrier(barriers, arraysize(barriers), cmd); } @@ -8933,8 +8927,7 @@ void ComputeTiledLightCulling( } const GPUResource* uavs[] = { - &res.entityTiles_Transparent, - &res.entityTiles_Opaque, + &res.entityTiles, }; device->BindUAVs(uavs, 0, arraysize(uavs), cmd); @@ -9822,6 +9815,7 @@ void BindCameraCB( shadercam.scissor_uv.w = (shadercam.scissor.w - 0.5f) * shadercam.internal_resolution_rcp.y; shadercam.entity_culling_tilecount = GetEntityCullingTileCount(shadercam.internal_resolution); + shadercam.entity_culling_tile_bucket_count_flat = shadercam.entity_culling_tilecount.x * shadercam.entity_culling_tilecount.y * SHADER_ENTITY_TILE_BUCKET_COUNT; shadercam.sample_count = camera.sample_count; shadercam.visibility_tilecount = GetVisibilityTileCount(shadercam.internal_resolution); shadercam.visibility_tilecount_flat = shadercam.visibility_tilecount.x * shadercam.visibility_tilecount.y; @@ -9832,8 +9826,7 @@ void BindCameraCB( shadercam.texture_velocity_index = camera.texture_velocity_index; shadercam.texture_normal_index = camera.texture_normal_index; shadercam.texture_roughness_index = camera.texture_roughness_index; - shadercam.buffer_entitytiles_opaque_index = camera.buffer_entitytiles_opaque_index; - shadercam.buffer_entitytiles_transparent_index = camera.buffer_entitytiles_transparent_index; + shadercam.buffer_entitytiles_index = camera.buffer_entitytiles_index; shadercam.texture_reflection_index = camera.texture_reflection_index; shadercam.texture_reflection_depth_index = camera.texture_reflection_depth_index; shadercam.texture_refraction_index = camera.texture_refraction_index; diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index b7e96c60ec..be58891b0e 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -31,12 +31,11 @@ namespace wi::renderer { return (userStencilRef << 4) | static_cast(engineStencilRef); } - constexpr XMUINT3 GetEntityCullingTileCount(XMUINT2 internalResolution) + constexpr XMUINT2 GetEntityCullingTileCount(XMUINT2 internalResolution) { - return XMUINT3( + return XMUINT2( (internalResolution.x + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE, - (internalResolution.y + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE, - 1 + (internalResolution.y + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE ); } constexpr XMUINT2 GetVisibilityTileCount(XMUINT2 internalResolution) @@ -296,10 +295,9 @@ namespace wi::renderer struct TiledLightResources { - XMUINT3 tileCount = {}; + XMUINT2 tileCount = {}; wi::graphics::GPUBuffer tileFrustums; // entity culling frustums - wi::graphics::GPUBuffer entityTiles_Opaque; // culled entity indices (for opaque pass) - wi::graphics::GPUBuffer entityTiles_Transparent; // culled entity indices (for transparent pass) + wi::graphics::GPUBuffer entityTiles; // culled entity indices }; void CreateTiledLightResources(TiledLightResources& res, XMUINT2 resolution); // Compute light grid tiles diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index ec889beec4..a3daaa27b2 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -1125,8 +1125,7 @@ namespace wi::scene int texture_rtshadow_index = -1; int texture_rtdiffuse_index = -1; int texture_surfelgi_index = -1; - int buffer_entitytiles_opaque_index = -1; - int buffer_entitytiles_transparent_index = -1; + int buffer_entitytiles_index = -1; int texture_vxgi_diffuse_index = -1; int texture_vxgi_specular_index = -1; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 34f4c7d523..2d44ffe404 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 358; + const int revision = 359; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);