Skip to content

Optimizing light loop part 2 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 17, 2020
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
83dd52a
Saving 10% off the PrepareLightForGPU
FrancescoC-unity Mar 24, 2020
09444e6
18% decrease in cost with this
FrancescoC-unity Mar 24, 2020
22f85bf
Around 12% cost shaving off GetLightData
FrancescoC-unity Mar 24, 2020
9520b38
Around 6.5% win here
FrancescoC-unity Mar 24, 2020
6af3741
Faster View matrix flip
FrancescoC-unity Mar 25, 2020
8f573d1
Missing *=-1
FrancescoC-unity Mar 25, 2020
d1546d6
About 7% win in preprocess light data
FrancescoC-unity Mar 25, 2020
340540a
Another small batch
FrancescoC-unity Mar 25, 2020
6337d37
Small cleanup for first optimization pass
FrancescoC-unity Mar 25, 2020
04409af
Tiny bit more cleanup
FrancescoC-unity Mar 25, 2020
18f5ce0
Make UpdateShadowRequests 12% cheaper
FrancescoC-unity Mar 25, 2020
6fab90f
Address review points
FrancescoC-unity Mar 25, 2020
c7d2f8f
A bit less than 20% win in ExtractPointLightData
FrancescoC-unity Mar 25, 2020
50140cf
Add comment
FrancescoC-unity Mar 25, 2020
e6a852b
changelog
FrancescoC-unity Mar 25, 2020
9734944
25% reduction of ExtractPointLightData
FrancescoC-unity Mar 25, 2020
a032bd3
18% win in UpdateShadowRequest
FrancescoC-unity Mar 25, 2020
b89293d
Another around 11% win for UpdateShadowRequest
FrancescoC-unity Mar 26, 2020
530d2e3
Merge branch 'HDRP/optimizing-light-loop' into HDRP/optimizing-light-…
FrancescoC-unity Mar 26, 2020
bc1a292
Move matrix multiply utils to core
FrancescoC-unity Mar 26, 2020
1134251
less lighttype computation
FrancescoC-unity Mar 26, 2020
6a625d2
Ooops
FrancescoC-unity Mar 27, 2020
815e969
Merge branch 'HDRP/staging' into HDRP/optimizing-light-loop-when-shadows
FrancescoC-unity Mar 27, 2020
63766fb
fixup changelog
FrancescoC-unity Mar 27, 2020
ddde84e
TMP merge staging, will need to fix more stuff on this.
FrancescoC-unity Apr 1, 2020
cb47788
Proper merge
FrancescoC-unity Apr 1, 2020
cf4f7c6
Missing leftovers .
FrancescoC-unity Apr 1, 2020
7556895
I'll manage to submit it all one day...
FrancescoC-unity Apr 1, 2020
f6aafb9
Merge branch 'HDRP/staging' into HDRP/optimizing-light-loop-when-shadows
sebastienlagarde Apr 8, 2020
e12c64d
Merge branch 'HDRP/staging' into HDRP/optimizing-light-loop-when-shadows
sebastienlagarde Apr 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Small cleanup for first optimization pass
  • Loading branch information
FrancescoC-unity committed Mar 25, 2020
commit 6337d376084af3f54135c53dd92ff1e6c6936c1c
Original file line number Diff line number Diff line change
Expand Up @@ -1552,31 +1552,6 @@ internal void GetLightData(CommandBuffer cmd, HDCamera hdCamera, HDShadowSetting
m_lightList.lights.Add(lightData);
}

Vector3 TMP_MULTIPLY(Matrix4x4 worldToView, Vector3 positionWS)
{
return worldToView.MultiplyPoint(positionWS);
}

Matrix4x4 MatrixMultiply(Matrix4x4 worldToView, Matrix4x4 lightToWorld)
{
return worldToView * lightToWorld;
}

void GetAxisA(Matrix4x4 worldToView, Matrix4x4 lightToWorld, out Vector3 xAxisVS, out Vector3 yAxisVS, out Vector3 zAxisVS)
{
Matrix4x4 lightToView = MatrixMultiply(worldToView, lightToWorld);
xAxisVS = lightToView.GetColumn(0);
yAxisVS = lightToView.GetColumn(1);
zAxisVS = lightToView.GetColumn(2);
}

void GetAxisB(Matrix4x4 worldToView, Matrix4x4 lightToWorld, out Vector3 xAxisVS, out Vector3 yAxisVS, out Vector3 zAxisVS)
{
xAxisVS = worldToView.MultiplyVector(lightToWorld.GetColumn(0));
yAxisVS = worldToView.MultiplyVector(lightToWorld.GetColumn(1));
zAxisVS = worldToView.MultiplyVector(lightToWorld.GetColumn(2));
}

// TODO: we should be able to do this calculation only with LightData without VisibleLight light, but for now pass both
void GetLightVolumeDataAndBound(LightCategory lightCategory, GPULightType gpuLightType, LightVolumeType lightVolumeType,
VisibleLight light, LightData lightData, Vector3 lightDimensions, Matrix4x4 worldToView, int viewIndex)
Expand All @@ -1585,7 +1560,7 @@ void GetLightVolumeDataAndBound(LightCategory lightCategory, GPULightType gpuLig
var range = lightDimensions.z;
var lightToWorld = light.localToWorldMatrix;
Vector3 positionWS = lightData.positionRWS;
Vector3 positionVS = TMP_MULTIPLY(worldToView, positionWS);
Vector3 positionVS = worldToView.MultiplyPoint(positionWS);

Vector3 xAxisVS = worldToView.MultiplyVector(lightToWorld.GetColumn(0));
Vector3 yAxisVS = worldToView.MultiplyVector(lightToWorld.GetColumn(1));
Expand Down Expand Up @@ -2251,9 +2226,13 @@ void PrepareGPULightdata(CommandBuffer cmd, HDCamera hdCamera, CullingResults cu
// The lightLoop is in charge, not the shadow pass.
// For now we will still apply the maximum of shadow here but we don't apply the sorting by priority + slot allocation yet

// Determine non-per light data
// Determine data that is light independent
int viewCount = hdCamera.viewCount;
var worldToMatrices = GetWorldToViewMatrices(hdCamera, viewCount);
List<Matrix4x4> worldToMatrices = new List<Matrix4x4>(viewCount);
for (int viewIndex = 0; viewIndex < viewCount; ++viewIndex)
{
worldToMatrices.Add(GetWorldToViewMatrix(hdCamera, viewIndex));
}
BoolScalableSetting contactShadowScalableSetting = HDAdditionalLightData.ScalableSettings.UseContactShadow(m_Asset);

// 2. Go through all lights, convert them to GPU format.
Expand Down