No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TileRangeExpansionJob.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Unity.Burst;
  2. using Unity.Collections;
  3. using Unity.Jobs;
  4. using Unity.Mathematics;
  5. namespace UnityEngine.Rendering.Universal
  6. {
  7. [BurstCompile(FloatMode = FloatMode.Fast, DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)]
  8. struct TileRangeExpansionJob : IJobFor
  9. {
  10. [ReadOnly]
  11. public NativeArray<InclusiveRange> tileRanges;
  12. [NativeDisableParallelForRestriction]
  13. public NativeArray<uint> tileMasks;
  14. public int rangesPerItem;
  15. public int itemsPerTile;
  16. public int wordsPerTile;
  17. public int2 tileResolution;
  18. public void Execute(int jobIndex)
  19. {
  20. var rowIndex = jobIndex % tileResolution.y;
  21. var viewIndex = jobIndex / tileResolution.y;
  22. var compactCount = 0;
  23. var itemIndices = new NativeArray<short>(itemsPerTile, Allocator.Temp);
  24. var itemRanges = new NativeArray<InclusiveRange>(itemsPerTile, Allocator.Temp);
  25. // Compact the light ranges for the current row.
  26. for (var itemIndex = 0; itemIndex < itemsPerTile; itemIndex++)
  27. {
  28. var range = tileRanges[viewIndex * rangesPerItem * itemsPerTile + itemIndex * rangesPerItem + 1 + rowIndex];
  29. if (!range.isEmpty)
  30. {
  31. itemIndices[compactCount] = (short)itemIndex;
  32. itemRanges[compactCount] = range;
  33. compactCount++;
  34. }
  35. }
  36. var rowBaseMaskIndex = viewIndex * wordsPerTile * tileResolution.x * tileResolution.y + rowIndex * wordsPerTile * tileResolution.x;
  37. for (var tileIndex = 0; tileIndex < tileResolution.x; tileIndex++)
  38. {
  39. var tileBaseIndex = rowBaseMaskIndex + tileIndex * wordsPerTile;
  40. for (var i = 0; i < compactCount; i++)
  41. {
  42. var itemIndex = (int)itemIndices[i];
  43. var wordIndex = itemIndex / 32;
  44. var itemMask = 1u << (itemIndex % 32);
  45. var range = itemRanges[i];
  46. if (range.Contains((short)tileIndex))
  47. {
  48. tileMasks[tileBaseIndex + wordIndex] |= itemMask;
  49. }
  50. }
  51. }
  52. itemIndices.Dispose();
  53. itemRanges.Dispose();
  54. }
  55. }
  56. }