-
Notifications
You must be signed in to change notification settings - Fork 860
Fix constant buffer being stomped on by shadows during async tasks #4093
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
sebastienlagarde
merged 185 commits into
master
from
HDRP/fix-cb-being-stomped-with-async
Apr 29, 2021
Merged
Changes from 176 commits
Commits
Show all changes
185 commits
Select commit
Hold shift + click to select a range
b9da5fa
Hd/fix 1299116 tesselation cull (#3057)
kecho 5b57f64
Change the source value for the ray tracing frame index iterator from…
anisunity b21345b
[HDRP] Added a RenderGraph pass that resets the camera size after the…
9581f38
Fix Light Intensity UI Prefab Override Application (1299563) (#3061)
johnpars 525ebf5
Fix Undo/Redo Stability for Light Temperature (1304176, 1301076) (#3079)
johnpars 8007c48
Fix labels style (#3046)
adrien-de-tocqueville 2df0185
Fixed side effect on styles during compositor rendering. (#3081)
adrien-de-tocqueville bf833ce
[HDRP][Compositor] Fix size and spacing of compositor info boxes (#3101)
pmavridis 7be5e6c
[HDRP][Compositor] Fix color picker UI glitch in the Graphics Composi…
pmavridis 6413dc6
Fix 1299233 ies resize bug (#3094)
skhiat 8998567
filter for xbone addded (#3116)
martint-unity 027cb37
[Yamato] Enable cache server for standalone build jobs (#3106)
sophiaaar 6429445
Fix undo redo on layered lit editor (#3059)
adrien-de-tocqueville d910dc8
Merge branch 'master' into hd/bugfix
sebastienlagarde 9c216c8
[HDRP] Added Vulkan install in system requirements (#3122)
8dbde86
[HDRP] Fix issue with compositor related custom passes (#3055)
pmavridis a5a6590
Fixed some render texture leaks. (#3050)
JulienIgnace-Unity 229f3e8
Hd/fix wizard runtime resources (#3123)
RSlysz 0a42f9b
[HDRP] Fixed lookdev reload bug when viewing a scene object (#3108)
eb1d074
[HDRP] Fix error in Depth Of Field near radius blur calculation (#3131)
pmavridis 22b5b7f
[HDRP] Fix GC allocs (#3136)
pmavridis 8cd8fe6
Revert: Fix 1299233 ies resize bug (#3094)
sebastienlagarde 9bcb75f
Merge branch 'master' into hd/bugfix
sebastienlagarde 31defd2
Merge branch 'master' into hd/bugfix
sebastienlagarde 6dffbc8
Hide light shadow near plane gizmo when shadows are disabled (#3114)
adrien-de-tocqueville 9ba9620
Hd/fix backplate globalcubemap2 (#3111)
JulienIgnace-Unity b4214a4
[HDRP][Path Tracing] Added alpha channel to path traced results (#3127)
eturquin feb0fe0
Doc update (#3160)
JulienIgnace-Unity d315646
Merge branch 'master' into hd/bugfix
sebastienlagarde f9c97c1
Fix various shader warnings (#3158)
FrancescoC-unity 316d6a6
Update Override-Screen-Space-GI.md
sebastienlagarde be8f685
Fixed shadow matte not working with ambient occlusion when MSAA is en…
sebastienlagarde 44ba81f
Merge branch 'master' into hd/bugfix
sebastienlagarde 4de9b07
Update HDLightUI.cs (#3203)
sebastienlagarde 1557004
[HDRP] fix nullref when chaging RP from HDRP to URP (#3191)
acd6199
fix case 1307653 (#3205)
sebastienlagarde f18d053
Merge branch 'master' into hd/bugfix
sebastienlagarde abd7de7
Fix LookDev env library assignment after leaving playmode. (#3214)
JulienIgnace-Unity 6349ef2
Update Hair Shader Preset Documentation (#3208)
johnpars cace53e
[HDRP] Fix locale diffusion profile shader property value in ShaderGr…
760837b
Fix error in the RTHandle scale of Depth Of Field when TAA is enabled…
pmavridis 3f480bd
Reset to current quality settings after preprocess build in HDRP (#3218)
jenniferd-unity 4c7dfb6
Merge branch 'master' into hd/bugfix
sebastienlagarde 3b4b1fb
Have bilinear default (#3223)
FrancescoC-unity a890c49
Merge branch 'master' into hd/bugfix
sebastienlagarde 4477283
Update CHANGELOG.md
sebastienlagarde 3112950
Added missing character to the layered lit document (#3310)
JordanL8 ac55059
Fix needs of exposure for debug display "SSR Transparent" (#3308)
skhiat bc0aa7d
[HDRP] Fix GUI exception in material UI (#3315)
c34ba38
[HDRP] Update decal angle fade tooltip (#3322)
1f827f1
Mention in TAA doc that a certain use case will lead to problems. (#3…
FrancescoC-unity fe86016
Hide shadow resolution value (#3335)
adrien-de-tocqueville 7a6ec1e
Bump timer of 2nd runtime test to make it work on all platforms. (#3…
FrancescoC-unity b84c14b
Fix light frustum planes (#3341)
adrien-de-tocqueville 2cc4b51
Project skybox without perspective for ortho cameras (#2955)
adrien-de-tocqueville 1c9a0ff
Fix non temporal SSAO issues with the rendergraph pass (#3351)
FrancescoC-unity b648896
Merge branch 'master' into hd/bugfix
sebastienlagarde 4338bc4
Reset ambient probe upon switching to very different skies (#3340)
FrancescoC-unity 0c56c5f
Fix white flash on camera cuts with volumetric (#3354)
FrancescoC-unity 43e6d15
Fix issues with light layers issues when editing multiple lights (#3323)
FrancescoC-unity bd1934f
Maximum of reflection distance must be bound by the min of all dimens…
kecho e813067
Fixed debug panel reseting when going through enum items (#3370)
JulienIgnace-Unity 317f976
Fix keywords with fbx importer (#3350)
adrien-de-tocqueville b480510
Fixed lightmaps not working properly with shader graphs in ray traced…
anisunity ff57004
revert: Reset ambient probe upon switching to very different skies (#…
sebastienlagarde 8250779
Merge branch 'master' into hd/bugfix
sebastienlagarde f41f5cf
Hdrp/fix tesselation wireframe (#3355)
kecho ab6fc9e
Adding missing meta from HDRP_test
sebastienlagarde 0923df0
Hd/fix input registering domain reload (#3373)
RSlysz 14bb032
Merge branch 'master' into hd/bugfix
sebastienlagarde 53be5eb
Fix nullref (#3460)
adrien-de-tocqueville 5d7fb34
Merge branch 'master' into hd/bugfix
sebastienlagarde 7655f87
Fix DepthOfField CoC debug view (#3466)
FrancescoC-unity 890195a
Fixed an issue with first frame of ao causing some kind of ghosting e…
JulienIgnace-Unity 78864e9
Fix mipmap generation internal format (#3470)
pmavridis 4402cf2
Change wizard check to be ok with -force api (#3422)
FrancescoC-unity cac2a5a
Merge branch 'master' into hd/bugfix
sebastienlagarde 4ec6ec4
Delete Volumes.meta
sebastienlagarde 24fa85c
revert: Hd/fix input registering domain reload #3373
sebastienlagarde 9160de3
update Vulkan win reference screenshots
sebastienlagarde c11fb81
Merge branch 'master' into hd/bugfix
sebastienlagarde e1d44d1
Fixed performance issue with ShaderGraph and Alpha Test
sebastienlagarde b0aaf41
Fixed dimensionality of a couple vectors (from 3 to 2). (#3395)
eturquin 0ef72d6
Fix error when increasing the maximum planar reflection limit (#3332)
pmavridis 0818713
Updated documentation of RequestRenderNextUpdate (#3368)
fredericv-unity3d 3c893e8
Fix alpha output in AOVs and debug views when using shadow matte (#3593)
pmavridis 57b3f7d
Merge branch 'master' into hd/bugfix
sebastienlagarde 26d6266
Added an additional check in the "check scene for ray tracing" (case …
anisunity 1bf4e2e
Fixed an issue with transparent meshes writing their depths and recur…
anisunity be375de
Fixed issue with compositor custom pass hooks added/removed repeatedl…
pmavridis 28a5016
[HDRP] Fixed SSR with SSR_Transparent (#3603)
skhiat bf1a486
Decal in material debug display (#3608)
adrien-de-tocqueville c079e41
Merge branch 'master' into hd/bugfix
sebastienlagarde 2c5b4e0
Formatting
sebastienlagarde 309596a
Merge branch 'master' into hd/bugfix
sebastienlagarde 21de710
Hd/fix pivot size ratio percistency through 0 (#3600)
RSlysz bf444c8
[HDRP] Fix volume component nullref (#3644)
50c0900
Fixed decal normal for double sided materials (case 1312065) (#3610)
adrien-de-tocqueville e350783
Fixed render graph resource log to display properly MB and improved r…
JulienIgnace-Unity 4851240
Display a warning help box when decal atlas is out of size (#3634)
adrien-de-tocqueville b6496c1
Improved render texture debug names (#3631)
JulienIgnace-Unity 22b4a1d
Fixing ordering of UI Frame settings [Fogbugz 1315452] (#3628)
kecho 48444ab
Port change. (#3656)
FrancescoC-unity f736f8e
Fix issue with velocity rejection in post-DoF TAA (#3672)
pmavridis 559dada
Merge branch 'master' into hd/bugfix
sebastienlagarde dbe4d26
Unify Emissive mapping options on lit shaders (#3606)
adrien-de-tocqueville ac69980
Fix a leak cause for area light cookies (#3614)
FrancescoC-unity fa7e304
Update 5001_PathTracing.png
sebastienlagarde 50c0d12
Update 1202_Lit_DoubleSideNormalMode.unity
sebastienlagarde b3e21c9
Merge branch 'master' into hd/bugfix
sebastienlagarde 33f19f1
Hd/alpha to mask frame setting fix 1315452 (#3681)
victorsclui 88911cf
Hd/rough distortion fix 1317952 (#3683)
victorsclui d9d255e
Merge branch 'master' into hd/bugfix
sebastienlagarde 728f787
Merge branch 'master' into hd/bugfix
sebastienlagarde 8a68fd8
Fix issue with physically-based DoF computation and transparent mater…
pmavridis 5625ab7
Update RaytracingIntersection.hlsl (#3703)
sebastienlagarde 83fcb3e
Hd/fix access current hdrp asset for default frame settings 1317968 (…
victorsclui 50074ab
Fix SSGI frame setting not greyed out while SSGI is disabled in HDRP …
victorsclui c60ce53
Merge branch 'master' into hd/bugfix
sebastienlagarde 0bc80f9
Merge branch 'master' into hd/bugfix
sebastienlagarde a9b5a05
Reduced the maximal number of bounces for both RTGI and RTR (case 131…
anisunity 21f5a26
Fix scene being fully grey on playstation when histogram exposure is …
FrancescoC-unity 18dd20d
fix faulty lights (#3870)
FrancescoC-unity d04c299
Fixed indent level on material Global Illumination field (#3881)
a18c180
[HDRP] Disc light realtime gi UI error (#3866)
cf82a28
Merge branch 'master' into hd/bugfix
sebastienlagarde 741445b
Remove useless shaders from the creation menu (#3893)
e03af0d
Fixed HDRPAsset loosing its reference to the ray tracing resources wh…
anisunity 8a92aa8
Fixed error message when having MSAA and Screen Space Shadows (case 1…
anisunity cc57993
Fixed Nans happening in RTR when the history render target is bigger …
anisunity 86237d3
[HDRP] Fix tube light mode (#3871)
6961231
Added tooltips for features being disabled because of MSAA/Raytracing…
JulienIgnace-Unity f3bcec5
Formatting
sebastienlagarde 7c91669
Merge branch 'master' into hd/bugfix
sebastienlagarde 1988da2
Merge branch 'master' into hd/bugfix
sebastienlagarde 5a41070
Update CHANGELOG.md
sebastienlagarde b6c9a67
Changed the behavior of the clear coat and SSR/RTR for the stack lit …
anisunity b7f5bb5
Fix warning for ShadowLoop (#3885)
skhiat 1a0a200
Fix SSR for 4K Render Target (#3874)
skhiat 0da3bee
Fix GBuffer debug view when using virtual texturing (#3880)
FrancescoC-unity 52f065f
Bugfix 1319005: Fix fog noise issues (#3891)
JarkkoUnity b971409
Fix Decal Normal Blending NaN (Case #1317162) (#3883)
johnpars 6356cb4
Fixed issue in wizard when resource folder not exist (#3907)
RSlysz ee80b5b
Merge branch 'master' into hd/bugfix
sebastienlagarde 628f581
Merge branch 'master' into hd/bugfix
sebastienlagarde d5dda1b
Fix for Xbox device types in SubSurfaceScattering (#3942)
Adrian1066 6c7f87f
Fixed issue with Decal projector edge on Metal (case 1286074) (#3941)
sebastienlagarde 892a756
Fix normal and update ref images. (#3928)
eturquin e803d7b
Fix diffusion profile doc (#3968)
f09f1cf
Fixed a potential issue causing the custom pass UI drawers to not ren…
74e7eea
Merge branch 'master' into hd/bugfix
sebastienlagarde 103cb69
Merge branch 'master' into hd/bugfix
sebastienlagarde 58db1d1
Moved the leaf example from sss to translucent (#3990)
JordanL8 e14c018
Merge branch 'master' into hd/bugfix
sebastienlagarde 6c9d933
Merge branch 'master' into hd/bugfix
sebastienlagarde 673eee8
Added rough distortion to the frame settings (#3991)
JordanL8 3b40bff
Fix Render Graph UI bug in Render Pipeline Debugger (#3992)
johnpars b6fc493
Fixed formatting issue and reworded some bits in the motion vectors p…
JordanL8 32230ac
Added a fallback for the ray traced directional shadow in case of a t…
anisunity 3336a3b
Fix sss in planar reflections planar (#3919)
adrien-de-tocqueville 9f5b16d
Added note about SSGI and RTGI replacing all lightmap and light probe…
JordanL8 875bb24
fix pivot edit mode 2D slider gizmo not supporting multi-edition (dec…
RSlysz ba68adb
Merge branch 'master' into hd/bugfix
sebastienlagarde 0013360
Merge branch 'master' into hd/bugfix
sebastienlagarde a492490
Merge branch 'master' into hd/bugfix
sebastienlagarde 9d7be90
Merge branch 'master' into hd/bugfix
sebastienlagarde f423b2c
[HDRP][Fogbugz 1325312] Hdrp/fix inverted y on cas (#4027)
kecho b1025c9
SceneObjectIDMap: Fix a nasty bug where game object to entry index di…
sebastienlagarde b48ff19
Merge branch 'master' into hd/bugfix
sebastienlagarde 89e9e5d
Fix shader compil issue on PS4 in Stacklit.hlsl (#4064)
sebastienlagarde e87e4dd
[Fogbugz 1325700] Fixing volumetric screen zmask & depth pyramid for …
kecho 04c1695
Update StackLit.hlsl
sebastienlagarde 5fcec3b
Merge branch 'master' into hd/bugfix
sebastienlagarde 2d39d4f
HD/Decals: allows negative UV (#4083)
RSlysz 68d3e6c
Add new CB API and refactor a bit of shadow init
FrancescoC-unity 0141dcb
Changelog
FrancescoC-unity 7fc5bd3
Merge branch 'master' into HDRP/fix-cb-being-stomped-with-async
sebastienlagarde 200e7f4
Fix typos
FrancescoC-unity bf34a1d
Fixes
FrancescoC-unity 00f0b8d
Use new API
FrancescoC-unity e806f03
Fix GCAlloc
FrancescoC-unity c2b705d
Merge branch 'master' into HDRP/fix-cb-being-stomped-with-async [NEED…
FrancescoC-unity 424e199
Fix issue post merge
FrancescoC-unity ee71700
Fix formatting issue
FrancescoC-unity 3f4a51c
Merge branch 'master' into HDRP/fix-cb-being-stomped-with-async
sebastienlagarde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ public class ConstantBuffer | |
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public static void PushGlobal<CBType>(CommandBuffer cmd, in CBType data, int shaderId) where CBType : struct | ||
| { | ||
| var cb = TypedConstantBuffer<CBType>.instance; | ||
| var cb = ConstantBufferSingleton<CBType>.instance; | ||
|
|
||
| cb.UpdateData(cmd, data); | ||
| cb.SetGlobal(cmd, shaderId); | ||
|
|
@@ -35,7 +35,7 @@ public static void PushGlobal<CBType>(CommandBuffer cmd, in CBType data, int sha | |
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public static void Push<CBType>(CommandBuffer cmd, in CBType data, ComputeShader cs, int shaderId) where CBType : struct | ||
| { | ||
| var cb = TypedConstantBuffer<CBType>.instance; | ||
| var cb = ConstantBufferSingleton<CBType>.instance; | ||
|
|
||
| cb.UpdateData(cmd, data); | ||
| cb.Set(cmd, cs, shaderId); | ||
|
|
@@ -51,7 +51,7 @@ public static void Push<CBType>(CommandBuffer cmd, in CBType data, ComputeShader | |
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public static void Push<CBType>(CommandBuffer cmd, in CBType data, Material mat, int shaderId) where CBType : struct | ||
| { | ||
| var cb = TypedConstantBuffer<CBType>.instance; | ||
| var cb = ConstantBufferSingleton<CBType>.instance; | ||
|
|
||
| cb.UpdateData(cmd, data); | ||
| cb.Set(mat, shaderId); | ||
|
|
@@ -65,7 +65,7 @@ public static void Push<CBType>(CommandBuffer cmd, in CBType data, Material mat, | |
| /// <param name="data">Input data of the constant buffer.</param> | ||
| public static void UpdateData<CBType>(CommandBuffer cmd, in CBType data) where CBType : struct | ||
| { | ||
| var cb = TypedConstantBuffer<CBType>.instance; | ||
| var cb = ConstantBufferSingleton<CBType>.instance; | ||
|
|
||
| cb.UpdateData(cmd, data); | ||
| } | ||
|
|
@@ -78,7 +78,7 @@ public static void UpdateData<CBType>(CommandBuffer cmd, in CBType data) where C | |
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public static void SetGlobal<CBType>(CommandBuffer cmd, int shaderId) where CBType : struct | ||
| { | ||
| var cb = TypedConstantBuffer<CBType>.instance; | ||
| var cb = ConstantBufferSingleton<CBType>.instance; | ||
|
|
||
| cb.SetGlobal(cmd, shaderId); | ||
| } | ||
|
|
@@ -92,7 +92,7 @@ public static void SetGlobal<CBType>(CommandBuffer cmd, int shaderId) where CBTy | |
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public static void Set<CBType>(CommandBuffer cmd, ComputeShader cs, int shaderId) where CBType : struct | ||
| { | ||
| var cb = TypedConstantBuffer<CBType>.instance; | ||
| var cb = ConstantBufferSingleton<CBType>.instance; | ||
|
|
||
| cb.Set(cmd, cs, shaderId); | ||
| } | ||
|
|
@@ -105,14 +105,14 @@ public static void Set<CBType>(CommandBuffer cmd, ComputeShader cs, int shaderId | |
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public static void Set<CBType>(Material mat, int shaderId) where CBType : struct | ||
| { | ||
| var cb = TypedConstantBuffer<CBType>.instance; | ||
| var cb = ConstantBufferSingleton<CBType>.instance; | ||
|
|
||
| cb.Set(mat, shaderId); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Release all currently allocated constant buffers. | ||
| /// This needs to be called before shutting down the application. | ||
| /// This needs to be called before shutting down the application. | ||
JulienIgnace-Unity marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// </summary> | ||
| public static void ReleaseAll() | ||
| { | ||
|
|
@@ -122,86 +122,134 @@ public static void ReleaseAll() | |
| m_RegisteredConstantBuffers.Clear(); | ||
| } | ||
|
|
||
| internal abstract class ConstantBufferBase | ||
| { | ||
| public abstract void Release(); | ||
| } | ||
|
|
||
| internal static void Register(ConstantBufferBase cb) | ||
| { | ||
| m_RegisteredConstantBuffers.Add(cb); | ||
| } | ||
|
|
||
| class TypedConstantBuffer<CBType> : ConstantBufferBase where CBType : struct | ||
| { | ||
| // Used to track all global bindings used by this CB type. | ||
| HashSet<int> m_GlobalBindings = new HashSet<int>(); | ||
| // Array is required by the ComputeBuffer SetData API | ||
| CBType[] m_Data = new CBType[1]; | ||
| } | ||
|
|
||
| static TypedConstantBuffer<CBType> s_Instance = null; | ||
| internal static TypedConstantBuffer<CBType> instance | ||
| { | ||
| get | ||
| { | ||
| if (s_Instance == null) | ||
| s_Instance = new TypedConstantBuffer<CBType>(); | ||
| return s_Instance; | ||
| } | ||
| set | ||
| { | ||
| s_Instance = value; | ||
| } | ||
| } | ||
| ComputeBuffer m_GPUConstantBuffer = null; | ||
| /// <summary> | ||
| /// The base class of Constant Buffer. | ||
| /// </summary> | ||
| public abstract class ConstantBufferBase | ||
| { | ||
| /// <summary> | ||
| /// Release the constant buffer. | ||
| /// </summary> | ||
| public abstract void Release(); | ||
| } | ||
|
|
||
| TypedConstantBuffer() | ||
| { | ||
| m_GPUConstantBuffer = new ComputeBuffer(1, UnsafeUtility.SizeOf<CBType>(), ComputeBufferType.Constant); | ||
| ConstantBuffer.Register(this); | ||
| } | ||
|
|
||
| public void UpdateData(CommandBuffer cmd, in CBType data) | ||
| { | ||
| m_Data[0] = data; | ||
| /// <summary> | ||
| /// An instance of a constant buffer. | ||
| /// </summary> | ||
| /// <typeparam name="CBType">The type of structure representing the constant buffer data.</typeparam> | ||
| public class ConstantBuffer<CBType> : ConstantBufferBase where CBType : struct | ||
| { | ||
| // Used to track all global bindings used by this CB type. | ||
| HashSet<int> m_GlobalBindings = new HashSet<int>(); | ||
| // Array is required by the ComputeBuffer SetData API | ||
| CBType[] m_Data = new CBType[1]; | ||
|
|
||
|
|
||
| ComputeBuffer m_GPUConstantBuffer = null; | ||
|
|
||
| /// <summary> | ||
| /// Constant Buffer constructor. | ||
| /// </summary> | ||
| public ConstantBuffer() | ||
| { | ||
| m_GPUConstantBuffer = new ComputeBuffer(1, UnsafeUtility.SizeOf<CBType>(), ComputeBufferType.Constant); | ||
| ConstantBuffer.Register(this); | ||
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Update the GPU data of the constant buffer. | ||
| /// </summary> | ||
| /// <param name="cmd">Command Buffer used to execute the graphic commands.</param> | ||
| /// <param name="data">Input data of the constant buffer.</param> | ||
| public void UpdateData(CommandBuffer cmd, in CBType data) | ||
| { | ||
| m_Data[0] = data; | ||
| #if UNITY_2021_1_OR_NEWER | ||
| cmd.SetBufferData(m_GPUConstantBuffer, m_Data); | ||
| cmd.SetBufferData(m_GPUConstantBuffer, m_Data); | ||
| #else | ||
| cmd.SetComputeBufferData(m_GPUConstantBuffer, m_Data); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| public void SetGlobal(CommandBuffer cmd, int shaderId) | ||
| { | ||
| m_GlobalBindings.Add(shaderId); | ||
| cmd.SetGlobalConstantBuffer(m_GPUConstantBuffer, shaderId, 0, m_GPUConstantBuffer.stride); | ||
| } | ||
| /// <summary> | ||
| /// Bind the constant buffer globally. | ||
| /// </summary> | ||
| /// <param name="cmd">Command Buffer used to execute the graphic commands.</param> | ||
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public void SetGlobal(CommandBuffer cmd, int shaderId) | ||
| { | ||
| m_GlobalBindings.Add(shaderId); | ||
| cmd.SetGlobalConstantBuffer(m_GPUConstantBuffer, shaderId, 0, m_GPUConstantBuffer.stride); | ||
| } | ||
|
|
||
| public void Set(CommandBuffer cmd, ComputeShader cs, int shaderId) | ||
| { | ||
| cmd.SetComputeConstantBufferParam(cs, shaderId, m_GPUConstantBuffer, 0, m_GPUConstantBuffer.stride); | ||
| } | ||
| /// <summary> | ||
| /// Bind the constant buffer to a compute shader. | ||
| /// </summary> | ||
| /// <param name="cmd">Command Buffer used to execute the graphic commands.</param> | ||
| /// <param name="cs">Compute shader to which the constant buffer should be bound.</param> | ||
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public void Set(CommandBuffer cmd, ComputeShader cs, int shaderId) | ||
| { | ||
| cmd.SetComputeConstantBufferParam(cs, shaderId, m_GPUConstantBuffer, 0, m_GPUConstantBuffer.stride); | ||
| } | ||
|
|
||
| public void Set(Material mat, int shaderId) | ||
| /// <summary> | ||
| /// Bind the constant buffer to a material. | ||
| /// </summary> | ||
| /// <param name="mat">Material to which the constant buffer should be bound.</param> | ||
| /// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param> | ||
| public void Set(Material mat, int shaderId) | ||
| { | ||
| // This isn't done via command buffer because as long as the buffer itself is not destroyed, | ||
| // the binding stays valid. Only the commit of data needs to go through the command buffer. | ||
| // We do it here anyway for now to simplify user API. | ||
| mat.SetConstantBuffer(shaderId, m_GPUConstantBuffer, 0, m_GPUConstantBuffer.stride); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Release the constant buffers. | ||
| /// </summary> | ||
| public override void Release() | ||
| { | ||
| // Depending on the device, globally bound buffers can leave stale "valid" shader ids pointing to a destroyed buffer. | ||
| // In DX11 it does not cause issues but on Vulkan this will result in skipped drawcalls (even if the buffer is not actually accessed in the shader). | ||
| // To avoid this kind of issues, it's good practice to "unbind" all globally bound buffers upon destruction. | ||
| foreach (int shaderId in m_GlobalBindings) | ||
| Shader.SetGlobalConstantBuffer(shaderId, (ComputeBuffer)null, 0, 0); | ||
| m_GlobalBindings.Clear(); | ||
|
|
||
| CoreUtils.SafeRelease(m_GPUConstantBuffer); | ||
| } | ||
| } | ||
|
|
||
| class ConstantBufferSingleton<CBType> : ConstantBuffer<CBType> where CBType : struct | ||
| { | ||
| static ConstantBufferSingleton<CBType> s_Instance = null; | ||
| internal static ConstantBufferSingleton<CBType> instance | ||
| { | ||
| get | ||
| { | ||
| // This isn't done via command buffer because as long as the buffer itself is not destroyed, | ||
| // the binding stays valid. Only the commit of data needs to go through the command buffer. | ||
| // We do it here anyway for now to simplify user API. | ||
| mat.SetConstantBuffer(shaderId, m_GPUConstantBuffer, 0, m_GPUConstantBuffer.stride); | ||
| if (s_Instance == null) | ||
| s_Instance = new ConstantBufferSingleton<CBType>(); | ||
| return s_Instance; | ||
| } | ||
|
|
||
| public override void Release() | ||
| set | ||
| { | ||
| // Depending on the device, globally bound buffers can leave stale "valid" shader ids pointing to a destroyed buffer. | ||
| // In DX11 it does not cause issues but on Vulkan this will result in skipped drawcalls (even if the buffer is not actually accessed in the shader). | ||
| // To avoid this kind of issues, it's good practice to "unbind" all globally bound buffers upon destruction. | ||
| foreach (int shaderId in m_GlobalBindings) | ||
| Shader.SetGlobalConstantBuffer(shaderId, (ComputeBuffer)null, 0, 0); | ||
| m_GlobalBindings.Clear(); | ||
|
|
||
| CoreUtils.SafeRelease(m_GPUConstantBuffer); | ||
| s_Instance = null; | ||
| s_Instance = value; | ||
| } | ||
| } | ||
|
|
||
| public override void Release() | ||
| { | ||
| s_Instance = null; | ||
JulienIgnace-Unity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding the PushGlobal version to regular CBs as well for consistency.