From bc39d56981292ae50fad31623d4109c8573a8bd3 Mon Sep 17 00:00:00 2001 From: "xingwei.zhu" Date: Mon, 21 Oct 2019 12:23:54 +0800 Subject: [PATCH 1/3] add configs for user to disable some features in their app usecase: in Editor app, the RasterCache may should be disabled to avoid Engine errors when the RenderTexture is too big --- Runtime/editor/window_config.cs | 29 +++++++++++++++++++ .../rendering/canvas_shader_initializer.cs | 5 ++-- .../compositeCanvas/flow/raster_cache.cs | 10 +++++++ Runtime/ui/window.cs | 4 ++- Samples/UIWidgetsGallery/GalleryMain.cs | 1 - 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 Runtime/editor/window_config.cs diff --git a/Runtime/editor/window_config.cs b/Runtime/editor/window_config.cs new file mode 100644 index 00000000..7dda42c2 --- /dev/null +++ b/Runtime/editor/window_config.cs @@ -0,0 +1,29 @@ +using Unity.UIWidgets.foundation; + +namespace Unity.UIWidgets.editor { + public class WindowConfig { + public readonly bool disableRasterCache; + + static bool? _disableComputeBuffer = null; + + public static bool disableComputeBuffer { + //disable compute buffer by default for now + get { return _disableComputeBuffer ?? true; } + set { + D.assert(_disableComputeBuffer == null + || _disableComputeBuffer == value + , () => "The global settings of [disableComputeBuffer] cannot be initiated for multiple times!"); + + _disableComputeBuffer = value; + } + } + + public WindowConfig(bool disableRasterCache) { + this.disableRasterCache = disableRasterCache; + } + + public static readonly WindowConfig defaultConfig = new WindowConfig( + disableRasterCache: false + ); + } +} \ No newline at end of file diff --git a/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader_initializer.cs b/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader_initializer.cs index f524c9ac..c124160d 100644 --- a/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader_initializer.cs +++ b/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader_initializer.cs @@ -1,10 +1,9 @@ +using Unity.UIWidgets.editor; using UnityEngine; using UnityEngine.Rendering; namespace Unity.UIWidgets.ui { static partial class CanvasShader { - const bool enableComputeBuffer = false; - const bool enableDebugLog = false; public static bool supportComputeBuffer; @@ -22,7 +21,7 @@ static bool IsShaderSupported() { } static void InitShaders() { - supportComputeBuffer = enableComputeBuffer && SystemInfo.supportsComputeShaders && IsShaderSupported(); + supportComputeBuffer = !WindowConfig.disableComputeBuffer && SystemInfo.supportsComputeShaders && IsShaderSupported(); if (!supportComputeBuffer) { DebugAssert(false, "init default shaders"); diff --git a/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs b/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs index 470e7b2c..29f82e5d 100644 --- a/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs +++ b/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs @@ -210,6 +210,10 @@ static bool _canRasterizePicture(Picture picture) { return false; } + if (Window.instance.windowConfig.disableRasterCache) { + return false; + } + var bounds = picture.paintBounds; if (bounds.isEmpty) { return false; @@ -223,6 +227,12 @@ static bool _canRasterizePicture(Picture picture) { return false; } + //https://forum.unity.com/threads/rendertexture-create-failed-rendertexture-too-big.58667/ + if (picture.paintBounds.size.width > 4096 || + picture.paintBounds.size.height > 4096) { + return false; + } + return true; } diff --git a/Runtime/ui/window.cs b/Runtime/ui/window.cs index 3a19242a..f9721448 100644 --- a/Runtime/ui/window.cs +++ b/Runtime/ui/window.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Unity.UIWidgets.async; +using Unity.UIWidgets.editor; using Unity.UIWidgets.foundation; using UnityEngine; @@ -148,11 +149,12 @@ public int antiAliasing { protected int _antiAliasing = defaultAntiAliasing; - public Size physicalSize { get { return this._physicalSize; } } + public WindowConfig windowConfig = WindowConfig.defaultConfig; + protected Size _physicalSize = Size.zero; public WindowPadding viewInsets { diff --git a/Samples/UIWidgetsGallery/GalleryMain.cs b/Samples/UIWidgetsGallery/GalleryMain.cs index 609a92f0..903da1ae 100644 --- a/Samples/UIWidgetsGallery/GalleryMain.cs +++ b/Samples/UIWidgetsGallery/GalleryMain.cs @@ -1,6 +1,5 @@ using UIWidgetsGallery.gallery; using Unity.UIWidgets.engine; -using Unity.UIWidgets.material; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; using UnityEngine; From 756267e382c1024e8eea63e2427139e036eae06e Mon Sep 17 00:00:00 2001 From: "xingwei.zhu" Date: Mon, 21 Oct 2019 12:24:08 +0800 Subject: [PATCH 2/3] add meta --- Runtime/editor/window_config.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Runtime/editor/window_config.cs.meta diff --git a/Runtime/editor/window_config.cs.meta b/Runtime/editor/window_config.cs.meta new file mode 100644 index 00000000..63eff8de --- /dev/null +++ b/Runtime/editor/window_config.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b07028e6b697b43e4a5911da0ab9ca54 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From ba90df23598f450d0f84067ba70a183f4493457a Mon Sep 17 00:00:00 2001 From: "xingwei.zhu" Date: Mon, 21 Oct 2019 12:26:06 +0800 Subject: [PATCH 3/3] make the maxRasterImage size configurable --- Runtime/editor/window_config.cs | 2 ++ Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Runtime/editor/window_config.cs b/Runtime/editor/window_config.cs index 7dda42c2..609d1d57 100644 --- a/Runtime/editor/window_config.cs +++ b/Runtime/editor/window_config.cs @@ -4,6 +4,8 @@ namespace Unity.UIWidgets.editor { public class WindowConfig { public readonly bool disableRasterCache; + public static float MaxRasterImageSize = 4096; + static bool? _disableComputeBuffer = null; public static bool disableComputeBuffer { diff --git a/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs b/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs index 29f82e5d..be847149 100644 --- a/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs +++ b/Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Unity.UIWidgets.editor; using Unity.UIWidgets.foundation; using Unity.UIWidgets.ui; using UnityEngine; @@ -228,8 +229,8 @@ static bool _canRasterizePicture(Picture picture) { } //https://forum.unity.com/threads/rendertexture-create-failed-rendertexture-too-big.58667/ - if (picture.paintBounds.size.width > 4096 || - picture.paintBounds.size.height > 4096) { + if (picture.paintBounds.size.width > WindowConfig.MaxRasterImageSize || + picture.paintBounds.size.height > WindowConfig.MaxRasterImageSize) { return false; }