Scriptable Render Pipeline (SRP) 之 CommandBuffer

/

CommandBuffer

Description

List of graphics commands to execute.

Command buffers hold list of rendering commands ("set render target, draw mesh, ..."). They can be set to execute at various points during camera rendering (see Camera.AddCommandBuffer), light rendering (see Light.AddCommandBuffer) or be executed immediately (see Graphics.ExecuteCommandBuffer).

Typically they would be used to extend Unity's rendering pipeline in some custom ways. For example, you could render some additional objects into deferred rendering G-buffer after all regular objects are done, or do custom processing of light shadow maps. See command buffers overview page for more details.

Command buffers can be created and then executed many times if needed.

See Also: Camera.AddCommandBufferLight.AddCommandBufferCameraEventLightEventGraphics.ExecuteCommandBuffercommand buffers overview.

Properties

nameName of this command buffer.
sizeInBytesSize of this command buffer in bytes (Read Only).

Constructors

CommandBufferCreate a new empty command buffer.

Public Methods

BeginSampleAdds a command to begin profile sampling.
BlitAdd a "blit into a render texture" command.
BuildRayTracingAccelerationStructureAdds a command to build the RayTracingAccelerationStructure to be used in a ray tracing dispatch.
ClearClear all commands in the buffer.
ClearRandomWriteTargetsClear random write targets for Shader Model 4.5 level pixel shaders.
ClearRenderTargetAdds a "clear render target" command.
ConvertTextureConverts and copies a source texture to a destination texture with a different format or dimensions.
CopyBufferAdds a command to copy the contents of one GraphicsBuffer into another.
CopyCounterValueAdds a command to copy ComputeBuffer or GraphicsBuffer counter value.
CopyTextureAdds a command to copy a texture into another texture.
CreateAsyncGraphicsFenceShortcut for calling GommandBuffer.CreateGraphicsFence with GraphicsFenceType.AsyncQueueSynchronization as the first parameter.
CreateGraphicsFenceCreates a GraphicsFence which will be passed after the last Blit, Clear, Draw, Dispatch or Texture Copy command prior to this call has been completed on the GPU.
DisableKeywordAdds a command to disable a global or local shader keyword.
DisableScissorRectAdd a command to disable the hardware scissor rectangle.
DisableShaderKeywordAdds a command to disable a global shader keyword with a given name.
DispatchComputeAdd a command to execute a ComputeShader.
DispatchRaysAdds a command to execute a RayTracingShader.
DrawMeshAdd a "draw mesh" command.
DrawMeshInstancedAdds a "draw mesh with instancing" command.The command will not immediately fail and throw an exception if Material.enableInstancing is false, but it will log an error and skips rendering each time the command is being executed if such a condition is detected.InvalidOperationException will be thrown if the current platform doesn't support this API (i.e. if GPU instancing is not available). See SystemInfo.supportsInstancing.
DrawMeshInstancedIndirectAdd a "draw mesh with indirect instancing" command.
DrawMeshInstancedProceduralAdd a "draw mesh with instancing" command.Draw a mesh using Procedural Instancing. This is similar to Graphics.DrawMeshInstancedIndirect, except that when the instance count is known from script, it can be supplied directly using this method, rather than via a ComputeBuffer. If Material.enableInstancing is false, the command logs an error and skips rendering each time the command is executed; the command does not immediately fail and throw an exception.InvalidOperationException will be thrown if the current platform doesn't support this API (for example, if GPU instancing is not available). See SystemInfo.supportsInstancing.
DrawOcclusionMeshAdds a command onto the commandbuffer to draw the VR Device's occlusion mesh to the current render target.
DrawProceduralAdd a "draw procedural geometry" command.
DrawProceduralIndirectAdd a "draw procedural geometry" command.
DrawRendererAdd a "draw renderer" command.
DrawRendererListAdds a "draw renderer list" command.
EnableKeywordAdds a command to enable a global or local shader keyword.
EnableScissorRectAdd a command to enable the hardware scissor rectangle.
EnableShaderKeywordAdds a command to enable a global keyword with a given name.
EndSampleAdds a command to end profile sampling.
GenerateMipsGenerate mipmap levels of a render texture.
GetTemporaryRTAdd a "get a temporary render texture" command.
GetTemporaryRTArrayAdd a "get a temporary render texture array" command.
IncrementUpdateCountIncrements the updateCount property of a Texture.
IssuePluginCustomBlitSend a user-defined blit event to a native code plugin.
IssuePluginCustomTextureUpdateV2Send a texture update event to a native code plugin.
IssuePluginEventSend a user-defined event to a native code plugin.
IssuePluginEventAndDataSend a user-defined event to a native code plugin with custom data.
MarkLateLatchMatrixShaderPropertyIDMark a global shader property id to be late latched. Possible shader properties include view, inverseView, viewProjection, and inverseViewProjection matrices. The Universal Render Pipeline (URP) uses this function to support late latching of shader properties. If you call this function when using built-in Unity rendering or the High-Definition Rendering Pipeline (HDRP), the results are ignored.
ReleaseTemporaryRTAdd a "release a temporary render texture" command.
RequestAsyncReadbackAdds an asynchonous GPU readback request command to the command buffer.
RequestAsyncReadbackIntoNativeArrayAdds an asynchonous GPU readback request command to the command buffer.
RequestAsyncReadbackIntoNativeSliceAdds an asynchonous GPU readback request command to the command buffer.
ResolveAntiAliasedSurfaceForce an antialiased render texture to be resolved.
SetBufferCounterValueAdds a command to set the counter value of append/consume buffer.
SetBufferDataAdds a command to set the buffer with values from an array.
SetComputeBufferParamAdds a command to set an input or output buffer parameter on a ComputeShader.
SetComputeConstantBufferParamAdds a command to set a constant buffer on a ComputeShader.
SetComputeFloatParamAdds a command to set a float parameter on a ComputeShader.
SetComputeFloatParamsAdds a command to set multiple consecutive float parameters on a ComputeShader.
SetComputeIntParamAdds a command to set an integer parameter on a ComputeShader.
SetComputeIntParamsAdds a command to set multiple consecutive integer parameters on a ComputeShader.
SetComputeMatrixArrayParamAdds a command to set a matrix array parameter on a ComputeShader.
SetComputeMatrixParamAdds a command to set a matrix parameter on a ComputeShader.
SetComputeTextureParamAdds a command to set a texture parameter on a ComputeShader.
SetComputeVectorArrayParamAdds a command to set a vector array parameter on a ComputeShader.
SetComputeVectorParamAdds a command to set a vector parameter on a ComputeShader.
SetExecutionFlagsSet flags describing the intention for how the command buffer will be executed.
SetGlobalBufferAdd a "set global shader buffer property" command.
SetGlobalColorAdd a "set global shader color property" command.
SetGlobalConstantBufferAdd a command to bind a global constant buffer.
SetGlobalDepthBiasAdds a command to set the global depth bias.
SetGlobalFloatAdd a "set global shader float property" command.
SetGlobalFloatArrayAdd a "set global shader float array property" command.
SetGlobalIntAdds a command to set the value of a given property for all Shaders, where the property has a type of Int in ShaderLab code.
SetGlobalIntegerAdds a command to set the value of a given property for all Shaders, where the property is an integer.
SetGlobalMatrixAdd a "set global shader matrix property" command.
SetGlobalMatrixArrayAdd a "set global shader matrix array property" command.
SetGlobalTextureAdd a "set global shader texture property" command, referencing a RenderTexture.
SetGlobalVectorAdd a "set global shader vector property" command.
SetGlobalVectorArrayAdd a "set global shader vector array property" command.
SetInstanceMultiplierAdds a command to multiply the instance count of every draw call by a specific multiplier.
SetInvertCullingAdd a "set invert culling" command to the buffer.
SetKeywordAdds a command to set the state of a global or local shader keyword.
SetLateLatchProjectionMatricesSet the current stereo projection matrices for late latching. Stereo matrices is passed in as an array of two matrices.
SetProjectionMatrixAdd a command to set the projection matrix.
SetRandomWriteTargetSet random write target for Shader Model 4.5 level pixel shaders.
SetRayTracingAccelerationStructureAdds a command to set the RayTracingAccelerationStructure to be used with the RayTracingShader.
SetRayTracingBufferParamAdds a command to set an input or output buffer parameter on a RayTracingShader.
SetRayTracingConstantBufferParamAdds a command to set a constant buffer on a RayTracingShader.
SetRayTracingFloatParamAdds a command to set a float parameter on a RayTracingShader.
SetRayTracingFloatParamsAdds a command to set multiple consecutive float parameters on a RayTracingShader.
SetRayTracingIntParamAdds a command to set an integer parameter on a RayTracingShader.
SetRayTracingIntParamsAdds a command to set multiple consecutive integer parameters on a RayTracingShader.
SetRayTracingMatrixArrayParamAdds a command to set a matrix array parameter on a RayTracingShader.
SetRayTracingMatrixParamAdds a command to set a matrix parameter on a RayTracingShader.
SetRayTracingShaderPassAdds a command to select which Shader Pass to use when executing ray/geometry intersection shaders.
SetRayTracingTextureParamAdds a command to set a texture parameter on a RayTracingShader.
SetRayTracingVectorArrayParamAdds a command to set a vector array parameter on a RayTracingShader.
SetRayTracingVectorParamAdds a command to set a vector parameter on a RayTracingShader.
SetRenderTargetAdd a "set active render target" command.
SetShadowSamplingModeAdd a "set shadow sampling mode" command.
SetSinglePassStereoAdd a command to set single-pass stereo mode for the camera.
SetViewMatrixAdd a command to set the view matrix.
SetViewportAdd a command to set the rendering viewport.
SetViewProjectionMatricesAdd a command to set the view and projection matrices.
UnmarkLateLatchMatrixUnmark a global shader property for late latching. After unmarking, the shader property will no longer be late latched. This function is intended for the Universal Render Pipeline (URP) to specify late latched shader properties.
WaitAllAsyncReadbackRequestsAdds an "AsyncGPUReadback.WaitAllRequests" command to the CommandBuffer.
WaitOnAsyncGraphicsFenceInstructs the GPU to wait until the given GraphicsFence is passed.

