Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Cannot fill the StructuredBuffer<int> in shader

Discussion in 'Shaders' started by Palom-Porom, Nov 28, 2023.

  1. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Hello everyone. Can someone help me with writting the simple fogOfWar shader. I have an array of integers meaning the view of the teams (visionArray[x + y * width] == view of teams in (x,y); 0 - noteam, 1 - firstTeam, 2- secondTeam, 3 - bothTeams). So I need to push use that array as a StructuredBuffer<int> in my shader. But for some reason it doesn't work...
    Here is my code for SettingBuffer:
    Code (CSharp):
    1. computeBuffer = new ComputeBuffer(250000, sizeof(int), ComputeBufferType.Default, ComputeBufferMode.SubUpdates);
    2. computeBuffer.BeginWrite<int>(0, 250000).CopyFrom(visionMapCopied);
    3. computeBuffer.EndWrite<int>(249999);
    4. material.SetBuffer("_VisionMap", computeBuffer);
    where visionMapCopied updates every frame
    And here is my Shader Code (I am using URP):
    Code (CSharp):
    1. Shader"Unlit/FogOfWarShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "RenderType"="Transparent" "ForceNoShadowCasting" = "True" "PreviewType" = "Plane"}
    10.  
    11.         Pass
    12.         {
    13.             HLSLPROGRAM
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.             #pragma target 4.5
    17.  
    18.             #include "UnityCG.cginc"
    19.  
    20.             struct appdata
    21.             {
    22.                 float4 vertex : POSITION;
    23.                 float2 uv : TEXCOORD0;
    24.             };
    25.  
    26.             struct v2f
    27.             {
    28.                 float2 uv : TEXCOORD0;
    29.                 float4 vertex : SV_POSITION;
    30.             };
    31.  
    32.             extern StructuredBuffer<int> _VisionMap;
    33.             sampler2D _MainTex;
    34.             float4 _MainTex_ST;
    35.  
    36.             v2f vert (appdata v)
    37.             {
    38.                 v2f o;
    39.                 o.vertex = UnityObjectToClipPos(v.vertex);
    40.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    41.                 return o;
    42.             }
    43.  
    44.             fixed4 frag (v2f i) : SV_Target
    45.             {
    46.     int x = int(floor(i.vertex.x));
    47.     int y = int(floor(i.vertex.z));
    48.     int visInfo = _VisionMap[x + y];
    49.     if (visInfo == 0)
    50.         return fixed4(0, 0, 0, 0);
    51.     else
    52.         return fixed4(160, 0, 0, 0);
    53. }
    54.             ENDHLSL
    55.         }
    56.     }
    57. }
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    A couple of notes:
    1. Why you have 249999 instead of 250000 in EndWrite. It should match if you copy 250000 length array. And different if you copy different length amount of data.
    2. What are you doing here:
    Code (CSharp):
    1. int x = int(floor(i.vertex.x));
    2. int y = int(floor(i.vertex.z));
    3. int visInfo = _VisionMap[x + y];
    Where your
    width
    multiply here
    (x + y * width)
    ? Is you vertices positions match fog cells if you doing that? (no negative positions according to pivot etc.) Otherwise these rows makes no sense.
    As a side note - you don't need
    extern
    here.
     
    Last edited: Nov 28, 2023
  3. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    1. Oh, that was just misunderstanding the parameter of function. Corrected to 250000, thanks
    2.Well, the width was deleted through my tryies of tests, but it should be there, you are right (and I should have put it back before posting that thread :( )
    What about the positions... Yeah you are right. Here is the corrected version of frag (it is still not working - the texture is all black, so visInfo == 0 everywhere; the original array has another values from zero for sure):
    Code (CSharp):
    1.         fixed4 frag (v2f i) : SV_Target
    2.         {
    3.             float x = (i.vertex.x) + 500;
    4.             float y = (i.vertex.z) + 500;
    5.             int visInfo = _VisionMap[(int)(floor(x / 2) + floor(y / 2) * 500)];
    6.             if (visInfo == 0)
    7.                 return fixed4(0, 0, 0, 0);
    8.             else
    9.                 return fixed4(160, 0, 0, 0);
    10.         }
    There are division by to because the actual size of physical map is 1000x1000, but the visualMap is only 500x500 for the better perfomance.
    Also there are such strange return-s because I am still in proccess of understanding how to enable transparency in my shader :) So for now it will just change the red value. After understanding transparency will try to remove those if-s because as I understand if-s are extremely bad for shader perfomance + will try to add some blur to the texture (still to think about how exactly)
     
    Last edited: Nov 28, 2023
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    What you see with this? I mean, your plane (?) with this shader. Is it completely black? And for test purposes make alpha 1 (fourth element of fixed4).
    And put these rows between Tags and Pass
    Code (CSharp):
    1. Blend SrcAlpha OneMinusSrcAlpha
    2. Cull Off Lighting Off ZWrite Off
     
  5. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Yeah, just completely black:
    upload_2023-11-28_11-54-24.png
    Below in the console there are:
    Code (CSharp):
    1. var visionMap = SystemAPI.GetSingletonBuffer<VisionMapBuffer>();
    2. int limit = 0;
    3. int limitMax = 500;
    4. for (int i = 0; i < 250000; i++)
    5. {
    6.     visionMapCopied[i] = visionMap[i];
    7.     if (visionMapCopied[i] != 0 && limit < limitMax)
    8.     {
    9.         Debug.Log(visionMapCopied[i]);
    10.         limit++;
    11.     }
    12. }
    So there are indeed other values than zero.

    Also Alpha = 1 didn't change anything

    Also may be it is a useful info, but I have not plane, but a cube. As it is a 3D game and I don't want player to look under the plane (even if I restrict the min height of camera, it will be still visible because of the 2D nature of plane)
     
    Last edited: Nov 28, 2023
  6. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Oh, wait. I understood that I wrongly got the "return fixed4" in the frag shader: it is not 0-255, but 0-1.
    If I put in the end of frag this:
    Code (CSharp):
    1. if (visInfo == 0)
    2.     return fixed4(0, 1, 0, 0.5);
    3. else
    4.     return fixed4(1, 0, 0, 1);
    The whole cube is painted semi-transparent green: upload_2023-11-28_12-17-28.png
    (But the StructedBuffer<int> is still filled only with zeroes :( )
    But already big thanks for giving me the key to transparency!
     
    Last edited: Nov 28, 2023
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Show you mesh wireframe. Is it simple quad of 4 vertices? Oh or it's just a cube?
     
  8. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    upload_2023-11-28_14-4-24.png
    I suppose you asked for this
    But anyway it is just standart Unity Cube Mesh, scaled by (1000, 20, 1000)
     
  9. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Ok, got your case. Then show vertex function where you send vertex position
     
  10. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Code (CSharp):
    1. v2f vert (appdata v)
    2. {
    3.     v2f o;
    4.     o.vertex = UnityObjectToClipPos(v.vertex);
    5.     o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    6.     return o;
    7. }
    Texture is not needed here, I suppose, as it is not used in frag function, but I didn't touch it for now, though. I didn't touch it at all, if I am not mistaken - all by default
     
  11. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Because this is wrong in your case:
    Code (CSharp):
    1. float x = (i.vertex.x) + 500;
    2. float y = (i.vertex.z) + 500;
    3. int visInfo = _VisionMap[(int)(floor(x / 2) + floor(y / 2) * 500)];
     
  12. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Well, then it's even worse in this case :) Because you use vertex position in clip space. You should pass in in object space or in world space. (In case of object space your scale wouldn't count and you'll need to manually pass it inside and calculate)
     
    Last edited: Nov 28, 2023
  13. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    For this one you mean I should just change to:
    Code (CSharp):
    1. v2f vert (appdata v)
    2. {
    3.     v2f o;
    4.  
    5.     //o.vertex = UnityObjectToClipPos(v.vertex);
    6.     o.vertex = mul(unity_ObjectToWorld, v.vertex);
    7.     o.vertex.x *= 1000;
    8.     o.vertex.y *= 20;
    9.     o.vertex.z *= 1000;
    10.     o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    11.     return o;
    12. }
    13.  
    If so, than it is some mess with the positions - on the Material I can see this:
    upload_2023-11-28_14-26-56.png
    But there is nothing I can see on the scene...

    And for this one, I am not sure I understand why. Before for debug I spawned cubes by the map, which was filled by the same algorithm of converting WorldPosition to one dimensional array, and it was spawned right. Now I redone this and it is still right:
    upload_2023-11-28_14-30-42.png
    (I have one unit of blue team in the center with a big radius of vision and 2 small units of red team nearly with small vision. Green means both teams can see that tile)

    (Here is the algorithm of filling that map, if needed. But it has pretty the same algorithm of getting idx in the array...):
    Code (CSharp):
    1.  
    2. const int ORIG_MAP_SIZE = 1000;
    3. const int VIS_MAP_SIZE = 500;
    4. const int ORIG_TO_VIS_MAP_RATIO = 2;
    5.  
    6. //...
    7.  
    8. for (int x = (-visionChars.radius) - visionChars.radius % ORIG_TO_VIS_MAP_RATIO; x <= visionChars.radius; x += ORIG_TO_VIS_MAP_RATIO)
    9. {
    10.     for (int y = (-visionChars.radius) - visionChars.radius % ORIG_TO_VIS_MAP_RATIO; y <= visionChars.radius; y += ORIG_TO_VIS_MAP_RATIO)
    11.     {
    12.         curpointline = new float2(x, y);
    13.         if (math.length(curpointline) > visionChars.radius)
    14.             continue;
    15.         point = math.floor(localtoworld.Position.xz + curpointline + VIS_MAP_SIZE);
    16.         int idx = (int)(point.x / ORIG_TO_VIS_MAP_RATIO + math.floor(point.y / ORIG_TO_VIS_MAP_RATIO) * VIS_MAP_SIZE);
    17.         if (idx >= 0 && idx < visionMap.Length)
    18.             visionMap[idx] |= team.teamInd;
    19.     }
    20. }
     
  14. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    No. That's incorrect too. Just convert it to world space and pass NOT in vertex (Because it needs to be in clip space for SV_POSITION) but add vertexWS (example) to your v2f. No need to multiply to anything if you already pass world space coordinates.
     
  15. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    It's wrong because wrong vertex data used for calculations.
    If you'll do what I've described above, then this calculation will be correct.
    Code (CSharp):
    1. float x = (i.vertexWS.x) + 500;
    2. float y = (i.vertexWS.z) + 500;
    3. int visInfo = _VisionMap[(int)(floor(x / 2) + floor(y / 2) * 500)];
     
  16. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Well, it now it I can see that cube... but there is still no changes due to the _VisionMap.. So maybe I am wrongly getting the vertexWS?
    Sorry, if it is a silly question..

    Code (CSharp):
    1.         Pass
    2.         {
    3.             HLSLPROGRAM
    4.             #pragma vertex vert
    5.             #pragma fragment frag
    6.             #pragma target 4.5
    7.  
    8.             #include "UnityCG.cginc"
    9.  
    10.             struct appdata
    11.             {
    12.                 float4 vertex : POSITION;
    13.                 float2 uv : TEXCOORD0;
    14.             };
    15.  
    16.             struct v2f
    17.             {
    18.                 float2 uv : TEXCOORD0;
    19.                 float4 vertex : SV_POSITION;
    20.                 float4 vertexWS : TEXCOORD1;
    21. };
    22.  
    23.             extern StructuredBuffer<int> _VisionMap;
    24.             sampler2D _MainTex;
    25.             float4 _MainTex_ST;
    26.  
    27.             v2f vert (appdata v)
    28.             {
    29.                 v2f o;
    30.  
    31.                 o.vertex = UnityObjectToClipPos(v.vertex);
    32.                 o.vertexWS = mul(unity_ObjectToWorld, v.vertex);
    33.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    34.                 return o;
    35.             }
    36.  
    37.             fixed4 frag (v2f i) : SV_Target
    38.             {
    39.                  float x = (i.vertexWS.x) + 500;
    40.                  float y = (i.vertexWS.z) + 500;
    41.                  int visInfo = _VisionMap[(int) (floor(x / 2) + floor(y / 2) * 500)];
    42.  
    43.                 if (visInfo == 0)
    44.                     return fixed4(0, 1, 0, 0.3);
    45.                 else
    46.                     return fixed4(1, 0, 0, 1);
    47.             }
    48.             ENDHLSL
    49.         }
     
  17. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Also isn't it a problem that I am using #include "UnityCG.cginc" in the HLSL shader? Only now I understood, that it was there all the time instead of
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
     
  18. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    If you using SRP you shouldn't use cgincludes.
    And in case of SRP you have other utility methods TransformObjectToWorld.
    And for clip space (as you have world from row above) you can use TransformWorldToHClip.

    Also to make it SRP batcher compatible you should use UnityPerMaterial constant buffer.
     
  19. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Well I've changed methods and added UnityPerMaterial constant buffer so now it is SRP batchare compatible
    But there is still no changes due to the VisualMap... Maybe it is a mistake in the SetBuffer or somewhere there? Because it just seems like data from the original array is not transfered to the Structured buffer...

    (Here is the shader code, if needed. But I suppose now it is finnaly right):
    Code (CSharp):
    1.     Pass
    2.     {
    3.         HLSLPROGRAM
    4.         #pragma vertex vert
    5.         #pragma fragment frag
    6.         #pragma target 4.5
    7.  
    8.         #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    9.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
    10.  
    11.         struct appdata
    12.         {
    13.             float4 vertex : POSITION;
    14.             float2 uv : TEXCOORD0;
    15.             #if UNITY_ANY_INSTANCING_ENABLED
    16.             uint instanceID : INSTANCEID_SEMANTIC;
    17.             #endif
    18.         };
    19.  
    20.         struct v2f
    21.         {
    22.             float2 uv : TEXCOORD0;
    23.             float4 vertex : SV_POSITION;
    24.             float3 vertexWS : TEXCOORD1;
    25.             #if UNITY_ANY_INSTANCING_ENABLED
    26.             uint instanceID : CUSTOM_INSTANCE_ID;
    27.             #endif
    28.         };
    29.  
    30.         #ifdef DOTS_INSTANCING_ON
    31.             UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
    32.                 UNITY_DOTS_INSTANCED_PROP(float4, _Color)
    33.             UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
    34.             #define _Color UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _Color)
    35.         #endif
    36.  
    37.         CBUFFER_START(UnityPerMaterial)
    38.         extern StructuredBuffer<int> _VisionMap;
    39.         sampler2D _MainTex;
    40.         float4 _MainTex_ST;
    41.         CBUFFER_END
    42.  
    43.         //extern StructuredBuffer<int> _VisionMap;
    44.         //sampler2D _MainTex;
    45.         //float4 _MainTex_ST;
    46.  
    47.         v2f vert (appdata v)
    48.         {
    49.             v2f o;
    50.  
    51.             UNITY_SETUP_INSTANCE_ID(input);
    52.             UNITY_TRANSFER_INSTANCE_ID(input, output);
    53.          
    54.             //o.vertex = GetVertexPositionInputs(v.vertex).positionCS;
    55.             o.vertexWS = TransformObjectToWorld(v.vertex);
    56.             o.vertex = TransformWorldToHClip(o.vertexWS);
    57.             o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    58.             return o;
    59.         }
    60.  
    61.         float4  frag (v2f i) : SV_Target
    62.         {
    63.             float x = (i.vertexWS.x) + 500;
    64.             float y = (i.vertexWS.z) + 500;
    65.             int visInfo = _VisionMap[(int) (floor(x / 2) + floor(y / 2) * 500)];
    66.  
    67.             if (visInfo == 0)
    68.                 return float4(0, 1, 0, 0.3);
    69.             else
    70.                 return float4(1, 0, 0, 1);
    71.             }
    72.         ENDHLSL
    73.     }
    74. }
     
  20. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Show code around Begin\EndWrite from above
     
  21. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Move StructuredBuffer out from constant buffer. It's in wrong place in your code right now. Also you don't need extern here, you can remove it.
     
  22. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Code (CSharp):
    1. public partial class FillVisionMapTextureSystem : SystemBase
    2. {
    3.     Material material;
    4.     ComputeBuffer computeBuffer;
    5.     NativeArray<int> visionMapCopied;
    6.  
    7.     protected override void OnCreate()
    8.     {
    9.         RequireForUpdate<VisionMapBuffer>();
    10.         RequireForUpdate<GameTag>();
    11.         visionMapCopied = new NativeArray<int>(250000, Allocator.Persistent);
    12.     }
    13.  
    14.     protected override void OnStartRunning()
    15.     {
    16.         material = FogMaterial.material;
    17.         computeBuffer = new ComputeBuffer(250000, sizeof(int), ComputeBufferType.Default, ComputeBufferMode.SubUpdates);
    18.         //unsafe
    19.         //{
    20.         //    void* visionMap = SystemAPI.GetSingletonBuffer<VisionMapBuffer>().GetUnsafePtr();
    21.         //    computeBuffer.BeginWrite<int>(0, 250000).CopyFrom((int*)visionMap);
    22.         //    computeBuffer.EndWrite<int>(249999);
    23.         //}
    24.         //material.SetBuffer("_VisionMap", computeBuffer);
    25.         computeBuffer.BeginWrite<int>(0, 250000).CopyFrom(visionMapCopied);
    26.         computeBuffer.EndWrite<int>(250000);
    27.         material.SetBuffer("_VisionMap", computeBuffer);
    28.     }
    29.  
    30.     protected override void OnUpdate()
    31.     {
    32.         var visionMap = SystemAPI.GetSingletonBuffer<VisionMapBuffer>();
    33.         //computeBuffer.SetData(visionMap);
    34.         //int limit = 0;
    35.         //int limitMax = 500;
    36.         for (int i = 0; i < 250000; i++)
    37.         {
    38.             visionMapCopied[i] = visionMap[i];
    39.             //if (visionMapCopied[i] != 0 && limit < limitMax)
    40.             //{
    41.             //    Debug.Log(visionMapCopied[i]);
    42.             //    limit++;
    43.             //}
    44.         }
    45.     }
    46. }
    (FogMaterial.material - static variable in class. Just didn't come up with any more beautiful solition)
     
  23. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Well you don't fill the buffer. On start running called before OnUpdate and called once (it's not called EVERY frame before OnUpdate, it will be called only if system stop running in previous frame)) in your case, as I believe you not remove GameTag or VisionMapBuffer required queries. For test purposes you can move BeginWrite\EndWrite inside OnUpdate.

    Something like this:
    Code (CSharp):
    1. public partial class FillVisionMapTextureSystem : SystemBase
    2. {
    3.     Material         material;
    4.     ComputeBuffer    computeBuffer;
    5.  
    6.     protected override void OnCreate()
    7.     {
    8.         RequireForUpdate<VisionMapBuffer>();
    9.         RequireForUpdate<GameTag>();
    10.         computeBuffer = new ComputeBuffer(250000, sizeof(int), ComputeBufferType.Default, ComputeBufferMode.SubUpdates);
    11.     }
    12.  
    13.     protected override void OnStartRunning()
    14.     {
    15.         material      = FogMaterial.material;
    16.         material.SetBuffer("_VisionMap", computeBuffer);
    17.     }
    18.  
    19.     protected override void OnDestroy()
    20.     {
    21.         computeBuffer?.Release();
    22.     }
    23.  
    24.     protected override void OnUpdate()
    25.     {
    26.         var visionMap = SystemAPI.GetSingletonBuffer<VisionMapBuffer>();
    27.         computeBuffer.BeginWrite<int>(0, 250000).CopyFrom(visionMap.Reinterpret<int>().AsNativeArray());
    28.         computeBuffer.EndWrite<int>(250000);
    29.     }
    30. }
    Also you don't need double buffer
    visionMapCopied
    here (for now, when you'll do scheduled logic without sync point you'll need double buffering and async gpu readback for it)
    Also I've used DynamicBuffer directly with AsNativeArray if you VisionMapBuffer is only int field inside - it will work without require of any additional copies, as it points directly to memory for copy to gpu buffer.
     
    Last edited: Nov 28, 2023
  24. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    CopyFrom needs NativeArray<int> or int[], but visionMap.AsNativeArray() returns NativeArray<VisionMapBuffer>. Even though I made such things in it:
    Code (CSharp):
    1. [InternalBufferCapacity(0)]
    2. public struct VisionMapBuffer : IBufferElementData
    3. {
    4.     public int value;
    5.     public static implicit operator VisionMapBuffer(int value)
    6.     {
    7.         return new VisionMapBuffer {  value = value };
    8.     }
    9.  
    10.     public static implicit operator int (VisionMapBuffer element)
    11.     {
    12.         return element.value;
    13.     }
    14. }
    So it just gives me a CS1503
     
  25. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Just add .Reinterpret<int>() before .AsNativeArray();
     
  26. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    WOW, Finaly Works!
    Now it is only left to come up with the algorigthm of bluring
    Thank you soo much for your enormous help!
     
  27. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    Sorry, one more question: is this message okay? It apperas in the console with same frequency...

    LockBufferForWrite: Multiple uploads in flight for buffer 000002132D4DBDB8 (bufferHandle: 385) of size 1000000. Falling back to slow path. LockBufferForWrite() should be called only once per frame on D3D11.
    It is leading to the:
    computeBuffer.BeginWrite<int>(0, 250000).CopyFrom(visionMap.Reinterpret<int>().AsNativeArray());
     
  28. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Are you sure is exact line? Because LockBufferForWrite is from GraphicsBuffer not from ComputeBuffer. And as it states if you have Begin write you should call EndWrite in the same frame
     
  29. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    upload_2023-11-28_17-35-19.png
    upload_2023-11-28_17-35-43.png
    Yes, it is exactly that line
     
  30. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,680
    Last edited: Nov 28, 2023
  31. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    51
    OMG, I am very sorry - for real I forgot to remove Begin\EndWrite from OnStartRunning (and even haven't noticed that strange in the code). I apologize for that - now the error has gone

    Again enormouse thanks to you for all your help!