diff --git a/Content/Editor/Camera/M_Camera.flax b/Content/Editor/Camera/M_Camera.flax index 0631de26c..b5473caa3 100644 --- a/Content/Editor/Camera/M_Camera.flax +++ b/Content/Editor/Camera/M_Camera.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:52c68260bfdf79f3cc9addea31680379c89c804b07a932d363be0254d44f708a -size 38302 +oid sha256:b8b77651be81af931c1e63c1cb411b9f2764b4b0be4a7fa51e2c3c043a063435 +size 38085 diff --git a/Content/Editor/Gizmo/Material.flax b/Content/Editor/Gizmo/Material.flax index c65bf8bfc..b4917f502 100644 --- a/Content/Editor/Gizmo/Material.flax +++ b/Content/Editor/Gizmo/Material.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cc1c77fbc5849a052d5a677c936d3fc1a926d3acde7595d02ef3b3bca6f9e287 -size 36009 +oid sha256:85435f0342a96eeebad705692df74ec19871e28bc35a3d3046f8f63dee4d9334 +size 35945 diff --git a/Content/Editor/Gizmo/MaterialWire.flax b/Content/Editor/Gizmo/MaterialWire.flax index ebd8e8d97..888846500 100644 --- a/Content/Editor/Gizmo/MaterialWire.flax +++ b/Content/Editor/Gizmo/MaterialWire.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:918b4f7c7dde101ebe9b3e757cde61718413408f585159173cd87372671af006 -size 35222 +oid sha256:9ab58f495cdd9fee4c81332a291bbee4f1adc327d7d14b5158d4360aac1ef8fa +size 35158 diff --git a/Content/Editor/Gizmo/SelectionOutlineMaterial.flax b/Content/Editor/Gizmo/SelectionOutlineMaterial.flax index 661897e62..48a87ba88 100644 --- a/Content/Editor/Gizmo/SelectionOutlineMaterial.flax +++ b/Content/Editor/Gizmo/SelectionOutlineMaterial.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:06b86af6ada11a767d70ebb5b633b998bbfc9fcdc507b09597fc8070d7bf4a4e -size 16115 +oid sha256:f578d4b9e0dbd295de0674cf46cfc5d2894db225fd2c3cfc443c6f2e9c7167d3 +size 15941 diff --git a/Content/Editor/Highlight Material.flax b/Content/Editor/Highlight Material.flax index 2b1baa997..9f1de8fcd 100644 --- a/Content/Editor/Highlight Material.flax +++ b/Content/Editor/Highlight Material.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:889bfcffc68926671e3915300900c6d5908b4c1a5981f815d56f0aa3877e672a -size 35420 +oid sha256:0eba0cb1115fb6510ed32159a8fa5a81bbfabfd0e6ec00f4d5ccbfa0426fad97 +size 35356 diff --git a/Content/Editor/Icons/IconsMaterial.flax b/Content/Editor/Icons/IconsMaterial.flax index 9d4eefd96..91bba0296 100644 --- a/Content/Editor/Icons/IconsMaterial.flax +++ b/Content/Editor/Icons/IconsMaterial.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9e2b53c83b4f1ac7908e0af6b5d917ccc617c74a67665d8484db8b9709c5bb85 -size 35353 +oid sha256:51bceae1877ea1859c8757a1e21abade8cf21eda8857d3204bf4b0239fc66d18 +size 35289 diff --git a/Content/Editor/MaterialTemplates/Decal.shader b/Content/Editor/MaterialTemplates/Decal.shader index 1e2076211..e0253efd6 100644 --- a/Content/Editor/MaterialTemplates/Decal.shader +++ b/Content/Editor/MaterialTemplates/Decal.shader @@ -114,8 +114,7 @@ Material GetMaterialPS(MaterialInput input) @4 } -// Programmatically set the line number after all the material inputs which have a variable number of line endings -// This allows shader error line numbers after this point to be the same regardless of which material is being compiled +// Fix line for errors/warnings for shader code from template #line 1000 // Input macro specified by the material: DECAL_BLEND_MODE @@ -160,12 +159,9 @@ void PS_Decal( float3 positionWS = positionHS.xyz / positionHS.w; float3 positionOS = mul(float4(positionWS, 1), InvWorld).xyz; - // Clip content outside the decal clip(0.5 - abs(positionOS.xyz)); - - // By default, map textures using the vectors perpendicular to the projection direction float2 decalUVs = positionOS.xz + 0.5f; - + // Setup material input MaterialInput materialInput = (MaterialInput)0; materialInput.WorldPosition = positionWS; diff --git a/Content/Editor/MaterialTemplates/GUI.shader b/Content/Editor/MaterialTemplates/GUI.shader index 6d3c11dc2..1457a0bc3 100644 --- a/Content/Editor/MaterialTemplates/GUI.shader +++ b/Content/Editor/MaterialTemplates/GUI.shader @@ -197,8 +197,7 @@ Material GetMaterialPS(MaterialInput input) @4 } -// Programmatically set the line number after all the material inputs which have a variable number of line endings -// This allows shader error line numbers after this point to be the same regardless of which material is being compiled +// Fix line for errors/warnings for shader code from template #line 1000 // Vertex Shader function for GUI materials rendering diff --git a/Content/Editor/MaterialTemplates/Particle.shader b/Content/Editor/MaterialTemplates/Particle.shader index cd7f163d0..5fd161645 100644 --- a/Content/Editor/MaterialTemplates/Particle.shader +++ b/Content/Editor/MaterialTemplates/Particle.shader @@ -330,8 +330,7 @@ Material GetMaterialPS(MaterialInput input) @4 } -// Programmatically set the line number after all the material inputs which have a variable number of line endings -// This allows shader error line numbers after this point to be the same regardless of which material is being compiled +// Fix line for errors/warnings for shader code from template #line 1000 // Calculates the transform matrix from mesh tangent space to local space @@ -834,7 +833,7 @@ float4 PS_Distortion(PixelInput input) : SV_Target0 // Scale up for better precision in low/subtle refractions at the expense of artefacts at higher refraction distortion *= 4.0f; - // Store positive and negative offsets separately + // Use separate storage for positive and negative offsets float2 addOffset = max(distortion, 0); float2 subOffset = abs(min(distortion, 0)); return float4(addOffset.x, addOffset.y, subOffset.x, subOffset.y); diff --git a/Content/Editor/MaterialTemplates/PostProcess.shader b/Content/Editor/MaterialTemplates/PostProcess.shader index d4a5424bf..dad9795af 100644 --- a/Content/Editor/MaterialTemplates/PostProcess.shader +++ b/Content/Editor/MaterialTemplates/PostProcess.shader @@ -134,8 +134,7 @@ Material GetMaterialPS(MaterialInput input) @4 } -// Programmatically set the line number after all the material inputs which have a variable number of line endings -// This allows shader error line numbers after this point to be the same regardless of which material is being compiled +// Fix line for errors/warnings for shader code from template #line 1000 // Pixel Shader function for PostFx materials rendering diff --git a/Content/Editor/MaterialTemplates/SurfaceDeferred.shader b/Content/Editor/MaterialTemplates/SurfaceDeferred.shader index cc65235c0..6f393464b 100644 --- a/Content/Editor/MaterialTemplates/SurfaceDeferred.shader +++ b/Content/Editor/MaterialTemplates/SurfaceDeferred.shader @@ -340,8 +340,7 @@ Material GetMaterialPS(MaterialInput input) @4 } -// Programmatically set the line number after all the material inputs which have a variable number of line endings -// This allows shader error line numbers after this point to be the same regardless of which material is being compiled +// Fix line for errors/warnings for shader code from template #line 1000 // Calculates the transform matrix from mesh tangent space to local space @@ -500,7 +499,7 @@ float3x4 GetBoneMatrix(int index) } // Calculates the transposed transform matrix for the given vertex (uses blending) -float3x4 CalcBoneMatrix(ModelInput_Skinned input) +float3x4 GetBoneMatrix(ModelInput_Skinned input) { float3x4 boneMatrix = input.BlendWeights.x * GetBoneMatrix(input.BlendIndices.x); boneMatrix += input.BlendWeights.y * GetBoneMatrix(input.BlendIndices.y); @@ -549,7 +548,7 @@ VertexOutput VS_Skinned(ModelInput_Skinned input) // Perform skinning SkinningData data; - data.BlendMatrix = CalcBoneMatrix(input); + data.BlendMatrix = GetBoneMatrix(input); float3 position = SkinPosition(input, data); float3x3 tangentToLocal = SkinTangents(input, data); @@ -808,7 +807,6 @@ TessalationDSToPS DS(TessalationPatch constantData, float3 barycentricCoords : S #define COPY(thing) output.thing = input[0].thing INTERPOLATE(Position); #if MATERIAL_TESSELLATION == MATERIAL_TESSELLATION_PN - // Precompute squares and squares * 3 float UU = U * U; float VV = V * V; float WW = W * W; diff --git a/Content/Editor/MaterialTemplates/SurfaceForward.shader b/Content/Editor/MaterialTemplates/SurfaceForward.shader index 64fe054d4..7a97e5e5a 100644 --- a/Content/Editor/MaterialTemplates/SurfaceForward.shader +++ b/Content/Editor/MaterialTemplates/SurfaceForward.shader @@ -337,8 +337,7 @@ Material GetMaterialPS(MaterialInput input) @4 } -// Programmatically set the line number after all the material inputs which have a variable number of line endings -// This allows shader error line numbers after this point to be the same regardless of which material is being compiled +// Fix line for errors/warnings for shader code from template #line 1000 // Calculates the transform matrix from mesh tangent space to local space @@ -474,7 +473,7 @@ float3x4 GetBoneMatrix(int index) } // Calculates the transposed transform matrix for the given vertex (uses blending) -float3x4 CalcBoneMatrix(ModelInput_Skinned input) +float3x4 GetBoneMatrix(ModelInput_Skinned input) { float3x4 boneMatrix = input.BlendWeights.x * GetBoneMatrix(input.BlendIndices.x); boneMatrix += input.BlendWeights.y * GetBoneMatrix(input.BlendIndices.y); @@ -521,7 +520,7 @@ VertexOutput VS_Skinned(ModelInput_Skinned input) // Perform skinning SkinningData data; - data.BlendMatrix = CalcBoneMatrix(input); + data.BlendMatrix = GetBoneMatrix(input); float3 position = SkinPosition(input, data); half3x3 tangentToLocal = SkinTangents(input, data); @@ -755,7 +754,6 @@ TessalationDSToPS DS(TessalationPatch constantData, float3 barycentricCoords : S #define COPY(thing) output.thing = input[0].thing INTERPOLATE(Position); #if MATERIAL_TESSELLATION == MATERIAL_TESSELLATION_PN - // Precompute squares and squares * 3 float UU = U * U; float VV = V * V; float WW = W * W; @@ -977,8 +975,8 @@ float4 PS_Distortion(PixelInput input) : SV_Target0 // Scale up for better precision in low/subtle refractions at the expense of artefacts at higher refraction distortion *= 4.0f; - - // Store positive and negative offsets separately + + // Use separate storage for positive and negative offsets float2 addOffset = max(distortion, 0); float2 subOffset = abs(min(distortion, 0)); return float4(addOffset.x, addOffset.y, subOffset.x, subOffset.y); diff --git a/Content/Editor/MaterialTemplates/Terrain.shader b/Content/Editor/MaterialTemplates/Terrain.shader index b05ebd91c..03a2081bf 100644 --- a/Content/Editor/MaterialTemplates/Terrain.shader +++ b/Content/Editor/MaterialTemplates/Terrain.shader @@ -234,8 +234,7 @@ Material GetMaterialPS(MaterialInput input) @4 } -// Programmatically set the line number after all the material inputs which have a variable number of line endings -// This allows shader error line numbers after this point to be the same regardless of which material is being compiled +// Fix line for errors/warnings for shader code from template #line 1000 // Calculates LOD value (with fractional part for blending) @@ -595,7 +594,6 @@ TessalationDSToPS DS(TessalationPatch constantData, float3 barycentricCoords : S #define COPY(thing) output.thing = input[0].thing INTERPOLATE(Position); #if MATERIAL_TESSELLATION == MATERIAL_TESSELLATION_PN - // Precompute squares and squares * 3 float UU = U * U; float VV = V * V; float WW = W * W; diff --git a/Content/Editor/Particles/Smoke Material.flax b/Content/Editor/Particles/Smoke Material.flax index 798c422f2..a3ae100ca 100644 --- a/Content/Editor/Particles/Smoke Material.flax +++ b/Content/Editor/Particles/Smoke Material.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a464d781c863bc54c43341cd68cc06726e6badd12813e381fefc8ba3dfd54fb4 -size 36574 +oid sha256:4c8642a2a7024ae38ae371d95c3411d8e362f42ef98c54dc9da9c061d2a568c1 +size 36552 diff --git a/Content/Editor/Wires Debug Material.flax b/Content/Editor/Wires Debug Material.flax index 146d8dba1..9dedbfea2 100644 --- a/Content/Editor/Wires Debug Material.flax +++ b/Content/Editor/Wires Debug Material.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f5980c96def69ba574b2feb1337d9dd23c56a28779df9601252545b1a01b452d -size 35420 +oid sha256:cb08e24a379cd67db22025bf5e3ae84979f0686179db871387d388f11aae20f0 +size 35356 diff --git a/Content/Engine/DefaultMaterial.flax b/Content/Engine/DefaultMaterial.flax index 23401a029..cd7cd19e0 100644 --- a/Content/Engine/DefaultMaterial.flax +++ b/Content/Engine/DefaultMaterial.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fc0d25b2686512eba5f52691d45ee2e8348d578d627299953e5cec4f97e5e074 -size 40081 +oid sha256:d195b3434472636eff8e34a2052f1ef5d02b1415802414bad6e15f21d0b16de8 +size 39864 diff --git a/Content/Engine/DefaultTerrainMaterial.flax b/Content/Engine/DefaultTerrainMaterial.flax index d1b0de859..be5145720 100644 --- a/Content/Engine/DefaultTerrainMaterial.flax +++ b/Content/Engine/DefaultTerrainMaterial.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:138d3bbb4297dd585c8a0a4ecfd8e48ae542c71d8aff2a199ed28d51d4ced4cf -size 28896 +oid sha256:98a8347591e895fccbe327f393d6376ad1113321daa8a7ad4f47d0753c2e76a1 +size 28681 diff --git a/Content/Shaders/ColorGrading.flax b/Content/Shaders/ColorGrading.flax index b89d4b22b..681fcc89d 100644 --- a/Content/Shaders/ColorGrading.flax +++ b/Content/Shaders/ColorGrading.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ae31d654f71cd691f66cd140fd066ad2cf8a31d984f62f411173972471b9022b -size 10987 +oid sha256:3c6177dd3a8e1490539a9846417cf7f2d1f7926ee4712af77afe32725f73e803 +size 10870 diff --git a/Content/Shaders/Forward.flax b/Content/Shaders/Forward.flax index 41ac2933a..05a66845d 100644 --- a/Content/Shaders/Forward.flax +++ b/Content/Shaders/Forward.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0e2ec3d7ecb31942e65371e6b7c706b9fd8e8d1ba8ca824a3049f3d058058e84 -size 1467 +oid sha256:ee2c02bcfa8ebad9d28005235cb6a396c50a9b4913c26778d4a435bfe9156116 +size 1221 diff --git a/Content/Shaders/PostProcessing.flax b/Content/Shaders/PostProcessing.flax index cd3923673..4f3fb00af 100644 --- a/Content/Shaders/PostProcessing.flax +++ b/Content/Shaders/PostProcessing.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6933ed1b8e8257ca9bd0a5e25deda41d3d79fff2d3aefb2b6be5b8e8d308c5f6 -size 17028 +oid sha256:c78aee780a8049f217023c8f31070be3d4e267ebe399a26009e9198dfed68ad9 +size 17000 diff --git a/Content/Shaders/VolumetricFog.flax b/Content/Shaders/VolumetricFog.flax index 4cd23cb0c..7bfe7b1a1 100644 --- a/Content/Shaders/VolumetricFog.flax +++ b/Content/Shaders/VolumetricFog.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e278259855304359f5cf5d4860c5d473eaae4ae20cdfe73a8b311fdfc00b1aa -size 14492 +oid sha256:1061b3d1c650aec5c937a1af5073ad120551655a059567c5a8740368e17ab246 +size 14259 diff --git a/Source/Editor/Viewport/Previews/AudioClipPreview.cs b/Source/Editor/Viewport/Previews/AudioClipPreview.cs index 2dfda0e9a..dce305ce0 100644 --- a/Source/Editor/Viewport/Previews/AudioClipPreview.cs +++ b/Source/Editor/Viewport/Previews/AudioClipPreview.cs @@ -115,11 +115,9 @@ namespace FlaxEditor.Viewport.Previews var color = Color; if (!EnabledInHierarchy) color *= 0.4f; + var sampleValueScale = height / info.NumChannels; - // Compute the scaled y-value used to render the channel data - float sampleYScale = height / info.NumChannels; - - // Compute amount of samples that are contained in the view + // Calculate the amount of samples that are contained in the view float unitsPerSecond = UnitsPerSecond * ViewScale; float clipDefaultWidth = length * unitsPerSecond; float clipsInView = width / clipDefaultWidth; @@ -173,7 +171,7 @@ namespace FlaxEditor.Viewport.Previews if (samplesInPixel > 0) { float sampleValueAvg = samplesSum / samplesInPixel; - float sampleValueAvgScaled = sampleValueAvg * sampleYScale; + float sampleValueAvgScaled = sampleValueAvg * sampleValueScale; if (sampleValueAvgScaled > 0.1f) { Render2D.DrawLine(new Vector2(pixelX, yCenter - sampleValueAvgScaled), new Vector2(pixelX, yCenter + sampleValueAvgScaled), color); diff --git a/Source/Engine/Content/Utilities/IESLoader.cpp b/Source/Engine/Content/Utilities/IESLoader.cpp index ae35f5bc5..60d6d3597 100644 --- a/Source/Engine/Content/Utilities/IESLoader.cpp +++ b/Source/Engine/Content/Utilities/IESLoader.cpp @@ -300,46 +300,35 @@ float IESLoader::ComputeFilterPos(float value, const Array& sortedValues) { return 0.0f; } - if (value > sortedValues[endPos]) { return static_cast(endPos); } - // Binary search while (startPos < endPos) { const uint32 testPos = (startPos + endPos + 1) / 2; - const float testValue = sortedValues[testPos]; if (value >= testValue) { - // Prevent endless loop ASSERT(startPos != testPos); - startPos = testPos; } else { - // Prevent endless loop ASSERT(endPos != testPos - 1); - endPos = testPos - 1; } } const float leftValue = sortedValues[startPos]; - float fraction = 0.0f; - if (startPos + 1 < static_cast(sortedValues.Count())) { - // If not at right border const float rightValue = sortedValues[startPos + 1]; const float deltaValue = rightValue - leftValue; - - if (deltaValue > 0.0001f) + if (deltaValue > 0.00005f) { fraction = (value - leftValue) / deltaValue; } diff --git a/Source/Engine/Core/Math/Math.cpp b/Source/Engine/Core/Math/Math.cpp index 8fcde780e..b598e7efd 100644 --- a/Source/Engine/Core/Math/Math.cpp +++ b/Source/Engine/Core/Math/Math.cpp @@ -45,22 +45,13 @@ uint32 Math::FloorLog2(uint32 value) Vector3 Math::RotateAboutAxis(const Vector3& normalizedRotationAxis, float angle, const Vector3& positionOnAxis, const Vector3& position) { - // Project position onto the rotation axis and find the closest point on the axis to Position const Vector3 closestPointOnAxis = positionOnAxis + normalizedRotationAxis * Vector3::Dot(normalizedRotationAxis, position - positionOnAxis); - - // Construct orthogonal axes in the plane of the rotation const Vector3 axisU = position - closestPointOnAxis; const Vector3 axisV = Vector3::Cross(normalizedRotationAxis, axisU); float cosAngle, sinAngle; Math::SinCos(angle, sinAngle, cosAngle); - - // Rotate using the orthogonal axes const Vector3 rotation = axisU * cosAngle + axisV * sinAngle; - - // Reconstruct the rotated world space position const Vector3 rotatedPosition = closestPointOnAxis + rotation; - - // Convert from position to a position offset return rotatedPosition - position; } diff --git a/Source/Engine/Core/Math/Plane.cpp b/Source/Engine/Core/Math/Plane.cpp index b93646a94..0b6c80f59 100644 --- a/Source/Engine/Core/Math/Plane.cpp +++ b/Source/Engine/Core/Math/Plane.cpp @@ -216,7 +216,6 @@ void Plane::Transform(Plane planes[], int32 planesCount, const Quaternion& rotat const float y = planes[i].Normal.Y; const float z = planes[i].Normal.Z; - // Factor common arithmetic out of loop planes[i].Normal.X = x * (1.0f - yy - zz) + y * (xy - wz) + z * (xz + wy); planes[i].Normal.Y = x * (xy + wz) + y * (1.0f - xx - zz) + z * (yz - wx); planes[i].Normal.Z = x * (xz - wy) + y * (yz + wx) + z * (1.0f - xx - yy); diff --git a/Source/Engine/Core/Types/DateTime.cpp b/Source/Engine/Core/Types/DateTime.cpp index a5166f5cc..227df6309 100644 --- a/Source/Engine/Core/Types/DateTime.cpp +++ b/Source/Engine/Core/Types/DateTime.cpp @@ -56,7 +56,6 @@ int32 DateTime::GetDay() const DayOfWeek DateTime::GetDayOfWeek() const { - // January 1, 0001 was a Monday return static_cast((Ticks / Constants::TicksPerDay) % 7); } @@ -64,8 +63,8 @@ int32 DateTime::GetDayOfYear() const { int32 year, month, day; GetDate(year, month, day); - for (int32 currentMonth = 1; currentMonth < month; currentMonth++) - day += DaysInMonth(year, currentMonth); + for (int32 i = 1; i < month; i++) + day += DaysInMonth(year, i); return day; } @@ -131,13 +130,7 @@ DateTime DateTime::NowUTC() bool DateTime::Validate(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second, int32 millisecond) { - return (year >= 1) && (year <= 9999) && - (month >= 1) && (month <= 12) && - (day >= 1) && (day <= DaysInMonth(year, month)) && - (hour >= 0) && (hour <= 23) && - (minute >= 0) && (minute <= 59) && - (second >= 0) && (second <= 59) && - (millisecond >= 0) && (millisecond <= 999); + return year >= 1 && year <= 999999 && month >= 1 && month <= 12 && day >= 1 && day <= DaysInMonth(year, month) && hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59 && second >= 0 && second <= 59 && millisecond >= 0 && millisecond <= 999; } String DateTime::ToString() const diff --git a/Source/Engine/Core/Types/TimeSpan.cpp b/Source/Engine/Core/Types/TimeSpan.cpp index aa90fcf8d..400891ec2 100644 --- a/Source/Engine/Core/Types/TimeSpan.cpp +++ b/Source/Engine/Core/Types/TimeSpan.cpp @@ -33,7 +33,7 @@ TimeSpan TimeSpan::FromSeconds(double seconds) return TimeSpan(static_cast(seconds * Constants::TicksPerSecond)); } -void TimeSpan::Assign(int32 days, int32 hours, int32 minutes, int32 seconds, int32 milliseconds) +void TimeSpan::Set(int32 days, int32 hours, int32 minutes, int32 seconds, int32 milliseconds) { const int64 totalMs = 1000 * (60 * 60 * 24 * (int64)days + 60 * 60 * (int64)hours + 60 * (int64)minutes + (int64)seconds) + (int64)milliseconds; ASSERT_LOW_LAYER((totalMs >= MinValue().GetTotalMilliseconds()) && (totalMs <= MaxValue().GetTotalMilliseconds())); diff --git a/Source/Engine/Core/Types/TimeSpan.h b/Source/Engine/Core/Types/TimeSpan.h index e26c5cc5a..7595d1bf1 100644 --- a/Source/Engine/Core/Types/TimeSpan.h +++ b/Source/Engine/Core/Types/TimeSpan.h @@ -49,8 +49,10 @@ public: { } - // Init - // @param ticks The number of ticks + /// + /// Initializes a new instance of the struct. + /// + /// The ticks in 100 nanoseconds resolution. TimeSpan(int64 ticks) : Ticks(ticks) { @@ -62,7 +64,7 @@ public: // @param Minutes Amount of minutes TimeSpan(int32 days, int32 hours, int32 minutes) { - Assign(days, hours, minutes, 0, 0); + Set(days, hours, minutes, 0, 0); } // Init @@ -72,7 +74,7 @@ public: // @param Seconds Amount of seconds TimeSpan(int32 days, int32 hours, int32 minutes, int32 seconds) { - Assign(days, hours, minutes, seconds, 0); + Set(days, hours, minutes, seconds, 0); } // Init @@ -83,7 +85,7 @@ public: // @param Milliseconds Amount of milliseconds TimeSpan(int32 days, int32 hours, int32 minutes, int32 seconds, int32 milliseconds) { - Assign(days, hours, minutes, seconds, milliseconds); + Set(days, hours, minutes, seconds, milliseconds); } public: @@ -325,7 +327,7 @@ public: private: - void Assign(int32 days, int32 hours, int32 minutes, int32 seconds, int32 milliseconds); + void Set(int32 days, int32 hours, int32 minutes, int32 seconds, int32 milliseconds); }; inline TimeSpan operator*(float scalar, const TimeSpan& timespan) diff --git a/Source/Engine/Graphics/GPUResourceState.h b/Source/Engine/Graphics/GPUResourceState.h index 8e485ed68..718d21a7d 100644 --- a/Source/Engine/Graphics/GPUResourceState.h +++ b/Source/Engine/Graphics/GPUResourceState.h @@ -46,13 +46,13 @@ public: { ASSERT(_subresourceState.IsEmpty() && subresourceCount > 0); - // Allocate space for per-subresource tracking structures - if (usePerSubresourceTracking && subresourceCount > 1) - _subresourceState.Resize(subresourceCount, false); - // Initialize state _allSubresourcesSame = true; _resourceState = initialState; + + // Allocate space for per-subresource state tracking + if (usePerSubresourceTracking && subresourceCount > 1) + _subresourceState.Resize(subresourceCount, false); #if BUILD_DEBUG _subresourceState.SetAll(InvalidState); #endif @@ -124,7 +124,7 @@ public: void SetSubresourceState(int32 subresourceIndex, StateType state) { - // If setting all subresources, or the resource only has a single subresource, set the per-resource state + // Check if use single state for the whole resource if (subresourceIndex == -1 || _subresourceState.Count() <= 1) { SetResourceState(state); @@ -133,16 +133,14 @@ public: { ASSERT(subresourceIndex < static_cast(_subresourceState.Count())); - // If state was previously tracked on a per-resource level, then transition to per-subresource tracking + // Transition for all sub-resources if (_allSubresourcesSame) { for (int32 i = 0; i < _subresourceState.Count(); i++) { _subresourceState[i] = _resourceState; } - _allSubresourcesSame = 0; - #if BUILD_DEBUG _resourceState = InvalidState; #endif diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp index 714c86563..3c9efc8ea 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp @@ -23,9 +23,8 @@ #define DX11_FORCE_USE_DX10 0 #define DX11_FORCE_USE_DX10_1 0 -static bool TryCreateDevice(IDXGIAdapter* adapter, D3D_FEATURE_LEVEL maxFeatureLevel, D3D_FEATURE_LEVEL* outFeatureLevel) +static bool TryCreateDevice(IDXGIAdapter* adapter, D3D_FEATURE_LEVEL maxFeatureLevel, D3D_FEATURE_LEVEL* featureLevel) { - // Temporary data ID3D11Device* device = nullptr; ID3D11DeviceContext* context = nullptr; uint32 deviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT; @@ -33,26 +32,22 @@ static bool TryCreateDevice(IDXGIAdapter* adapter, D3D_FEATURE_LEVEL maxFeatureL deviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif - D3D_FEATURE_LEVEL requestedFeatureLevels[] = + // Pick the first level + D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0 }; - - int32 firstAllowedFeatureLevel = 0; - int32 numAllowedFeatureLevels = ARRAY_COUNT(requestedFeatureLevels); - while (firstAllowedFeatureLevel < numAllowedFeatureLevels) + int32 levelIndex = 0; + while (levelIndex < ARRAY_COUNT(featureLevels)) { - if (requestedFeatureLevels[firstAllowedFeatureLevel] == maxFeatureLevel) - { + if (featureLevels[levelIndex] == maxFeatureLevel) break; - } - firstAllowedFeatureLevel++; + levelIndex++; } - numAllowedFeatureLevels -= firstAllowedFeatureLevel; - if (numAllowedFeatureLevels == 0) + if (levelIndex >= ARRAY_COUNT(featureLevels)) { return false; } @@ -63,18 +58,16 @@ static bool TryCreateDevice(IDXGIAdapter* adapter, D3D_FEATURE_LEVEL maxFeatureL D3D_DRIVER_TYPE_UNKNOWN, NULL, deviceFlags, - &requestedFeatureLevels[firstAllowedFeatureLevel], - numAllowedFeatureLevels, + &featureLevels[levelIndex], + ARRAY_COUNT(featureLevels) - levelIndex, D3D11_SDK_VERSION, &device, - outFeatureLevel, + featureLevel, &context ))) { - // Release created stuff device->Release(); context->Release(); - return true; } diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp index b346b5ece..cf9d2f219 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp @@ -144,10 +144,8 @@ bool GPUTextureDX12::OnInit() { resourceDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; initialState = D3D12_RESOURCE_STATE_DEPTH_WRITE; - if (!useSRV) { - // Only deny shader resources if it's a depth resource that will never be used as SRV resourceDesc.Flags |= D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE; } } diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp index aa2d17bed..4b2482d66 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp @@ -86,7 +86,7 @@ void QueryHeapDX12::EndQueryBatchAndResolveQueryData(GPUContextDX12* context) { ASSERT(_currentBatch.Open); - // Discard empty batches + // Skip empty batches if (_currentBatch.Count == 0) { return; diff --git a/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp index d06328fdf..37a5bf369 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp @@ -297,7 +297,7 @@ void CmdBufferManagerVulkan::PrepareForNewActiveCommandBuffer() } } - // All cmd buffers are being executed still + // Always begin fresh command buffer for rendering _activeCmdBuffer = _pool.Create(); _activeCmdBuffer->Begin(); diff --git a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp index 5b85dca1f..e51b9c15b 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp @@ -32,7 +32,6 @@ void DescriptorSetLayoutInfoVulkan::CacheTypesUsageID() void DescriptorSetLayoutInfoVulkan::AddDescriptor(int32 descriptorSetIndex, const VkDescriptorSetLayoutBinding& descriptor) { - // Increment type usage _layoutTypes[descriptor.descriptorType]++; if (descriptorSetIndex >= _setLayouts.Count()) @@ -43,7 +42,6 @@ void DescriptorSetLayoutInfoVulkan::AddDescriptor(int32 descriptorSetIndex, cons SetLayout& descSetLayout = _setLayouts[descriptorSetIndex]; descSetLayout.LayoutBindings.Add(descriptor); - // TODO: manual hash update method? _hash = Crc::MemCrc32(&descriptor, sizeof(descriptor), _hash); } @@ -116,20 +114,20 @@ void DescriptorSetLayoutVulkan::Compile() DescriptorPoolVulkan::DescriptorPoolVulkan(GPUDeviceVulkan* device, const DescriptorSetLayoutVulkan& layout) : _device(device) , _handle(VK_NULL_HANDLE) - , DescriptorSetsMax(0) - , AllocatedDescriptorSetsCount(0) - , AllocatedDescriptorSetsCountMax(0) - , Layout(layout) + , _descriptorSetsMax(0) + , _allocatedDescriptorSetsCount(0) + , _allocatedDescriptorSetsCountMax(0) + , _layout(layout) { Array> types; // The maximum amount of descriptor sets layout allocations to hold const uint32 MaxSetsAllocations = 256; - DescriptorSetsMax = MaxSetsAllocations * (VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? 1 : Layout.GetLayouts().Count()); + _descriptorSetsMax = MaxSetsAllocations * (VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? 1 : _layout.GetLayouts().Count()); for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { const VkDescriptorType descriptorType = (VkDescriptorType)typeIndex; - const uint32 typesUsed = Layout.GetTypesUsed(descriptorType); + const uint32 typesUsed = _layout.GetTypesUsed(descriptorType); if (typesUsed > 0) { VkDescriptorPoolSize& type = types.AddOne(); @@ -144,7 +142,7 @@ DescriptorPoolVulkan::DescriptorPoolVulkan(GPUDeviceVulkan* device, const Descri createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; createInfo.poolSizeCount = types.Count(); createInfo.pPoolSizes = types.Get(); - createInfo.maxSets = DescriptorSetsMax; + createInfo.maxSets = _descriptorSetsMax; VALIDATE_VULKAN_RESULT(vkCreateDescriptorPool(_device->Device, &createInfo, nullptr, &_handle)); } @@ -156,16 +154,16 @@ DescriptorPoolVulkan::~DescriptorPoolVulkan() } } -void DescriptorPoolVulkan::TrackAddUsage(const DescriptorSetLayoutVulkan& layout) +void DescriptorPoolVulkan::Track(const DescriptorSetLayoutVulkan& layout) { - // Check and increment our current type usage +#if !BUILD_RELEASE for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { - ASSERT(Layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); + ASSERT(_layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); } - - AllocatedDescriptorSetsCount += layout.GetLayouts().Count(); - AllocatedDescriptorSetsCountMax = Math::Max(AllocatedDescriptorSetsCount, AllocatedDescriptorSetsCountMax); +#endif + _allocatedDescriptorSetsCount += layout.GetLayouts().Count(); + _allocatedDescriptorSetsCountMax = Math::Max(_allocatedDescriptorSetsCount, _allocatedDescriptorSetsCountMax); } void DescriptorPoolVulkan::TrackRemoveUsage(const DescriptorSetLayoutVulkan& layout) @@ -173,10 +171,10 @@ void DescriptorPoolVulkan::TrackRemoveUsage(const DescriptorSetLayoutVulkan& lay // Check and increment our current type usage for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { - ASSERT(Layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); + ASSERT(_layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); } - AllocatedDescriptorSetsCount -= layout.GetLayouts().Count(); + _allocatedDescriptorSetsCount -= layout.GetLayouts().Count(); } void DescriptorPoolVulkan::Reset() @@ -185,7 +183,7 @@ void DescriptorPoolVulkan::Reset() { VALIDATE_VULKAN_RESULT(vkResetDescriptorPool(_device->Device, _handle, 0)); } - AllocatedDescriptorSetsCount = 0; + _allocatedDescriptorSetsCount = 0; } bool DescriptorPoolVulkan::AllocateDescriptorSets(const VkDescriptorSetAllocateInfo& descriptorSetAllocateInfo, VkDescriptorSet* result) @@ -335,8 +333,6 @@ void DescriptorPoolsManagerVulkan::ReleasePoolSet(DescriptorPoolSetContainerVulk void DescriptorPoolsManagerVulkan::GC() { ScopeLock lock(_locker); - - // Pool sets are forward allocated - iterate from the back to increase the chance of finding an unused one for (int32 i = _poolSets.Count() - 1; i >= 0; i--) { const auto poolSet = _poolSets[i]; @@ -374,12 +370,12 @@ PipelineLayoutVulkan::~PipelineLayoutVulkan() } } -uint32 DescriptorSetWriterVulkan::SetupDescriptorWrites(const SpirvShaderDescriptorInfo& info, VkWriteDescriptorSet* writeDescriptors, VkDescriptorImageInfo* imageInfo, VkDescriptorBufferInfo* bufferInfo, uint8* bindingToDynamicOffsetMap) +uint32 DescriptorSetWriterVulkan::SetupDescriptorWrites(const SpirvShaderDescriptorInfo& info, VkWriteDescriptorSet* writeDescriptors, VkDescriptorImageInfo* imageInfo, VkDescriptorBufferInfo* bufferInfo, uint8* bindingToDynamicOffset) { + ASSERT(info.DescriptorTypesCount <= 64); WriteDescriptors = writeDescriptors; WritesCount = info.DescriptorTypesCount; - ASSERT(info.DescriptorTypesCount <= 64 && TEXT("Out of bits for Dirty Mask! More than 64 resources in one descriptor set!")); - BindingToDynamicOffsetMap = bindingToDynamicOffsetMap; + BindingToDynamicOffset = bindingToDynamicOffset; uint32 dynamicOffsetIndex = 0; for (uint32 i = 0; i < info.DescriptorTypesCount; i++) @@ -392,8 +388,8 @@ uint32 DescriptorSetWriterVulkan::SetupDescriptorWrites(const SpirvShaderDescrip switch (writeDescriptors->descriptorType) { case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: - BindingToDynamicOffsetMap[i] = dynamicOffsetIndex; - ++dynamicOffsetIndex; + BindingToDynamicOffset[i] = dynamicOffsetIndex; + dynamicOffsetIndex++; writeDescriptors->pBufferInfo = bufferInfo++; break; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: diff --git a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h index 78ea83eb2..125eea923 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h @@ -230,16 +230,15 @@ private: GPUDeviceVulkan* _device; VkDescriptorPool _handle; - uint32 DescriptorSetsMax; - uint32 AllocatedDescriptorSetsCount; - uint32 AllocatedDescriptorSetsCountMax; + uint32 _descriptorSetsMax; + uint32 _allocatedDescriptorSetsCount; + uint32 _allocatedDescriptorSetsCountMax; - const DescriptorSetLayoutVulkan& Layout; + const DescriptorSetLayoutVulkan& _layout; public: DescriptorPoolVulkan(GPUDeviceVulkan* device, const DescriptorSetLayoutVulkan& layout); - ~DescriptorPoolVulkan(); public: @@ -251,25 +250,24 @@ public: inline bool IsEmpty() const { - return AllocatedDescriptorSetsCount == 0; + return _allocatedDescriptorSetsCount == 0; } inline bool CanAllocate(const DescriptorSetLayoutVulkan& layout) const { - return DescriptorSetsMax > AllocatedDescriptorSetsCount + layout.GetLayouts().Count(); + return _descriptorSetsMax > _allocatedDescriptorSetsCount + layout.GetLayouts().Count(); } inline uint32 GetAllocatedDescriptorSetsCount() const { - return AllocatedDescriptorSetsCount; + return _allocatedDescriptorSetsCount; } - void TrackAddUsage(const DescriptorSetLayoutVulkan& layout); +public: + void Track(const DescriptorSetLayoutVulkan& layout); void TrackRemoveUsage(const DescriptorSetLayoutVulkan& layout); - void Reset(); - bool AllocateDescriptorSets(const VkDescriptorSetAllocateInfo& descriptorSetAllocateInfo, VkDescriptorSet* result); }; @@ -416,14 +414,14 @@ struct DescriptorSetWriteContainerVulkan Array DescriptorImageInfo; Array DescriptorBufferInfo; Array DescriptorWrites; - Array BindingToDynamicOffsetMap; + Array BindingToDynamicOffset; void Release() { DescriptorImageInfo.Resize(0); DescriptorBufferInfo.Resize(0); DescriptorWrites.Resize(0); - BindingToDynamicOffsetMap.Resize(0); + BindingToDynamicOffset.Resize(0); } }; @@ -431,24 +429,14 @@ class DescriptorSetWriterVulkan { public: - VkWriteDescriptorSet* WriteDescriptors; - uint8* BindingToDynamicOffsetMap; - uint32* DynamicOffsets; - uint32 WritesCount; + VkWriteDescriptorSet* WriteDescriptors = nullptr; + byte* BindingToDynamicOffset = nullptr; + uint32* DynamicOffsets = nullptr; + uint32 WritesCount = 0; public: - DescriptorSetWriterVulkan() - : WriteDescriptors(nullptr) - , BindingToDynamicOffsetMap(nullptr) - , DynamicOffsets(nullptr) - , WritesCount(0) - { - } - -public: - - uint32 SetupDescriptorWrites(const SpirvShaderDescriptorInfo& info, VkWriteDescriptorSet* writeDescriptors, VkDescriptorImageInfo* imageInfo, VkDescriptorBufferInfo* bufferInfo, uint8* bindingToDynamicOffsetMap); + uint32 SetupDescriptorWrites(const SpirvShaderDescriptorInfo& info, VkWriteDescriptorSet* writeDescriptors, VkDescriptorImageInfo* imageInfo, VkDescriptorBufferInfo* bufferInfo, byte* bindingToDynamicOffset); bool WriteUniformBuffer(uint32 descriptorIndex, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range) const { @@ -471,7 +459,7 @@ public: bool edited = DescriptorSet::CopyAndReturnNotEqual(bufferInfo->buffer, buffer); edited |= DescriptorSet::CopyAndReturnNotEqual(bufferInfo->offset, offset); edited |= DescriptorSet::CopyAndReturnNotEqual(bufferInfo->range, range); - const uint8 dynamicOffsetIndex = BindingToDynamicOffsetMap[descriptorIndex]; + const byte dynamicOffsetIndex = BindingToDynamicOffset[descriptorIndex]; DynamicOffsets[dynamicOffsetIndex] = dynamicOffset; return edited; } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index 881e575e7..5c4f7a64c 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -146,7 +146,6 @@ void GPUContextVulkan::AddImageBarrier(GPUTextureViewVulkan* handle, VkImageLayo { // Transition entire resource at once const VkImageLayout srcLayout = state.GetSubresourceState(0); - VkImageSubresourceRange range; range.aspectMask = handle->Info.subresourceRange.aspectMask; range.baseMipLevel = 0; @@ -157,7 +156,7 @@ void GPUContextVulkan::AddImageBarrier(GPUTextureViewVulkan* handle, VkImageLayo } else { - // Slow path. Want to transition the entire resource (with multiple subresources). But they aren't in the same state. + // Slow path to transition each subresource for (int32 i = 0; i < state.GetSubresourcesCount(); i++) { const VkImageLayout srcLayout = state.GetSubresourceState(i); @@ -174,8 +173,6 @@ void GPUContextVulkan::AddImageBarrier(GPUTextureViewVulkan* handle, VkImageLayo state.SetSubresourceState(i, dstLayout); } } - - // The entire resource should now be in the after state on this command list ASSERT(state.CheckResourceState(dstLayout)); } @@ -538,7 +535,7 @@ void GPUContextVulkan::UpdateDescriptorSets(GPUPipelineStateVulkan* pipelineStat remainingHasDescriptorsPerStageMask >>= 1; } - // Allocate sets based on what changed + // Allocate sets if need to //if (needsWrite) // TODO: write on change only? { if (!pipelineState->AllocateDescriptorSets()) @@ -578,7 +575,7 @@ void GPUContextVulkan::UpdateDescriptorSets(ComputePipelineStateVulkan* pipeline // Update descriptors UpdateDescriptorSets(*pipelineState->DescriptorInfo, pipelineState->DSWriter, needsWrite); - // Allocate sets based on what changed + // Allocate sets if need to //if (needsWrite) // TODO: write on change only?f { if (!pipelineState->AllocateDescriptorSets()) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp index d65425041..3b9d69357 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp @@ -149,12 +149,12 @@ static int FindLayerIndex(const Array& list, const char* layerNa return i; } } - return INVALID_INDEX; + return -1; } static bool ContainsLayer(const Array& list, const char* layerName) { - return FindLayerIndex(list, layerName) != INVALID_INDEX; + return FindLayerIndex(list, layerName) != -1; } static bool FindLayerExtension(const Array& list, const char* extensionName, const char*& foundLayer) @@ -400,7 +400,6 @@ void GPUDeviceVulkan::GetInstanceLayersAndExtensions(Array& outInst void GPUDeviceVulkan::GetDeviceExtensionsAndLayers(VkPhysicalDevice gpu, Array& outDeviceExtensions, Array& outDeviceLayers) { Array deviceLayerExtensions; - // 0 is reserved for regular device deviceLayerExtensions.AddDefault(1); { uint32 count = 0; @@ -409,10 +408,10 @@ void GPUDeviceVulkan::GetDeviceExtensionsAndLayers(VkPhysicalDevice gpu, Array platformExtensions; VulkanPlatform::GetDeviceExtensions(platformExtensions); for (const char* extension : platformExtensions) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index 29ceb8230..4c6a2ec0e 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -345,10 +345,6 @@ DeferredDeletionQueueVulkan::~DeferredDeletionQueueVulkan() void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately) { ScopeLock lock(&_locker); - - const VkDevice device = _device->Device; - - // Traverse list backwards so the swap switches to elements already tested const uint64 checkFrame = Engine::FrameCount - VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT; for (int32 i = 0; i < _entries.Count(); i++) { @@ -361,24 +357,26 @@ void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately) { switch (e->StructureType) { -#define VK_SWITCH(type) case Type::type: vkDestroy##type(device, (Vk##type)e->Handle, nullptr); break - VK_SWITCH(RenderPass); - VK_SWITCH(Buffer); - VK_SWITCH(BufferView); - VK_SWITCH(Image); - VK_SWITCH(ImageView); - VK_SWITCH(Pipeline); - VK_SWITCH(PipelineLayout); - VK_SWITCH(Framebuffer); - VK_SWITCH(DescriptorSetLayout); - VK_SWITCH(Sampler); - VK_SWITCH(Semaphore); - VK_SWITCH(ShaderModule); - VK_SWITCH(Event); - VK_SWITCH(QueryPool); -#undef VK_SWITCH +#define SWITCH_CASE(type) case Type::type: vkDestroy##type(_device->Device, (Vk##type)e->Handle, nullptr); break + SWITCH_CASE(RenderPass); + SWITCH_CASE(Buffer); + SWITCH_CASE(BufferView); + SWITCH_CASE(Image); + SWITCH_CASE(ImageView); + SWITCH_CASE(Pipeline); + SWITCH_CASE(PipelineLayout); + SWITCH_CASE(Framebuffer); + SWITCH_CASE(DescriptorSetLayout); + SWITCH_CASE(Sampler); + SWITCH_CASE(Semaphore); + SWITCH_CASE(ShaderModule); + SWITCH_CASE(Event); + SWITCH_CASE(QueryPool); +#undef SWITCH_CASE default: +#if !BUILD_RELEASE CRASH; +#endif break; } } @@ -1068,23 +1066,10 @@ GPUDeviceVulkan::GPUDeviceVulkan(ShaderProfile shaderProfile, GPUAdapterVulkan* , _renderPasses(512) , _framebuffers(512) , _layouts(4096) - , MainContext(nullptr) , Adapter(adapter) - , Device(VK_NULL_HANDLE) , DeferredDeletionQueue(this) , StagingManager(this) , HelperResources(this) - , GraphicsQueue(nullptr) - , ComputeQueue(nullptr) - , TransferQueue(nullptr) - , PresentQueue(nullptr) - , Allocator(VK_NULL_HANDLE) - , PipelineCache(VK_NULL_HANDLE) -#if VK_EXT_validation_cache - , ValidationCache(VK_NULL_HANDLE) -#endif - , UniformBufferUploader(nullptr) - , DescriptorPoolsManager(nullptr) { } @@ -1151,7 +1136,7 @@ GPUDevice* GPUDeviceVulkan::Create() } if (result == VK_ERROR_EXTENSION_NOT_PRESENT) { - // Check for missing extensions + // Extensions error uint32_t propertyCount; vkEnumerateInstanceExtensionProperties(nullptr, &propertyCount, nullptr); Array properties; @@ -1159,28 +1144,27 @@ GPUDevice* GPUDeviceVulkan::Create() vkEnumerateInstanceExtensionProperties(nullptr, &propertyCount, properties.Get()); for (const char* extension : InstanceExtensions) { - bool extensionFound = false; + bool found = false; for (uint32_t propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++) { if (!StringUtils::Compare(properties[propertyIndex].extensionName, extension)) { - extensionFound = true; + found = true; break; } } - if (!extensionFound) + if (!found) { LOG(Warning, "Missing required Vulkan extension: {0}", String(extension)); } } - - // Missing extensions auto error = String::Format(TEXT("Vulkan driver doesn't contain specified extensions:\n{0}\nPlease make sure your layers path is set appropriately.")); Platform::Error(*error); return nullptr; } if (result != VK_SUCCESS) { + // Driver error LOG(Warning, "Vulkan create instance failed with error code: {0}", RenderToolsVulkan::GetVkErrorString(result)); Platform::Fatal(TEXT("Vulkan failed to create instance\n\nDo you have a compatible Vulkan driver installed?")); return nullptr; @@ -1560,7 +1544,7 @@ bool GPUDeviceVulkan::Init() _state = DeviceState::Created; const auto gpu = Adapter->Gpu; - // Query queues properties + // Get queues properties uint32 queueCount = 0; vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queueCount, nullptr); ASSERT(queueCount >= 1); @@ -1570,23 +1554,21 @@ bool GPUDeviceVulkan::Init() // Query device features vkGetPhysicalDeviceFeatures(Adapter->Gpu, &PhysicalDeviceFeatures); - // Setup extension and layer info - VkDeviceCreateInfo deviceInfo; - RenderToolsVulkan::ZeroStruct(deviceInfo, VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO); - + // Get extensions and layers Array deviceExtensions; Array validationLayers; GetDeviceExtensionsAndLayers(gpu, deviceExtensions, validationLayers); - ParseOptionalDeviceExtensions(deviceExtensions); + // Setup device info + VkDeviceCreateInfo deviceInfo; + RenderToolsVulkan::ZeroStruct(deviceInfo, VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO); deviceInfo.enabledExtensionCount = deviceExtensions.Count(); deviceInfo.ppEnabledExtensionNames = deviceExtensions.Get(); - deviceInfo.enabledLayerCount = validationLayers.Count(); deviceInfo.ppEnabledLayerNames = deviceInfo.enabledLayerCount > 0 ? validationLayers.Get() : nullptr; - // Setup Queue info + // Setup queues info Array queueFamilyInfos; int32 graphicsQueueFamilyIndex = -1; int32 computeQueueFamilyIndex = -1; @@ -1655,7 +1637,6 @@ bool GPUDeviceVulkan::Init() numPriorities += curProps.queueCount; LOG(Info, "- queue family {0}: {1} queues{2}", familyIndex, curProps.queueCount, queueTypeInfo); } - Array queuePriorities; queuePriorities.AddDefault(numPriorities); float* currentPriority = queuePriorities.Get(); @@ -1663,14 +1644,12 @@ bool GPUDeviceVulkan::Init() { VkDeviceQueueCreateInfo& queue = queueFamilyInfos[index]; queue.pQueuePriorities = currentPriority; - const VkQueueFamilyProperties& properties = QueueFamilyProps[queue.queueFamilyIndex]; for (int32 queueIndex = 0; queueIndex < (int32)properties.queueCount; queueIndex++) { *currentPriority++ = 1.0f; } } - deviceInfo.queueCreateInfoCount = queueFamilyInfos.Count(); deviceInfo.pQueueCreateInfos = queueFamilyInfos.Get(); @@ -2129,7 +2108,6 @@ bool FenceManagerVulkan::CheckFenceState(FenceVulkan* fence) void FenceManagerVulkan::DestroyFence(FenceVulkan* fence) { - // Does not need to go in the deferred deletion queue vkDestroyFence(_device->Device, fence->GetHandle(), nullptr); fence->_handle = VK_NULL_HANDLE; Delete(fence); diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h index 805cfd8f9..3c0ff7eb2 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h @@ -554,17 +554,17 @@ public: /// /// The main Vulkan commands context. /// - GPUContextVulkan* MainContext; + GPUContextVulkan* MainContext = nullptr; /// /// The Vulkan adapter. /// - GPUAdapterVulkan* Adapter; + GPUAdapterVulkan* Adapter = nullptr; /// /// The Vulkan device. /// - VkDevice Device; + VkDevice Device = VK_NULL_HANDLE; /// /// The Vulkan device queues family properties. @@ -594,51 +594,51 @@ public: /// /// The graphics queue. /// - QueueVulkan* GraphicsQueue; + QueueVulkan* GraphicsQueue = nullptr; /// /// The compute queue. /// - QueueVulkan* ComputeQueue; + QueueVulkan* ComputeQueue = nullptr; /// /// The transfer queue. /// - QueueVulkan* TransferQueue; + QueueVulkan* TransferQueue = nullptr; /// /// The present queue. /// - QueueVulkan* PresentQueue; + QueueVulkan* PresentQueue = nullptr; /// /// The Vulkan memory allocator. /// - VmaAllocator Allocator; + VmaAllocator Allocator = VK_NULL_HANDLE; /// /// The pipeline cache. /// - VkPipelineCache PipelineCache; + VkPipelineCache PipelineCache = VK_NULL_HANDLE; #if VK_EXT_validation_cache /// /// The optional validation cache. /// - VkValidationCacheEXT ValidationCache; + VkValidationCacheEXT ValidationCache = VK_NULL_HANDLE; #endif /// /// The uniform buffers uploader. /// - UniformBufferUploaderVulkan* UniformBufferUploader; + UniformBufferUploaderVulkan* UniformBufferUploader = nullptr; /// /// The descriptor pools manager. /// - DescriptorPoolsManagerVulkan* DescriptorPoolsManager; + DescriptorPoolsManagerVulkan* DescriptorPoolsManager = nullptr; /// /// The physical device limits. diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp index ee7305daf..1fa709943 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp @@ -45,13 +45,10 @@ ComputePipelineStateVulkan* GPUShaderProgramCSVulkan::GetOrCreateState() // Setup the state _pipelineState = New(_device, pipeline, layout); - _pipelineState->DescriptorInfo = &DescriptorInfo; _pipelineState->DescriptorSetsLayout = &layout->GetDescriptorSetLayout(); _pipelineState->DescriptorSetHandles.AddZeroed(_pipelineState->DescriptorSetsLayout->GetHandles().Count()); - - uint32 totalNumDynamicOffsets = 0; - + uint32 dynamicOffsetsCount = 0; if (DescriptorInfo.DescriptorTypesCount != 0) { _pipelineState->DSWriteContainer.DescriptorWrites.AddZeroed(DescriptorInfo.DescriptorTypesCount); @@ -59,18 +56,18 @@ ComputePipelineStateVulkan* GPUShaderProgramCSVulkan::GetOrCreateState() _pipelineState->DSWriteContainer.DescriptorBufferInfo.AddZeroed(DescriptorInfo.BufferInfosCount); ASSERT(DescriptorInfo.DescriptorTypesCount < 255); - _pipelineState->DSWriteContainer.BindingToDynamicOffsetMap.AddDefault(DescriptorInfo.DescriptorTypesCount); - _pipelineState->DSWriteContainer.BindingToDynamicOffsetMap.SetAll(255); + _pipelineState->DSWriteContainer.BindingToDynamicOffset.AddDefault(DescriptorInfo.DescriptorTypesCount); + _pipelineState->DSWriteContainer.BindingToDynamicOffset.SetAll(255); VkWriteDescriptorSet* currentDescriptorWrite = _pipelineState->DSWriteContainer.DescriptorWrites.Get(); VkDescriptorImageInfo* currentImageInfo = _pipelineState->DSWriteContainer.DescriptorImageInfo.Get(); VkDescriptorBufferInfo* currentBufferInfo = _pipelineState->DSWriteContainer.DescriptorBufferInfo.Get(); - uint8* currentBindingToDynamicOffsetMap = _pipelineState->DSWriteContainer.BindingToDynamicOffsetMap.Get(); + uint8* currentBindingToDynamicOffsetMap = _pipelineState->DSWriteContainer.BindingToDynamicOffset.Get(); - totalNumDynamicOffsets = _pipelineState->DSWriter.SetupDescriptorWrites(DescriptorInfo, currentDescriptorWrite, currentImageInfo, currentBufferInfo, currentBindingToDynamicOffsetMap); + dynamicOffsetsCount = _pipelineState->DSWriter.SetupDescriptorWrites(DescriptorInfo, currentDescriptorWrite, currentImageInfo, currentBufferInfo, currentBindingToDynamicOffsetMap); } - _pipelineState->DynamicOffsets.AddZeroed(totalNumDynamicOffsets); + _pipelineState->DynamicOffsets.AddZeroed(dynamicOffsetsCount); _pipelineState->DSWriter.DynamicOffsets = _pipelineState->DynamicOffsets.Get(); return _pipelineState; @@ -346,26 +343,26 @@ bool GPUPipelineStateVulkan::Init(const Description& desc) DSWriteContainer.DescriptorBufferInfo.AddZeroed(descriptor->BufferInfosCount); ASSERT(descriptor->DescriptorTypesCount < 255); - DSWriteContainer.BindingToDynamicOffsetMap.AddDefault(descriptor->DescriptorTypesCount); - DSWriteContainer.BindingToDynamicOffsetMap.SetAll(255); + DSWriteContainer.BindingToDynamicOffset.AddDefault(descriptor->DescriptorTypesCount); + DSWriteContainer.BindingToDynamicOffset.SetAll(255); } VkWriteDescriptorSet* currentDescriptorWrite = DSWriteContainer.DescriptorWrites.Get(); VkDescriptorImageInfo* currentImageInfo = DSWriteContainer.DescriptorImageInfo.Get(); VkDescriptorBufferInfo* currentBufferInfo = DSWriteContainer.DescriptorBufferInfo.Get(); - uint8* currentBindingToDynamicOffsetMap = DSWriteContainer.BindingToDynamicOffsetMap.Get(); + byte* currentBindingToDynamicOffsetMap = DSWriteContainer.BindingToDynamicOffset.Get(); uint32 dynamicOffsetsStart[DescriptorSet::GraphicsStagesCount]; - uint32 totalNumDynamicOffsets = 0; + uint32 dynamicOffsetsCount = 0; for (int32 stage = 0; stage < DescriptorSet::GraphicsStagesCount; stage++) { - dynamicOffsetsStart[stage] = totalNumDynamicOffsets; + dynamicOffsetsStart[stage] = dynamicOffsetsCount; const auto descriptor = DescriptorInfoPerStage[stage]; if (descriptor == nullptr || descriptor->DescriptorTypesCount == 0) continue; const uint32 numDynamicOffsets = DSWriter[stage].SetupDescriptorWrites(*descriptor, currentDescriptorWrite, currentImageInfo, currentBufferInfo, currentBindingToDynamicOffsetMap); - totalNumDynamicOffsets += numDynamicOffsets; + dynamicOffsetsCount += numDynamicOffsets; currentDescriptorWrite += descriptor->DescriptorTypesCount; currentImageInfo += descriptor->ImageInfosCount; @@ -373,7 +370,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc) currentBindingToDynamicOffsetMap += descriptor->DescriptorTypesCount; } - DynamicOffsets.AddZeroed(totalNumDynamicOffsets); + DynamicOffsets.AddZeroed(dynamicOffsetsCount); for (int32 stage = 0; stage < DescriptorSet::GraphicsStagesCount; stage++) { DSWriter[stage].DynamicOffsets = dynamicOffsetsStart[stage] + DynamicOffsets.Get(); diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp index fc1c5ab8d..632b9fe37 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp @@ -187,10 +187,10 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height) const auto& gpu = _device->Adapter->Gpu; - // Find pixel format for presentable images + // Pick a format for backbuffer PixelFormat resultFormat = GPU_BACK_BUFFER_PIXEL_FORMAT; - VkSurfaceFormatKHR curFormat; - Platform::MemoryClear(&curFormat, sizeof(curFormat)); + VkSurfaceFormatKHR result; + Platform::MemoryClear(&result, sizeof(result)); { uint32 surfaceFormatsCount; VALIDATE_VULKAN_RESULT(vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, _surface, &surfaceFormatsCount, nullptr)); @@ -210,7 +210,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height) { if (surfaceFormats[i].format == requested) { - curFormat = surfaceFormats[i]; + result = surfaceFormats[i]; found = true; break; } @@ -240,8 +240,8 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height) if (surfaceFormats[i].format == RenderToolsVulkan::ToVulkanFormat(static_cast(pixelFormat))) { resultFormat = static_cast(pixelFormat); - curFormat = surfaceFormats[i]; - LOG(Info, "No swapchain format requested, picking up Vulkan format {0}", (uint32)curFormat.format); + result = surfaceFormats[i]; + LOG(Info, "No swapchain format requested, picking up Vulkan format {0}", (uint32)result.format); break; } } @@ -264,7 +264,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height) if (surfaceFormats[i].format == format) { supported = true; - curFormat = surfaceFormats[i]; + result = surfaceFormats[i]; break; } } @@ -290,13 +290,13 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height) LOG(Error, "Unable to find a pixel format for the swapchain; swapchain returned {0} Vulkan formats {1}", surfaceFormats.Count(), *msg); } } - curFormat.format = RenderToolsVulkan::ToVulkanFormat(resultFormat); + result.format = RenderToolsVulkan::ToVulkanFormat(resultFormat); _format = resultFormat; // Prepare present queue _device->SetupPresentQueue(_surface); - // Fetch present mode + // Calculate the swap chain present mode VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; { uint32 presentModesCount = 0; @@ -358,8 +358,8 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height) RenderToolsVulkan::ZeroStruct(swapChainInfo, VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR); swapChainInfo.surface = _surface; swapChainInfo.minImageCount = VULKAN_BACK_BUFFERS_COUNT; - swapChainInfo.imageFormat = curFormat.format; - swapChainInfo.imageColorSpace = curFormat.colorSpace; + swapChainInfo.imageFormat = result.format; + swapChainInfo.imageColorSpace = result.colorSpace; swapChainInfo.imageExtent.width = width; swapChainInfo.imageExtent.height = height; swapChainInfo.imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; diff --git a/Source/Engine/Physics/Physics.Queries.cpp b/Source/Engine/Physics/Physics.Queries.cpp index 812e9ae14..51578b055 100644 --- a/Source/Engine/Physics/Physics.Queries.cpp +++ b/Source/Engine/Physics/Physics.Queries.cpp @@ -78,7 +78,7 @@ protected: { if (this->hasBlock) { - // Copy blocking hit to hits + // Blocking hits go to hits processTouches(&this->block, 1); } } diff --git a/Source/Engine/Physics/Physics.cpp b/Source/Engine/Physics/Physics.cpp index 1abf6d49d..265b1250c 100644 --- a/Source/Engine/Physics/Physics.cpp +++ b/Source/Engine/Physics/Physics.cpp @@ -177,8 +177,7 @@ bool PhysicsService::Init() // only in non-production builds. #if PHYSX_MEMORY_STATS - // Want names of PhysX allocations - GPhysXFoundation->setReportAllocationNames(true); + _foundation->setReportAllocationNames(true); #endif // Config diff --git a/Source/Engine/Platform/Android/AndroidPlatform.cpp b/Source/Engine/Platform/Android/AndroidPlatform.cpp index 7c937e111..a5a0c4b89 100644 --- a/Source/Engine/Platform/Android/AndroidPlatform.cpp +++ b/Source/Engine/Platform/Android/AndroidPlatform.cpp @@ -767,7 +767,7 @@ void AndroidPlatform::GetSystemTime(int32& year, int32& month, int32& dayOfWeek, void AndroidPlatform::GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond) { - // Query for calendar time + // Get the calendar time struct timeval time; gettimeofday(&time, nullptr); @@ -803,11 +803,11 @@ bool AndroidPlatform::Init() } // Set info about the CPU - cpu_set_t availableCpusMask; - CPU_ZERO(&availableCpusMask); - if (sched_getaffinity(0, sizeof(availableCpusMask), &availableCpusMask) == 0) + cpu_set_t cpus; + CPU_ZERO(&cpus); + if (sched_getaffinity(0, sizeof(cpus), &cpus) == 0) { - AndroidCpu.ProcessorCoreCount = AndroidCpu.LogicalProcessorCount = CPU_COUNT(&availableCpusMask); + AndroidCpu.ProcessorCoreCount = AndroidCpu.LogicalProcessorCount = CPU_COUNT(&cpus); } else { diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 4d16a4c47..06b714658 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -1277,7 +1277,7 @@ void LinuxPlatform::GetSystemTime(int32& year, int32& month, int32& dayOfWeek, i void LinuxPlatform::GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond) { - // Query for calendar time + // Get the calendar time struct timeval time; gettimeofday(&time, nullptr); @@ -1315,34 +1315,33 @@ bool LinuxPlatform::Init() } // Set info about the CPU - cpu_set_t availableCpusMask; - CPU_ZERO(&availableCpusMask); - if (sched_getaffinity(0, sizeof(availableCpusMask), &availableCpusMask) == 0) + cpu_set_t cpus; + CPU_ZERO(&cpus); + if (sched_getaffinity(0, sizeof(cpus), &cpus) == 0) { int32 numberOfCores = 0; struct CpuInfo { - int Core; - int Package; - } cpuInfos[CPU_SETSIZE]; - - Platform::MemoryClear(cpuInfos, sizeof(cpuInfos)); - int maxCoreId = 0; - int maxPackageId = 0; - int cpuCountAvailable = 0; + int32 Core; + int32 Package; + } cpusInfo[CPU_SETSIZE]; + Platform::MemoryClear(cpusInfo, sizeof(cpusInfo)); + int32 maxCoreId = 0; + int32 maxPackageId = 0; + int32 cpuCountAvailable = 0; for (int32 cpuIdx = 0; cpuIdx < CPU_SETSIZE; cpuIdx++) { - if (CPU_ISSET(cpuIdx, &availableCpusMask)) + if (CPU_ISSET(cpuIdx, &cpus)) { cpuCountAvailable++; sprintf(fileNameBuffer, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpuIdx); if (FILE* coreIdFile = fopen(fileNameBuffer, "r")) { - if (fscanf(coreIdFile, "%d", &cpuInfos[cpuIdx].Core) != 1) + if (fscanf(coreIdFile, "%d", &cpusInfo[cpuIdx].Core) != 1) { - cpuInfos[cpuIdx].Core = 0; + cpusInfo[cpuIdx].Core = 0; } fclose(coreIdFile); } @@ -1350,22 +1349,21 @@ bool LinuxPlatform::Init() sprintf(fileNameBuffer, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpuIdx); if (FILE* packageIdFile = fopen(fileNameBuffer, "r")) { - // physical_package_id can be -1 on embedded devices - treat all CPUs as separate in that case. - if (fscanf(packageIdFile, "%d", &cpuInfos[cpuIdx].Package) != 1 || cpuInfos[cpuIdx].Package < 0) + if (fscanf(packageIdFile, "%d", &cpusInfo[cpuIdx].Package) != 1 || cpusInfo[cpuIdx].Package < 0) { - cpuInfos[cpuIdx].Package = cpuInfos[cpuIdx].Core; + cpusInfo[cpuIdx].Package = cpusInfo[cpuIdx].Core; } fclose(packageIdFile); } - maxCoreId = Math::Max(maxCoreId, cpuInfos[cpuIdx].Core); - maxPackageId = Math::Max(maxPackageId, cpuInfos[cpuIdx].Package); + maxCoreId = Math::Max(maxCoreId, cpusInfo[cpuIdx].Core); + maxPackageId = Math::Max(maxPackageId, cpusInfo[cpuIdx].Package); } } - int coresCount = maxCoreId + 1; - int packagesCount = maxPackageId + 1; - int pairsCount = packagesCount * coresCount; + int32 coresCount = maxCoreId + 1; + int32 packagesCount = maxPackageId + 1; + int32 pairsCount = packagesCount * coresCount; if (coresCount * 2 < cpuCountAvailable) { @@ -1378,9 +1376,9 @@ bool LinuxPlatform::Init() for (int32 cpuIdx = 0; cpuIdx < CPU_SETSIZE; cpuIdx++) { - if (CPU_ISSET(cpuIdx, &availableCpusMask)) + if (CPU_ISSET(cpuIdx, &cpus)) { - pairs[cpuInfos[cpuIdx].Package * coresCount + cpuInfos[cpuIdx].Core] = 1; + pairs[cpusInfo[cpuIdx].Package * coresCount + cpusInfo[cpuIdx].Core] = 1; } } @@ -1394,7 +1392,7 @@ bool LinuxPlatform::Init() UnixCpu.ProcessorPackageCount = packagesCount; UnixCpu.ProcessorCoreCount = Math::Max(numberOfCores, 1); - UnixCpu.LogicalProcessorCount = CPU_COUNT(&availableCpusMask); + UnixCpu.LogicalProcessorCount = CPU_COUNT(&cpus); } else { diff --git a/Source/Engine/Platform/Windows/WindowsWindow.cpp b/Source/Engine/Platform/Windows/WindowsWindow.cpp index 58a7de73e..6fb496ac1 100644 --- a/Source/Engine/Platform/Windows/WindowsWindow.cpp +++ b/Source/Engine/Platform/Windows/WindowsWindow.cpp @@ -417,13 +417,13 @@ void WindowsWindow::GetScreenInfo(int32& x, int32& y, int32& width, int32& heigh { ASSERT(HasHWND()); - // Grab current monitor data for sizing + // Pick the current monitor data for sizing const HMONITOR monitor = MonitorFromWindow(_handle, MONITOR_DEFAULTTONEAREST); MONITORINFO monitorInfo; monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfoW(monitor, &monitorInfo); - // Return result + // Calculate result x = monitorInfo.rcMonitor.left; y = monitorInfo.rcMonitor.top; width = monitorInfo.rcMonitor.right - x; diff --git a/Source/Engine/Render2D/FontTextureAtlas.cpp b/Source/Engine/Render2D/FontTextureAtlas.cpp index 63b70f447..e964d455c 100644 --- a/Source/Engine/Render2D/FontTextureAtlas.cpp +++ b/Source/Engine/Render2D/FontTextureAtlas.cpp @@ -126,12 +126,11 @@ void FontTextureAtlas::CopyDataIntoSlot(const Slot* slot, const Array& dat } } - // Copy each row of the texture + // Actual data copy for (uint32 row = padding; row < slot->Height - padding; row++) { rowData.SrcRow = row - padding; rowData.DstRow = row; - copyRow(rowData); } diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index 369980daa..6618a6e2c 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1292,7 +1292,7 @@ void Render2D::DrawRectangle(const Rectangle& rect, const Color& color1, const C drawCall.StartIB = IBIndex; drawCall.CountIB = 4 * (6 + 3); - // The has to match HLSL code + // This must be the same as in HLSL code const float filterScale = 1.0f; const float thicknessHalf = (2.82842712f + thickness) * 0.5f + filterScale; @@ -1544,10 +1544,8 @@ void DrawLines(const Vector2* points, int32 pointsCount, const Color& color1, co Vector2 p1t, p2t; #if RENDER2D_USE_LINE_AA - // Half of the width of the filter size to use for anti-aliasing. Increasing this value will increase the fuzziness of line edges. - const float filterScale = 1.0f; // Must match HLSL code - - // The amount we increase each side of the line to generate enough pixels + // This must be the same as in HLSL code + const float filterScale = 1.0f; const float thicknessHalf = (2.82842712f + thickness) * 0.5f + filterScale; drawCall.Type = DrawCallType::LineAA; diff --git a/Source/Engine/Renderer/ReflectionsPass.cpp b/Source/Engine/Renderer/ReflectionsPass.cpp index 39d02d025..51f48d401 100644 --- a/Source/Engine/Renderer/ReflectionsPass.cpp +++ b/Source/Engine/Renderer/ReflectionsPass.cpp @@ -12,6 +12,10 @@ #if GENERATE_GF_CACHE +// This code below (PreIntegratedGF namespace) is based on many Siggraph presentations about BRDF shading: +// https://blog.selfshadow.com/publications/s2015-shading-course/ +// https://blog.selfshadow.com/publications/s2012-shading-course/ + #include #include #include diff --git a/Source/Engine/Renderer/VolumetricFogPass.cpp b/Source/Engine/Renderer/VolumetricFogPass.cpp index f92dcb82c..aebe21c6e 100644 --- a/Source/Engine/Renderer/VolumetricFogPass.cpp +++ b/Source/Engine/Renderer/VolumetricFogPass.cpp @@ -152,7 +152,7 @@ bool VolumetricFogPass::Init(RenderContext& renderContext, GPUContext* context, _cache.GridSizeZ = 64; _cache.FogJitter = false; _cache.TemporalReprojection = false; - _cache.HistoryMissSupersampleCount = 1; + _cache.MissedHistorySamplesCount = 1; break; } case Quality::Medium: @@ -161,7 +161,7 @@ bool VolumetricFogPass::Init(RenderContext& renderContext, GPUContext* context, _cache.GridSizeZ = 64; _cache.FogJitter = true; _cache.TemporalReprojection = true; - _cache.HistoryMissSupersampleCount = 4; + _cache.MissedHistorySamplesCount = 4; break; } case Quality::High: @@ -170,7 +170,7 @@ bool VolumetricFogPass::Init(RenderContext& renderContext, GPUContext* context, _cache.GridSizeZ = 128; _cache.FogJitter = true; _cache.TemporalReprojection = true; - _cache.HistoryMissSupersampleCount = 4; + _cache.MissedHistorySamplesCount = 4; break; } case Quality::Ultra: @@ -179,7 +179,7 @@ bool VolumetricFogPass::Init(RenderContext& renderContext, GPUContext* context, _cache.GridSizeZ = 256; _cache.FogJitter = true; _cache.TemporalReprojection = true; - _cache.HistoryMissSupersampleCount = 8; + _cache.MissedHistorySamplesCount = 8; break; } } @@ -208,7 +208,7 @@ bool VolumetricFogPass::Init(RenderContext& renderContext, GPUContext* context, _cache.Data.InverseSquaredLightDistanceBiasScale = _cache.InverseSquaredLightDistanceBiasScale; _cache.Data.PhaseG = options.ScatteringDistribution; _cache.Data.VolumetricFogMaxDistance = options.Distance; - _cache.Data.HistoryMissSuperSampleCount = Math::Clamp(_cache.HistoryMissSupersampleCount, 1, (int32)ARRAY_COUNT(_cache.Data.FrameJitterOffsets)); + _cache.Data.MissedHistorySamplesCount = Math::Clamp(_cache.MissedHistorySamplesCount, 1, (int32)ARRAY_COUNT(_cache.Data.FrameJitterOffsets)); Matrix::Transpose(view.PrevViewProjection, _cache.Data.PrevWorldToClip); _cache.Data.DirectionalLightShadow.NumCascades = 0; _cache.Data.SkyLight.VolumetricScatteringIntensity = 0; @@ -221,7 +221,7 @@ bool VolumetricFogPass::Init(RenderContext& renderContext, GPUContext* context, } if (_cache.FogJitter && _cache.TemporalReprojection) { - for (int32 i = 0; i < _cache.HistoryMissSupersampleCount; i++) + for (int32 i = 0; i < _cache.MissedHistorySamplesCount; i++) { const uint64 frameNumber = renderContext.Task->LastUsedFrame - i; _cache.Data.FrameJitterOffsets[i] = Vector4( diff --git a/Source/Engine/Renderer/VolumetricFogPass.h b/Source/Engine/Renderer/VolumetricFogPass.h index 26c4dfc99..576aee5c5 100644 --- a/Source/Engine/Renderer/VolumetricFogPass.h +++ b/Source/Engine/Renderer/VolumetricFogPass.h @@ -30,7 +30,7 @@ private: float HistoryWeight; Vector3 GridSize; - uint32 HistoryMissSuperSampleCount; + uint32 MissedHistorySamplesCount; int32 GridSizeIntX; int32 GridSizeIntY; @@ -105,9 +105,9 @@ private: float HistoryWeight; /// - /// Number of lighting samples to compute for voxels whose history value is not available. This reduces noise when panning or on camera cuts, but introduces a variable cost to volumetric fog computation. Valid range [1, 8]. + /// The amount of lighting samples to compute for voxels whose history value is not available. This reduces noise when panning or on camera cuts, but introduces a variable cost to volumetric fog computation. Valid range [1, 8]. /// - int32 HistoryMissSupersampleCount; + int32 MissedHistorySamplesCount; /// /// Scales the amount added to the inverse squared falloff denominator. This effectively removes the spike from inverse squared falloff that causes extreme aliasing. diff --git a/Source/Engine/Utilities/Crc.cpp b/Source/Engine/Utilities/Crc.cpp index 25ca8f0c6..fc922ac89 100644 --- a/Source/Engine/Utilities/Crc.cpp +++ b/Source/Engine/Utilities/Crc.cpp @@ -4,7 +4,9 @@ #include "Engine/Core/Math/Math.h" #include "Engine/Platform/Platform.h" -// Use CRC 32 polynomial +// Based on the Slicing-by-8 implementation found here: +// http://slicing-by-8.sourceforge.net/ + enum { Crc32Poly = 0x04c11db7 }; uint32 Crc::CachedCRCTablesSB8[8][256] = diff --git a/Source/Engine/Utilities/PerlinNoise.cs b/Source/Engine/Utilities/PerlinNoise.cs index e876bd689..1a47e6a4b 100644 --- a/Source/Engine/Utilities/PerlinNoise.cs +++ b/Source/Engine/Utilities/PerlinNoise.cs @@ -71,9 +71,9 @@ namespace FlaxEngine.Utilities return Base + noise * NoiseAmount; } - private float Fade(float T) + private float Fade(float t) { - return T * T * T * (T * (T * 6 - 15) + 10); + return t * t * t * (t * (t * 6 - 15) + 10); } private float Grad(int hash, float x, float y) diff --git a/Source/Shaders/ColorGrading.shader b/Source/Shaders/ColorGrading.shader index 9a811cb0b..fdad35dd6 100644 --- a/Source/Shaders/ColorGrading.shader +++ b/Source/Shaders/ColorGrading.shader @@ -109,8 +109,14 @@ float3 ColorCorrect(float3 color, float luma, float4 saturation, float4 contrast return color; } -float3 ColorCorrectAll(float3 color) +float3 ColorGrade(float3 linearColor) { + // Convert into ACEScg color + const float3x3 sRGB_2_AP1 = mul(XYZ_2_AP1_MAT, mul(D65_2_D60_CAT, sRGB_2_XYZ_MAT)); + const float3x3 AP1_2_sRGB = mul(XYZ_2_sRGB_MAT, mul(D60_2_D65_CAT, AP1_2_XYZ_MAT)); + float3 color = mul(sRGB_2_AP1, linearColor); + + // Perform color grading with CC wheels float luma = dot(color, AP1_RGB2Y); float3 ccColorShadows = ColorCorrect(color, luma, ColorSaturationShadows, ColorContrastShadows, ColorGammaShadows, ColorGainShadows, ColorOffsetShadows); float ccWeightShadows = 1 - smoothstep(0, ColorCorrectionShadowsMax, luma); @@ -118,18 +124,7 @@ float3 ColorCorrectAll(float3 color) float ccWeightHighlights = smoothstep(ColorCorrectionHighlightsMin, 1, luma); float3 ccColorMidtones = ColorCorrect(color, luma, ColorSaturationMidtones, ColorContrastMidtones, ColorGammaMidtones, ColorGainMidtones, ColorOffsetMidtones); float ccWeightMidtones = 1 - ccWeightShadows - ccWeightHighlights; - return ccColorShadows * ccWeightShadows + ccColorMidtones * ccWeightMidtones + ccColorHighlights * ccWeightHighlights; -} - -float3 ColorGrade(float3 linearColor) -{ - // ACEScg working space - const float3x3 sRGB_2_AP1 = mul(XYZ_2_AP1_MAT, mul(D65_2_D60_CAT, sRGB_2_XYZ_MAT)); - const float3x3 AP1_2_sRGB = mul(XYZ_2_sRGB_MAT, mul(D60_2_D65_CAT, AP1_2_XYZ_MAT)); - float3 color = mul(sRGB_2_AP1, linearColor); - - // Nuke-style color correct - color = ColorCorrectAll(color); + color = ccColorShadows * ccWeightShadows + ccColorMidtones * ccWeightMidtones + ccColorHighlights * ccWeightHighlights; // Convert back to linear color return mul(AP1_2_sRGB, color); @@ -216,23 +211,20 @@ float4 CombineLUTs(float2 uv, uint layerIndex) { float3 encodedColor; #if USE_VOLUME_LUT - // Construct the neutral color from a 3d position volume texture + // Calculate the neutral color from 3d position { uv = uv - float2(0.5f / LUTSize, 0.5f / LUTSize); encodedColor = float3(uv * LUTSize / (LUTSize - 1), layerIndex / (LUTSize - 1)); } #else - // Construct the neutral color from a 2d position in 256x16 + // Calculate the neutral color from 2d position { uv -= float2(0.49999f / (LUTSize * LUTSize), 0.49999f / LUTSize); - float3 rgb; rgb.r = frac(uv.x * LUTSize); rgb.b = uv.x - rgb.r / LUTSize; rgb.g = uv.y; - - float scale = LUTSize / (LUTSize - 1); - encodedColor = rgb * scale; + encodedColor = rgb * (LUTSize / (LUTSize - 1)); } #endif diff --git a/Source/Shaders/ExponentialHeightFog.hlsl b/Source/Shaders/ExponentialHeightFog.hlsl index 9727380f1..0040c8ed3 100644 --- a/Source/Shaders/ExponentialHeightFog.hlsl +++ b/Source/Shaders/ExponentialHeightFog.hlsl @@ -37,7 +37,7 @@ float4 GetExponentialHeightFog(ExponentialHeightFogData exponentialHeightFog, fl float cameraToPosLen = cameraToPosSqr * cameraToPosLenInv; float3 cameraToReceiverNorm = cameraToPos * cameraToPosLenInv; - float rayOriginTerms = exponentialHeightFog.FogAtViewPosition; + float rayOriginTerms = exponentialHeightFog.FogAtViewPosition; float rayLength = cameraToPosLen; float rayDirectionY = cameraToPos.y; @@ -48,25 +48,20 @@ float4 GetExponentialHeightFog(ExponentialHeightFogData exponentialHeightFog, fl float excludeIntersectionTime = skipDistance * cameraToPosLenInv; float cameraToExclusionIntersectionY = excludeIntersectionTime * cameraToPos.y; float exclusionIntersectionY = camWS.y + cameraToExclusionIntersectionY; - float exclusionIntersectionToReceiverY = cameraToPos.y - cameraToExclusionIntersectionY; - - // Calculate fog off of the ray starting from the exclusion distance, instead of starting from the camera rayLength = (1.0f - excludeIntersectionTime) * cameraToPosLen; - rayDirectionY = exclusionIntersectionToReceiverY; - - // Move off the viewer + rayDirectionY = cameraToPos.y - cameraToExclusionIntersectionY; float exponent = exponentialHeightFog.FogHeightFalloff * (exclusionIntersectionY - exponentialHeightFog.FogHeight); rayOriginTerms = exponentialHeightFog.FogDensity * exp2(-exponent); } - // Calculate the line integral of the ray from the camera to the receiver position through the fog density function + // Calculate the integral of the ray starting from the view to the object position with the fog density function float falloff = max(-127.0f, exponentialHeightFog.FogHeightFalloff * rayDirectionY); float lineIntegral = (1.0f - exp2(-falloff)) / falloff; - float lineIntegralTaylor = log(2.0) - (0.5 * Pow2(log(2.0))) * falloff; + float lineIntegralTaylor = log(2.0f) - (0.5f * Pow2(log(2.0f))) * falloff; float exponentialHeightLineIntegralCalc = rayOriginTerms * (abs(falloff) > 0.01f ? lineIntegral : lineIntegralTaylor); float exponentialHeightLineIntegral = exponentialHeightLineIntegralCalc * rayLength; - // Calculate the amount of light that made it through the fog using the transmission equation + // Calculate the light that went through the fog float expFogFactor = max(saturate(exp2(-exponentialHeightLineIntegral)), exponentialHeightFog.FogMinOpacity); // Calculate the directional light inscattering @@ -75,17 +70,10 @@ float4 GetExponentialHeightFog(ExponentialHeightFogData exponentialHeightFog, fl BRANCH if (exponentialHeightFog.ApplyDirectionalInscattering > 0) { - // Setup a cosine lobe around the light direction to approximate inscattering from the directional light off of the ambient haze float3 directionalLightInscattering = exponentialHeightFog.DirectionalInscatteringColor * pow(saturate(dot(cameraToReceiverNorm, exponentialHeightFog.InscatteringLightDirection)), exponentialHeightFog.DirectionalInscatteringExponent); - - // Calculate the line integral of the eye ray through the haze, using a special starting distance to limit the inscattering to the distance float dirExponentialHeightLineIntegral = exponentialHeightLineIntegralCalc * max(rayLength - exponentialHeightFog.DirectionalInscatteringStartDistance, 0.0f); - - // Calculate the amount of light that made it through the fog using the transmission equation float directionalInscatteringFogFactor = saturate(exp2(-dirExponentialHeightLineIntegral)); - - // Final inscattering from the light - directionalInscattering = directionalLightInscattering * (1 - directionalInscatteringFogFactor); + directionalInscattering = directionalLightInscattering * (1.0f - directionalInscatteringFogFactor); } // Disable fog after a certain distance diff --git a/Source/Shaders/Forward.shader b/Source/Shaders/Forward.shader index fbd91b7f3..0c786eddd 100644 --- a/Source/Shaders/Forward.shader +++ b/Source/Shaders/Forward.shader @@ -9,24 +9,16 @@ Texture2D Distortion : register(t1); META_PS(true, FEATURE_LEVEL_ES2) float4 PS_ApplyDistortion(Quad_VS2PS input) : SV_Target { - // Sample accumulated distortion offset - half4 accumDist = Distortion.Sample(SamplerPointClamp, input.TexCoord); - - // Offset = [R-B,G-A] - half2 distOffset = (accumDist.rg - accumDist.ba); - - static const half InvDistortionScaleBias = 1 / 4.0f; - distOffset *= InvDistortionScaleBias; - + float4 accumDist = Distortion.Sample(SamplerPointClamp, input.TexCoord); + float2 distOffset = (accumDist.rg - accumDist.ba) / 4.0f; float2 newTexCoord = input.TexCoord + distOffset; - // If we're about to sample outside the valid area, set to 0 distortion + // Clamp around screen FLATTEN if (newTexCoord.x < 0 || newTexCoord.x > 1 || newTexCoord.y < 0 || newTexCoord.y > 1) { newTexCoord = input.TexCoord; } - // Sample screen using offset coords return Input.SampleLevel(SamplerPointClamp, newTexCoord, 0); } diff --git a/Source/Shaders/GammaCorrectionCommon.hlsl b/Source/Shaders/GammaCorrectionCommon.hlsl index 7a1d1f6cf..ee3e9d222 100644 --- a/Source/Shaders/GammaCorrectionCommon.hlsl +++ b/Source/Shaders/GammaCorrectionCommon.hlsl @@ -60,34 +60,18 @@ half3 sRGBToLinear(half3 color) float3 LogToLinear(float3 logColor) { - const float linearRange = 14; - const float linearGrey = 0.18; - const float exposureGrey = 444; - - // Using stripped down, 'pure log', formula. Parameterized by grey points and dynamic range covered. - float3 linearColor = exp2((logColor - exposureGrey / 1023.0) * linearRange) * linearGrey; - //float3 linearColor = 2 * (pow(10.0, ((logColor - 0.616596 - 0.03) / 0.432699)) - 0.037584); // SLog - //float3 linearColor = (pow( 10, (1023 * logColor - 685) / 300) - 0.0108) / (1 - 0.0108); // Cineon - //linearColor = max(0, linearColor); - - return linearColor; + const float linearRange = 14.0f; + const float linearGrey = 0.18f; + const float exposureGrey = 444.0f; + return exp2((logColor - exposureGrey / 1023.0) * linearRange) * linearGrey; } float3 LinearToLog(float3 linearColor) { - const float linearRange = 14; - const float linearGrey = 0.18; - const float exposureGrey = 444; - - // Using stripped down, 'pure log', formula. Parameterized by grey points and dynamic range covered. - float3 logColor = log2(linearColor) / linearRange - log2(linearGrey) / linearRange + exposureGrey / 1023.0; // scalar: 3log2 3mad - //float3 logColor = (log2(linearColor) - log2(linearGrey)) / linearRange + exposureGrey / 1023.0; - //float3 logColor = log2(linearColor / linearGrey) / linearRange + exposureGrey / 1023.0; - //float3 logColor = (0.432699 * log10(0.5 * linearColor + 0.037584) + 0.616596) + 0.03; // SLog - //float3 logColor = (300 * log10(linearColor * (1 - 0.0108) + 0.0108) + 685) / 1023; // Cineon - logColor = saturate(logColor); - - return logColor; + const float linearRange = 14.0f; + const float linearGrey = 0.18f; + const float exposureGrey = 444.0f; + return saturate(log2(linearColor) / linearRange - log2(linearGrey) / linearRange + exposureGrey / 1023.0f); } #endif diff --git a/Source/Shaders/LightingCommon.hlsl b/Source/Shaders/LightingCommon.hlsl index ac98ef360..ba0b9b4bf 100644 --- a/Source/Shaders/LightingCommon.hlsl +++ b/Source/Shaders/LightingCommon.hlsl @@ -82,19 +82,16 @@ void GetRadialLightAttenuation( BRANCH if (lightData.SourceLength > 0) { - // Line segment irradiance - float3 L01 = lightData.Direction * lightData.SourceLength; - float3 L0 = toLight - 0.5 * L01; - float3 L1 = toLight + 0.5 * L01; - float LengthL0 = length(L0); - float LengthL1 = length(L1); - - distanceAttenuation = rcp((LengthL0 * LengthL1 + dot(L0, L1)) * 0.5 + distanceBiasSqr); - NoL = saturate(0.5 * (dot(N, L0) / LengthL0 + dot(N, L1) / LengthL1)); + float3 l01 = lightData.Direction * lightData.SourceLength; + float3 l0 = toLight - 0.5 * l01; + float3 l1 = toLight + 0.5 * l01; + float lengthL0 = length(l0); + float lengthL1 = length(l1); + distanceAttenuation = rcp((lengthL0 * lengthL1 + dot(l0, l1)) * 0.5 + distanceBiasSqr); + NoL = saturate(0.5 * (dot(N, l0) / lengthL0 + dot(N, l1) / lengthL1)); } else { - // Sphere irradiance (technically just 1/d^2 but this avoids inf) distanceAttenuation = rcp(distanceSqr + distanceBiasSqr); NoL = saturate(dot(N, L)); } diff --git a/Source/Shaders/PostProcessing.shader b/Source/Shaders/PostProcessing.shader index 1b8db3638..1dacf6e31 100644 --- a/Source/Shaders/PostProcessing.shader +++ b/Source/Shaders/PostProcessing.shader @@ -98,8 +98,6 @@ Texture2D Input3 : register(t3); Texture2D LensDirt : register(t4); Texture2D LensStar : register(t5); Texture2D LensColor : register(t6); - -// LUT for color grading #if USE_VOLUME_LUT Texture3D ColorGradingLUT : register(t7); #else diff --git a/Source/Shaders/ShadowsSampling.hlsl b/Source/Shaders/ShadowsSampling.hlsl index fbadc64de..26bd8db90 100644 --- a/Source/Shaders/ShadowsSampling.hlsl +++ b/Source/Shaders/ShadowsSampling.hlsl @@ -119,7 +119,7 @@ float SampleShadowMapFixedSizePCF(Texture2DArray shadowMap, float2 shadowMapSize if (value != 0.0f) { - // Using Gather: xyzw in counter clockwise order starting with the sample to the lower left of the queried location + // Gather returns xyzw which is counter clockwise order starting with the sample to the lower left of the queried location #if CAN_USE_GATHER v1[(col + FS_2) / 2] = shadowMap.GatherCmp(ShadowSampler, baseUV, sceneDepth, int2(col, row)); diff --git a/Source/Shaders/VolumetricFog.shader b/Source/Shaders/VolumetricFog.shader index 0b1fdb650..8bd344f73 100644 --- a/Source/Shaders/VolumetricFog.shader +++ b/Source/Shaders/VolumetricFog.shader @@ -37,7 +37,7 @@ float3 GlobalEmissive; float HistoryWeight; float3 GridSize; -uint HistoryMissSuperSampleCount; +uint MissedHistorySamplesCount; int3 GridSizeInt; float PhaseG; @@ -205,7 +205,7 @@ float4 PS_InjectLight(Quad_GS2PS input) : SV_Target0 { historyAlpha = 0; } - uint samplesCount = historyAlpha < 0.001f ? HistoryMissSuperSampleCount : 1; + uint samplesCount = historyAlpha < 0.001f ? MissedHistorySamplesCount : 1; #else uint samplesCount = 1; #endif @@ -261,7 +261,6 @@ void CS_Initialize(uint3 GroupId : SV_GroupID, uint3 DispatchThreadId : SV_Dispa { uint3 gridCoordinate = DispatchThreadId; - // Center of the voxel float voxelOffset = 0.5f; float3 positionWS = GetCellPositionWS(gridCoordinate, voxelOffset); @@ -272,11 +271,10 @@ void CS_Initialize(uint3 GroupId : SV_GroupID, uint3 DispatchThreadId : SV_Dispa // Calculate the global fog density that matches the exponential height fog density float globalDensity = fogDensity * exp2(-fogHeightFalloff * (positionWS.y - fogHeight)); - float matchFactor = 0.24f; - float extinction = max(globalDensity * GlobalExtinctionScale * matchFactor, 0); + float extinction = max(0.0f, globalDensity * GlobalExtinctionScale * 0.24f); float3 scattering = GlobalAlbedo * extinction; - float absorption = max(extinction - Luminance(scattering), 0.0f); + float absorption = max(0.0f, extinction - Luminance(scattering)); if (all((int3)gridCoordinate < GridSizeInt)) { @@ -306,7 +304,7 @@ void CS_LightScattering(uint3 GroupId : SV_GroupID, uint3 DispatchThreadId : SV_ { uint3 gridCoordinate = DispatchThreadId; float3 lightScattering = 0; - uint numSuperSamples = 1; + uint samplesCount = 1; #if USE_TEMPORAL_REPROJECTION float3 historyUV = GetVolumeUV(GetCellPositionWS(gridCoordinate, 0.5f), PrevWorldToClip); @@ -318,13 +316,11 @@ void CS_LightScattering(uint3 GroupId : SV_GroupID, uint3 DispatchThreadId : SV_ { historyAlpha = 0; } - - // Supersample if the history was outside the camera frustum - // The compute shader is dispatched with extra threads, make sure those don't supersample - numSuperSamples = historyAlpha < 0.001f && all(gridCoordinate < GridSizeInt) ? HistoryMissSuperSampleCount : 1; + + samplesCount = historyAlpha < 0.001f && all(gridCoordinate < GridSizeInt) ? MissedHistorySamplesCount : 1; #endif - for (uint sampleIndex = 0; sampleIndex < numSuperSamples; sampleIndex++) + for (uint sampleIndex = 0; sampleIndex < samplesCount; sampleIndex++) { float3 cellOffset = FrameJitterOffsets[sampleIndex].xyz; //float3 cellOffset = 0.5f; @@ -357,8 +353,7 @@ void CS_LightScattering(uint3 GroupId : SV_GroupID, uint3 DispatchThreadId : SV_ lightScattering += skyLighting * SkyLight.VolumetricScatteringIntensity; } } - - lightScattering /= (float)numSuperSamples; + lightScattering /= (float)samplesCount; // Apply scattering from the point and spot lights lightScattering += LocalShadowedLightScattering[gridCoordinate].rgb; diff --git a/Source/Tools/Flax.Build/Deploy/VCEnvironment.cs b/Source/Tools/Flax.Build/Deploy/VCEnvironment.cs index e7ef5997f..359c571ef 100644 --- a/Source/Tools/Flax.Build/Deploy/VCEnvironment.cs +++ b/Source/Tools/Flax.Build/Deploy/VCEnvironment.cs @@ -71,7 +71,7 @@ namespace Flax.Deploy } } - if (TryReadInstallPath("Microsoft\\VisualStudio\\SxS\\VS7", "15.0", "MSBuild\\15.0\\bin\\MSBuild.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\VisualStudio\\SxS\\VS7", "15.0", "MSBuild\\15.0\\bin\\MSBuild.exe", out toolPath)) { return toolPath; } @@ -82,17 +82,17 @@ namespace Flax.Deploy return toolPath; } - if (TryReadInstallPath("Microsoft\\MSBuild\\ToolsVersions\\14.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\14.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath)) { return toolPath; } - if (TryReadInstallPath("Microsoft\\MSBuild\\ToolsVersions\\12.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\12.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath)) { return toolPath; } - if (TryReadInstallPath("Microsoft\\MSBuild\\ToolsVersions\\4.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\4.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath)) { return toolPath; } @@ -121,7 +121,7 @@ namespace Flax.Deploy } case TargetPlatform.Windows: { - if (TryReadInstallPath("Microsoft\\VisualStudio\\SxS\\VS7", "15.0", "MSBuild\\15.0\\bin\\csc.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\VisualStudio\\SxS\\VS7", "15.0", "MSBuild\\15.0\\bin\\csc.exe", out toolPath)) { return toolPath; } @@ -132,17 +132,17 @@ namespace Flax.Deploy return toolPath; } - if (TryReadInstallPath("Microsoft\\MSBuild\\ToolsVersions\\14.0", "MSBuildToolsPath", "csc.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\14.0", "MSBuildToolsPath", "csc.exe", out toolPath)) { return toolPath; } - if (TryReadInstallPath("Microsoft\\MSBuild\\ToolsVersions\\12.0", "MSBuildToolsPath", "csc.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\12.0", "MSBuildToolsPath", "csc.exe", out toolPath)) { return toolPath; } - if (TryReadInstallPath("Microsoft\\MSBuild\\ToolsVersions\\4.0", "MSBuildToolsPath", "csc.exe", out toolPath)) + if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\4.0", "MSBuildToolsPath", "csc.exe", out toolPath)) { return toolPath; } @@ -154,13 +154,9 @@ namespace Flax.Deploy return string.Empty; } - /// - /// Queries the registry entries for a certain install directory of the MsBuild. - /// - /// True if found MsBuild tool, otherwise false. - private static bool TryReadInstallPath(string keyRelativePath, string keyName, string msBuildRelativePath, out string outMsBuildPath) + private static bool CheckMsBuildPathFromRegistry(string keyRelativePath, string keyName, string msBuildRelativePath, out string outMsBuildPath) { - string[] keyBasePaths = + string[] prefixes = { @"HKEY_CURRENT_USER\SOFTWARE\", @"HKEY_LOCAL_MACHINE\SOFTWARE\", @@ -168,9 +164,9 @@ namespace Flax.Deploy @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\" }; - foreach (string keyBasePath in keyBasePaths) + for (var i = 0; i < prefixes.Length; i++) { - if (Registry.GetValue(keyBasePath + keyRelativePath, keyName, null) is string value) + if (Registry.GetValue(prefixes[i] + keyRelativePath, keyName, null) is string value) { string msBuildPath = Path.Combine(value, msBuildRelativePath); if (File.Exists(msBuildPath))