Skip to content

Commit

Permalink
skip entity culling and wind compute if they are zero anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jan 11, 2024
1 parent bf5d86e commit 0aa9eea
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
2 changes: 2 additions & 0 deletions WickedEngine/wiRenderPath3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ namespace wi

wi::renderer::ComputeTiledLightCulling(
tiledLightResources,
visibility_main,
debugUAV,
cmd
);
Expand Down Expand Up @@ -1132,6 +1133,7 @@ namespace wi

wi::renderer::ComputeTiledLightCulling(
tiledLightResources_planarReflection,
visibility_reflection,
Texture(),
cmd
);
Expand Down
92 changes: 60 additions & 32 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4265,15 +4265,25 @@ void UpdateRenderData(
{
auto range = wi::profiler::BeginRangeGPU("Wind", cmd);
device->EventBegin("Wind", cmd);

device->BindComputeShader(&shaders[CSTYPE_WIND], cmd);
device->BindUAV(&textures[TEXTYPE_3D_WIND], 0, cmd);
device->BindUAV(&textures[TEXTYPE_3D_WIND_PREV], 1, cmd);
const TextureDesc& desc = textures[TEXTYPE_3D_WIND].GetDesc();
device->Dispatch(desc.width / 8, desc.height / 8, desc.depth / 8, cmd);
if (
vis.scene->weather.windDirection.x == 0 &&
vis.scene->weather.windDirection.y == 0 &&
vis.scene->weather.windDirection.z == 0
)
{
device->ClearUAV(&textures[TEXTYPE_3D_WIND], 0, cmd);
device->ClearUAV(&textures[TEXTYPE_3D_WIND_PREV], 0, cmd);
}
else
{
device->BindComputeShader(&shaders[CSTYPE_WIND], cmd);
device->BindUAV(&textures[TEXTYPE_3D_WIND], 0, cmd);
device->BindUAV(&textures[TEXTYPE_3D_WIND_PREV], 1, cmd);
const TextureDesc& desc = textures[TEXTYPE_3D_WIND].GetDesc();
device->Dispatch(desc.width / 8, desc.height / 8, desc.depth / 8, cmd);
}
barrier_stack.push_back(GPUBarrier::Image(&textures[TEXTYPE_3D_WIND], ResourceState::UNORDERED_ACCESS, textures[TEXTYPE_3D_WIND].desc.layout));
barrier_stack.push_back(GPUBarrier::Image(&textures[TEXTYPE_3D_WIND_PREV], ResourceState::UNORDERED_ACCESS, textures[TEXTYPE_3D_WIND_PREV].desc.layout));

device->EventEnd(cmd);
wi::profiler::EndRange(range);
}
Expand Down Expand Up @@ -8837,13 +8847,48 @@ void CreateTiledLightResources(TiledLightResources& res, XMUINT2 resolution)
}
void ComputeTiledLightCulling(
const TiledLightResources& res,
const Visibility& vis,
const Texture& debugUAV,
CommandList cmd
)
{
BindCommonResources(cmd);
auto range = wi::profiler::BeginRangeGPU("Entity Culling", cmd);

// Initial barriers to put all resources into UAV:
{
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),
};
device->Barrier(barriers, arraysize(barriers), cmd);
}

if (
vis.visibleLights.empty() &&
vis.visibleDecals.empty() &&
vis.visibleEnvProbes.empty()
)
{
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);
{
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),
};
device->Barrier(barriers, arraysize(barriers), cmd);
}
device->EventEnd(cmd);
wi::profiler::EndRange(range);
return;
}

BindCommonResources(cmd);

// Frustum computation
{
device->EventBegin("Tile Frustums", cmd);
Expand All @@ -8854,20 +8899,20 @@ void ComputeTiledLightCulling(
};
device->BindUAVs(uavs, 0, arraysize(uavs), cmd);

{
GPUBarrier barriers[] = {
GPUBarrier::Buffer(&res.tileFrustums, ResourceState::SHADER_RESOURCE, ResourceState::UNORDERED_ACCESS)
};
device->Barrier(barriers, arraysize(barriers), cmd);
}

device->Dispatch(
(res.tileCount.x + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE,
(res.tileCount.y + TILED_CULLING_BLOCKSIZE - 1) / TILED_CULLING_BLOCKSIZE,
1,
cmd
);

{
GPUBarrier barriers[] = {
GPUBarrier::Buffer(&res.tileFrustums, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE),
};
device->Barrier(barriers, arraysize(barriers), cmd);
}

device->EventEnd(cmd);
}

Expand All @@ -8893,25 +8938,8 @@ void ComputeTiledLightCulling(
};
device->BindUAVs(uavs, 0, arraysize(uavs), cmd);

{
GPUBarrier barriers[] = {
GPUBarrier::Buffer(&res.tileFrustums, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE),
GPUBarrier::Buffer(&res.entityTiles_Transparent, ResourceState::SHADER_RESOURCE, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Buffer(&res.entityTiles_Opaque, ResourceState::SHADER_RESOURCE, ResourceState::UNORDERED_ACCESS),
};
device->Barrier(barriers, arraysize(barriers), cmd);
}

device->Dispatch(res.tileCount.x, res.tileCount.y, 1, cmd);

{
GPUBarrier barriers[] = {
GPUBarrier::Buffer(&res.entityTiles_Opaque, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE),
GPUBarrier::Buffer(&res.entityTiles_Transparent, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE),
};
device->Barrier(barriers, arraysize(barriers), cmd);
}

device->EventEnd(cmd);
}

Expand Down
1 change: 1 addition & 0 deletions WickedEngine/wiRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ namespace wi::renderer
// Compute light grid tiles
void ComputeTiledLightCulling(
const TiledLightResources& res,
const Visibility& vis,
const wi::graphics::Texture& debugUAV,
wi::graphics::CommandList cmd
);
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 357;
const int revision = 358;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit 0aa9eea

Please sign in to comment.