///

Camera.AddCommandBuffer

Declaration

public void AddCommandBuffer(Rendering.CameraEvent evt, Rendering.CommandBuffer buffer);

Parameters

evtWhen to execute the command buffer during rendering.
bufferThe buffer to execute.

Description

Add a command buffer to be executed at a specified place.

Multiple command buffers can be set to execute at the same camera event (or even the same buffer can be added multiple times). To remove command buffer from execution, use RemoveCommandBuffer.

/

Camera.RemoveCommandBuffer

Declaration

public void RemoveCommandBuffer(Rendering.CameraEvent evt, Rendering.CommandBuffer buffer);

Parameters

evtWhen to execute the command buffer during rendering.
bufferThe buffer to execute.

Description

Remove command buffer from execution at a specified place.

If the same buffer is added multiple times on this camera event, all occurrences of it will be removed.

Light.AddCommandBuffer

Declaration

public void AddCommandBuffer(Rendering.LightEvent evt, Rendering.CommandBuffer buffer);

Declaration

public void AddCommandBuffer(Rendering.LightEvent evt, Rendering.CommandBuffer buffer, Rendering.ShadowMapPass shadowPassMask);

Parameters

evtWhen to execute the command buffer during rendering.
bufferThe buffer to execute.
shadowPassMaskA mask specifying which shadow passes to execute the buffer for.

Description

Add a command buffer to be executed at a specified place.

Multiple command buffers can be set to execute at the same light event (or even the same buffer can be added multiple times). To remove command buffer from execution, use RemoveCommandBuffer.

Passing a shadow pass mask allows detailed control over which shadow passes will execute the buffer.

//

Light.RemoveCommandBuffer

Declaration

public void RemoveCommandBuffer(Rendering.LightEvent evt, Rendering.CommandBuffer buffer);

Parameters

evtWhen to execute the command buffer during rendering.
bufferThe buffer to execute.

Description

Remove command buffer from execution at a specified place.

If the same buffer is added multiple times on this light event, all occurrences of it will be removed.

Graphics.ExecuteCommandBuffer

Declaration

public static void ExecuteCommandBuffer(Rendering.CommandBuffer buffer);

Parameters

bufferThe buffer to execute.

Description

Execute a command buffer.

All commands in the buffer will be executed immediately.

//

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值