|
1 | 1 | using System;
|
| 2 | +using System.Diagnostics; |
2 | 3 | using UnityEngine.Rendering.RenderGraphModule;
|
3 | 4 |
|
4 | 5 | namespace UnityEngine.Rendering
|
@@ -26,79 +27,83 @@ internal BaseCommandBuffer(CommandBuffer wrapped, RenderGraphPass executingPass,
|
26 | 27 | ///<summary>See (https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer-sizeInBytes.html)</summary>
|
27 | 28 | public int sizeInBytes => m_WrappedCommandBuffer.sizeInBytes;
|
28 | 29 |
|
| 30 | + [Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")] |
29 | 31 | internal protected void ThrowIfGlobalStateNotAllowed()
|
30 | 32 | {
|
31 |
| -#if DEVELOPMENT_BUILD || UNITY_EDITOR |
32 | 33 | if (m_ExecutingPass != null && !m_ExecutingPass.allowGlobalState) throw new InvalidOperationException($"{m_ExecutingPass.name}: Modifying global state from this command buffer is not allowed. Please ensure your render graph pass allows modifying global state.");
|
33 |
| -#endif |
34 | 34 | }
|
35 | 35 |
|
36 | 36 | /// <summary>
|
37 | 37 | /// Checks if the Raster Command Buffer has set a valid render target.
|
38 | 38 | /// </summary>
|
39 | 39 | /// <exception cref="InvalidOperationException">Thrown if the there are no active render targets.</exception>
|
| 40 | + [Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")] |
40 | 41 | internal protected void ThrowIfRasterNotAllowed()
|
41 | 42 | {
|
42 |
| -#if DEVELOPMENT_BUILD || UNITY_EDITOR |
43 | 43 | if (m_ExecutingPass != null && !m_ExecutingPass.HasRenderAttachments()) throw new InvalidOperationException($"{m_ExecutingPass.name}: Using raster commands from a pass with no active render targets is not allowed as it will use an undefined render target state. Please set-up the pass's render targets using SetRenderAttachments.");
|
44 |
| -#endif |
45 | 44 | }
|
46 | 45 |
|
47 | 46 |
|
48 | 47 | // Validation when it is unknown if the texture will be read or written
|
| 48 | + [Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")] |
49 | 49 | internal protected void ValidateTextureHandle(TextureHandle h)
|
50 | 50 | {
|
51 |
| -#if DEVELOPMENT_BUILD || UNITY_EDITOR |
52 |
| - if (m_ExecutingPass == null) return; |
| 51 | + if(RenderGraph.enableValidityChecks) |
| 52 | + { |
| 53 | + if (m_ExecutingPass == null) return; |
53 | 54 |
|
54 |
| - if (h.IsBuiltin()) return; |
| 55 | + if (h.IsBuiltin()) return; |
55 | 56 |
|
56 |
| - if (!m_ExecutingPass.IsRead(h.handle) && !m_ExecutingPass.IsWritten(h.handle)) |
57 |
| - { |
58 |
| - throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to use a texture on the command buffer that was never registered with the pass builder. Please indicate the texture use to the pass builder."); |
59 |
| - } |
60 |
| - if (m_ExecutingPass.IsAttachment(h)) |
61 |
| - { |
62 |
| - throw new Exception("Pass '" + m_ExecutingPass.name + "' is using a texture as a fragment attachment (SetRenderAttachment/SetRenderAttachmentDepth) but is also trying to bind it as regular texture. Please fix this pass. "); |
| 57 | + if (!m_ExecutingPass.IsRead(h.handle) && !m_ExecutingPass.IsWritten(h.handle)) |
| 58 | + { |
| 59 | + throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to use a texture on the command buffer that was never registered with the pass builder. Please indicate the texture use to the pass builder."); |
| 60 | + } |
| 61 | + if (m_ExecutingPass.IsAttachment(h)) |
| 62 | + { |
| 63 | + throw new Exception("Pass '" + m_ExecutingPass.name + "' is using a texture as a fragment attachment (SetRenderAttachment/SetRenderAttachmentDepth) but is also trying to bind it as regular texture. Please fix this pass. "); |
| 64 | + } |
63 | 65 | }
|
64 |
| -#endif |
65 | 66 | }
|
66 | 67 |
|
| 68 | + [Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")] |
67 | 69 | internal protected void ValidateTextureHandleRead(TextureHandle h)
|
68 | 70 | {
|
69 |
| -#if DEVELOPMENT_BUILD || UNITY_EDITOR |
70 |
| - if (m_ExecutingPass == null) return; |
71 |
| - |
72 |
| - if (!m_ExecutingPass.IsRead(h.handle)) |
73 |
| - { |
74 |
| - throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to read a texture on the command buffer that was never registered with the pass builder. Please indicate the texture as read to the pass builder."); |
75 |
| - } |
76 |
| - if (m_ExecutingPass.IsAttachment(h)) |
| 71 | + if(RenderGraph.enableValidityChecks) |
77 | 72 | {
|
78 |
| - throw new Exception("Pass '" + m_ExecutingPass.name + "' is using a texture as a fragment attachment (SetRenderAttachment/SetRenderAttachmentDepth) but is also trying to bind it as regular texture. Please fix this pass. "); |
| 73 | + if (m_ExecutingPass == null) return; |
| 74 | + |
| 75 | + if (!m_ExecutingPass.IsRead(h.handle)) |
| 76 | + { |
| 77 | + throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to read a texture on the command buffer that was never registered with the pass builder. Please indicate the texture as read to the pass builder."); |
| 78 | + } |
| 79 | + if (m_ExecutingPass.IsAttachment(h)) |
| 80 | + { |
| 81 | + throw new Exception("Pass '" + m_ExecutingPass.name + "' is using a texture as a fragment attachment (SetRenderAttachment/SetRenderAttachmentDepth) but is also trying to bind it as regular texture. Please fix this pass. "); |
| 82 | + } |
79 | 83 | }
|
80 |
| -#endif |
81 | 84 | }
|
82 | 85 |
|
| 86 | + [Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")] |
83 | 87 | internal protected void ValidateTextureHandleWrite(TextureHandle h)
|
84 | 88 | {
|
85 |
| -#if DEVELOPMENT_BUILD || UNITY_EDITOR |
86 |
| - if (m_ExecutingPass == null) return; |
87 |
| - |
88 |
| - if (h.IsBuiltin()) |
| 89 | + if(RenderGraph.enableValidityChecks) |
89 | 90 | {
|
90 |
| - throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to write to a built-in texture. This is not allowed built-in textures are small default resources like `white` or `black` that cannot be written to."); |
91 |
| - } |
| 91 | + if (m_ExecutingPass == null) return; |
92 | 92 |
|
93 |
| - if (!m_ExecutingPass.IsWritten(h.handle)) |
94 |
| - { |
95 |
| - throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to write a texture on the command buffer that was never registered with the pass builder. Please indicate the texture as written to the pass builder."); |
96 |
| - } |
97 |
| - if (m_ExecutingPass.IsAttachment(h)) |
98 |
| - { |
99 |
| - throw new Exception("Pass '" + m_ExecutingPass.name + "' is using a texture as a fragment attachment (SetRenderAttachment/SetRenderAttachmentDepth) but is also trying to bind it as regular texture. Please fix this pass. "); |
| 93 | + if (h.IsBuiltin()) |
| 94 | + { |
| 95 | + throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to write to a built-in texture. This is not allowed built-in textures are small default resources like `white` or `black` that cannot be written to."); |
| 96 | + } |
| 97 | + |
| 98 | + if (!m_ExecutingPass.IsWritten(h.handle)) |
| 99 | + { |
| 100 | + throw new Exception("Pass '" + m_ExecutingPass.name + "' is trying to write a texture on the command buffer that was never registered with the pass builder. Please indicate the texture as written to the pass builder."); |
| 101 | + } |
| 102 | + if (m_ExecutingPass.IsAttachment(h)) |
| 103 | + { |
| 104 | + throw new Exception("Pass '" + m_ExecutingPass.name + "' is using a texture as a fragment attachment (SetRenderAttachment/SetRenderAttachmentDepth) but is also trying to bind it as regular texture. Please fix this pass. "); |
| 105 | + } |
100 | 106 | }
|
101 |
| -#endif |
102 | 107 | }
|
103 | 108 | }
|
104 | 109 | }
|
0 commit comments