Will changing from Gamma space to Linear space cause performance degradation?

1) Will changing from Gamma space to Linear space cause performance degradation?
2) How to deal with receiving warnings from the GooglePlay platform without using Unity Ads?
3) How to deal with xLua’s infinite loop when executing DoString on the C# side?
4) Texture2DArray related


This is the 350th UWA technical knowledge sharing push. It selects hot topics in the UWA community and covers UWA Q&A, community posts and other technical knowledge points to help everyone master and learn more comprehensively.

Rendering

Q: Is Linear performance worse than Gamma? Our project has been using Unity 2020.2.7f1 version before, and chose Gamma. Currently upgraded to 2021.3.21f1, switched to Linear space, Shader and pictures have been modified, and performance has been optimized.

However, the overall test performance is not as good as the previous Gamma. The frame rate is not as high as before, and the frame rate drops a lot. After optimization, it is still not satisfactory. It always feels stuck. I wonder if it is the reason for upgrading from Gamma to Linear?

A1: It should have nothing to do with changing the color space. If there are no special functions, the main difference between Gamma and Linear is whether to perform color correction when finally outputting to the monitor. According to your description, it should be related to modifying the Shader.

Thanks to Li Wei @UWA Q&A Community for providing the answer

A2: On hardware-supported devices, there should be no significant performance differences.

When the hardware does not support it (such as OpenGL ES 2.0), if the Linear Space effect is implemented based on the simulation conversion in the Shader, there will be a certain amount of GPU consumption. However, if you feel that it is stuck rather than a sustained low frame rate, that is not the case. It is recommended to start with the specific performance Profile data to investigate.

There is a related discussion here. Search for the performance keyword to see experiments done by some people:
Gamma vs Linear Space - Unity Forum

部分结论引用如下:
“I have just done a stress test of Gamma vs Linear color spaces with transparencies and Gamma is indeed a liiiitle faster than Linear, but the difference is so minimal it doesn't even matter. (2 to 3 frames per second more on a stress test that was overdrawing 8 transparent planes one over the other for the full screen space.)


On any GPU that handles GLES3 there is no performance reason to use Gamma space over Linear.

Gamma space is legacy now and is only useful for legacy GLES2 GPUs (because linear requires GLES3)”

Different game test results may be slightly different, but in principle there should be no observable performance difference. The questioner can refer to it.

Thanks to Jia Weihao@UWA Q&A Community for providing the answer


Script

Q: I don’t use Unity Ads, but I still receive a warning from the Google Play platform:

Your "xxxxxxx" app (version code: 8) contains the "com.unity3d.ads:unity-ads" SDK or an SDK that one of your code bases relies on, which collects personal or sensitive data, including But it may not be limited to Advertising ID, Android ID identifier. Per the User Data Policy, apps may not associate persistent device identifiers with other personal data, sensitive user data, or resettable device identifiers.

As of midnight Coordinated Universal Time (UTC) on January 11, 2023, new app versions may not be released if they contain an SDK version and do not comply with the user data policy. You may consider upgrading the SDK to a compliant version of the SDK that does not contain the violating code (if available), or removing the SDK from your app.

Depending on your SDK provider, you may consider upgrading to 4.0.1 and/or contact your SDK provider to see if a suitable later version is available. Google cannot recommend or provide any endorsement of any third-party software.

A1: It is recommended to check the reference of SystemInfo.

Thanks to Knight-132872@UWA Q&A Community for providing the answer

A2: Provide some ideas:
1. Confirm whether there is com.unity.ads package under Package
2. If you are using the Chinese version of Unity, you can switch to the following version or the international version of the same version

Thanks to bo@UWA Q&A community for providing the answer

A3: For personal testing, just use the corresponding international version. After unpacking, I found that the Chinese version will contain Ads content in the package regardless of whether Ads is imported or not. The international version does not have this problem. I submitted it to Google Store for verification today.

After unpacking, in the splash folder in the smali\com\unity3d directory, you must first remove Ads in the project, and then package and test. I tested with 2020.3.38f1 and 2018.4.36f1 and there was no problem.

Thanks to TimWang@UWA Q&A community for providing the answer


Script

Q: I use xLua as the game's embedded scripting language, allowing players to customize scripts.

Now a player has written an infinite loop in the script. When I use DoString to load the script, it will get stuck directly, so I added a Task outside:

var isSucceed = false;
var task = Task.Run(() => { 
isSucceed = sandbox.DoString(xxxx)//这里简化一下.核心就是加载这个脚本执行DoString
});

bool isCompletedSuccessfully = task.Wait(TimeSpan.FromMilliseconds(1500)); //1.5s timeout

if (!isCompletedSuccessfully)
{
    CELog.LogError("加载脚本超时");
    isSucceed = false;

    luaEnv.Dispose(); //Kill掉当前的Evn


    return; //不再加载后续脚本
}

Now the editor will crash immediately as long as 'luaEnv.Dispose()' is called, whether the call is timed out or after a few seconds.

I feel it's because Task's Timeout only calls back after timeout, but Lua is still in deadlock at this time, so I can't Dispose.

The official FAQ mentions:

Calling LuaEnv.Dispose crashes. It is very likely that the Dispose operation is executed by the Lua driver, which is equivalent to releasing the Lua virtual machine during the execution of Lua and changing it to be executed only by C#.

I feel the same situation as mine, how should I deal with it?

A: Update the progress of the current research:

This is the result of asking for advice from xLua, which currently meets my own needs:
How to deal with the infinite loop in C# when xlua DoString · Issue #1077 · Tencent/xLua · GitHub

If the above methods are not satisfactory, you can also If you can't figure out the bottom layer, you can try the following directions:

