暫無描述
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.

CommandBufferHelpers.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using UnityEngine.VFX;
  3. namespace UnityEngine.Rendering
  4. {
  5. /// <summary>
  6. /// This struct contains some static helper functions that can be used when you want to convert between Commandbuffer and RasterCommandBuffer/ComputeCommandBuffer/UnsafeCommandBuffer
  7. /// </summary>
  8. public struct CommandBufferHelpers
  9. {
  10. internal static RasterCommandBuffer rasterCmd = new RasterCommandBuffer(null, null, false);
  11. internal static ComputeCommandBuffer computeCmd = new ComputeCommandBuffer(null, null, false);
  12. internal static UnsafeCommandBuffer unsafeCmd = new UnsafeCommandBuffer(null, null, false);
  13. /// <summary>
  14. /// Get a RasterCommandBuffer given an standard CommandBuffer.
  15. /// </summary>
  16. /// <param name="baseBuffer">The CommandBuffer the RasterCommandBuffer should record it's commands to.</param>
  17. /// <returns>A RasterCommandBuffer that will record its commands to the given buffer.</returns>
  18. public static RasterCommandBuffer GetRasterCommandBuffer(CommandBuffer baseBuffer)
  19. {
  20. rasterCmd.m_WrappedCommandBuffer = baseBuffer;
  21. return rasterCmd;
  22. }
  23. /// <summary>
  24. /// Get a ComputeCommandBuffer given an standard CommandBuffer.
  25. /// </summary>
  26. /// <param name="baseBuffer">The CommandBuffer the RasterCommandBuffer should record it's commands to.</param>
  27. /// <returns>A ComputeCommandBuffer that will record its commands to the given buffer.</returns>
  28. public static ComputeCommandBuffer GetComputeCommandBuffer(CommandBuffer baseBuffer)
  29. {
  30. computeCmd.m_WrappedCommandBuffer = baseBuffer;
  31. return computeCmd;
  32. }
  33. /// <summary>
  34. /// Get an UnsafeCommandBuffer given an standard CommandBuffer.
  35. /// </summary>
  36. /// <param name="baseBuffer">The CommandBuffer the UnsafeCommandBuffer should record its commands to.</param>
  37. /// <returns>A UnsafeCommandBuffer that will record its commands to the given buffer.</returns>
  38. public static UnsafeCommandBuffer GetUnsafeCommandBuffer(CommandBuffer baseBuffer)
  39. {
  40. unsafeCmd.m_WrappedCommandBuffer = baseBuffer;
  41. return unsafeCmd;
  42. }
  43. /// <summary>
  44. /// Get the actual unity engine CommandBuffer backing a UnsafeCommandBuffer. This strips the last remnants of render graph safety from the UnsafeCommandBuffer
  45. /// you are fully on your own now to ensure any and all render graph safety. Please carefully consider if you really need this.
  46. /// </summary>
  47. /// <param name="baseBuffer">The UnsafeCommandBuffer you want to get the engine commandbuffer from.</param>
  48. /// <returns>A CommandBuffer that will record its commands to the given buffer.</returns>
  49. public static CommandBuffer GetNativeCommandBuffer(UnsafeCommandBuffer baseBuffer)
  50. {
  51. return baseBuffer.m_WrappedCommandBuffer;
  52. }
  53. /// <summary>
  54. /// Wrapper for VFXManager.ProcessCameraCommand that works with UnsafeCommandBuffer.
  55. /// </summary>
  56. /// <param name="cam">The Camera to process the VFX commands for.</param>
  57. /// <param name="cmd">The CommandBuffer to push commands to (can be null).</param>
  58. /// <param name="camXRSettings">The XR settings that the Visual Effect Graph uses to process the Camera commands.</param>
  59. /// <param name="results">The culling results to use.</param>
  60. public static void VFXManager_ProcessCameraCommand(Camera cam, UnsafeCommandBuffer cmd,
  61. VFXCameraXRSettings camXRSettings, CullingResults results)
  62. {
  63. VFXManager.ProcessCameraCommand(cam, cmd.m_WrappedCommandBuffer, camXRSettings, results);
  64. }
  65. }
  66. }