MoonSharp
MoonSharp

MoonSharp is Lua written purely in C#, but it is no longer updated. Discord is still active and any questions you ask will be answered.

https://gist.github.com/xanathar/2c777a79937398834ad4

The above requirements can be achieved by using Hook.

The advantage is that it is pure C# and relatively easy to operate. But the performance is weak, but if you are like me, Lua is only used as a player's Mod. In fact, it's okay, because the logic on the Lua side will be very weak.

nLua
Using Debug Hooks crashes Lua execution · Issue #56 · NLua/NLua · GitHub

nLua's DebugHook is directly integrated, and xLua's Hook boss is not exposed, so you have to do it yourself.

uLua
Lua Modding Framework | Utilities Tools | Unity Asset Store

The resources on Assetstore are still being updated recently.

Thanks to the question owner Eran@UWA Q&A Community for providing the answer


Texture

Q: According to the Texture arrays document ( Unity - Manual: Texture arrays ), GLES3 Metal can already support it.

The easiest thing to think of is the Splat layer of the terrain. If it is a four-layer Splat, then it can be replaced by a Texture2DArray. The advantage is that Bind consumption is reduced. According to Gong Da ( Why should we emphasize the application of Texture2DArray on terrain? - Zhihu ), it seems that the number of Splat sampling can also be reduced, but according to my own testing and understanding, it is not possible because the Slice of Texture2DArray is between I don't know how to blend. I don't know if I understand the problem.

I use a Texture2DArray to replace the 4-layer Splat terrain. From the xCode point of view, there is no reduction in the cost. So at present, the significance of doing this terrain is not very big. There is a plug-in on AssetStore called MegaSplat that uses Texture2DArray to achieve many layer mixing.

Another place where Texture2DArray that comes to mind can be used is the scene map. For example, the scene uses multiple 1024 textures or multiple Lightmaps. Originally, StaticBatching could not be merged due to different textures. Now you can use Texture2DArray to do it.

There are also icons on the UI that can be merged into a Texture2DArray to achieve DrawCall merging.

The worst thing about Texture2DArray at present is that it can only be created through code and has no editor support. If you want to make Texture2DArray offline, you need to prepare multiple resources for different platforms.

I would like to ask if anyone has any experience with Texture2DArray that you can share. Have you used it or plan to use it?

A1: After researching Texture2DArray, it seems that it combines multiple 2D Textures into one object, so you only need to bind it once when using it to sample multiple 2D Textures. Indeed, as the questioner said, only one specified Slice can be sampled at a time, and Blend also requires additional Shader code to complete.

The subject said:

According to Gong Da's intention, it seems that the number of splat sampling can be reduced, but according to my own testing and understanding, it is not feasible.

I think what he means is: it is not necessary to collect all the Slices every time, but only a part of them can be collected. I guess what I originally wanted to express was that only one Slice is taken at a time.

I use a Texture2DArray to replace the 4-layer Splat terrain. From the perspective of xcode, the cost has not been reduced at all. So at present, the significance of doing this terrain is not very big.

If you look at performance alone, Texture2DArray does only reduce the overhead of texture binding compared to Texture2D, which may have an impact on batching in the game engine. Other methods are the same as ordinary Texture2D. Texture2DArray is different from Texture3D in LOD processing. Texture3D will reduce Slice, which is not what you want when rendering Terrain. Then Texture2DArray will only do it on u and v when filtering, while Texture3D will also do it on d, so this part of Texture2DArray has better performance than Texture3D. Combining these factors may be the reason why it is recommended to use Texture2DArray for rendering Terrain. The questioner showed through experiments that Texture2DArray did not reduce the cost of rendering terrain. It may also be because generally there is only one terrain in a scene. It takes a few milliseconds to change from tying 4 textures to 1, and it is not tied every frame, so from the overall The effect is not obvious.

---Updated on 2018.2.22

, I did a simple experiment to verify it. The following figures show the terrain results and GLES API calls using Texture2D and Texture2DArray respectively. The experimental equipment is Samsung s6.

Texture2D:

Texture2DArray:

Among them, the red box in the GLES API call diagram represents the texture binding API call, and the green box represents the rendering API call. WT represents the time taken by the API call, in nanoseconds. From the Texture2D diagram, we can see that there are a total of 5 texture bindings, corresponding to the 5 texture bindings in the material, while there are only two calls in the Texture2DArray diagram, which are the binding of the Splat texture and the four-layer mixed texture. It can be seen from the figure that the time consumption of a glBindTexture is about 1000~10000ns, that is, up to 0.01ms. Therefore, three times glBindTexture plus three times glActiveTexture is also at most 0.06ms. So you can't see it.

Thanks to the ZFK@UWA Q&A community for providing answers

A2: If the terrain requires 16 pictures, is it feasible to ensure that the same location is affected by at most 4 pictures? If possible, can it be understood that using Texture2DArray saves 16-(4+1)=11 Samples and corresponding Bind compared to not using it? (This 4 may also be 2 or 10 depending on the demand. +1 is because the index and weight must be stored separately. Whether +1 is determined depends on the actual situation.) When Array is not used, reducing the number of Samples can also be determined by if, but it will affect GPU parallelism. bigger.

Thanks to [email protected]@UWA Q&A community for providing the answer


That’s it for today’s sharing. Life has limits but knowledge has no limits. In the long development cycle, the problems we encountered are just the tip of the iceberg. The UWA community is willing to accompany you to explore and share together. More developers are welcome to join the UWA community.

UWA official website: www.uwa4d.com
UWA community: community.uwa4d.com

 

Guess you like

Origin blog.csdn.net/UWA4D/article/details/132585032