1 // Copyright 2017 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_COMMANDS_H_ 16 #define DAWNNATIVE_COMMANDS_H_ 17 18 #include "common/Constants.h" 19 20 #include "dawn_native/AttachmentState.h" 21 #include "dawn_native/BindingInfo.h" 22 #include "dawn_native/Texture.h" 23 24 #include "dawn_native/dawn_platform.h" 25 26 #include <array> 27 #include <bitset> 28 29 namespace dawn_native { 30 31 // Definition of the commands that are present in the CommandIterator given by the 32 // CommandBufferBuilder. There are not defined in CommandBuffer.h to break some header 33 // dependencies: Ref<Object> needs Object to be defined. 34 35 enum class Command { 36 BeginComputePass, 37 BeginOcclusionQuery, 38 BeginRenderPass, 39 ClearBuffer, 40 CopyBufferToBuffer, 41 CopyBufferToTexture, 42 CopyTextureToBuffer, 43 CopyTextureToTexture, 44 Dispatch, 45 DispatchIndirect, 46 Draw, 47 DrawIndexed, 48 DrawIndirect, 49 DrawIndexedIndirect, 50 EndComputePass, 51 EndOcclusionQuery, 52 EndRenderPass, 53 ExecuteBundles, 54 InsertDebugMarker, 55 PopDebugGroup, 56 PushDebugGroup, 57 ResolveQuerySet, 58 SetComputePipeline, 59 SetRenderPipeline, 60 SetStencilReference, 61 SetViewport, 62 SetScissorRect, 63 SetBlendConstant, 64 SetBindGroup, 65 SetIndexBuffer, 66 SetVertexBuffer, 67 WriteBuffer, 68 WriteTimestamp, 69 }; 70 71 struct BeginComputePassCmd {}; 72 73 struct BeginOcclusionQueryCmd { 74 Ref<QuerySetBase> querySet; 75 uint32_t queryIndex; 76 }; 77 78 struct RenderPassColorAttachmentInfo { 79 Ref<TextureViewBase> view; 80 Ref<TextureViewBase> resolveTarget; 81 wgpu::LoadOp loadOp; 82 wgpu::StoreOp storeOp; 83 dawn_native::Color clearColor; 84 }; 85 86 struct RenderPassDepthStencilAttachmentInfo { 87 Ref<TextureViewBase> view; 88 wgpu::LoadOp depthLoadOp; 89 wgpu::StoreOp depthStoreOp; 90 wgpu::LoadOp stencilLoadOp; 91 wgpu::StoreOp stencilStoreOp; 92 float clearDepth; 93 uint32_t clearStencil; 94 bool depthReadOnly; 95 bool stencilReadOnly; 96 }; 97 98 struct BeginRenderPassCmd { 99 Ref<AttachmentState> attachmentState; 100 ityp::array<ColorAttachmentIndex, RenderPassColorAttachmentInfo, kMaxColorAttachments> 101 colorAttachments; 102 RenderPassDepthStencilAttachmentInfo depthStencilAttachment; 103 104 // Cache the width and height of all attachments for convenience 105 uint32_t width; 106 uint32_t height; 107 108 Ref<QuerySetBase> occlusionQuerySet; 109 }; 110 111 struct BufferCopy { 112 Ref<BufferBase> buffer; 113 uint64_t offset; 114 uint32_t bytesPerRow; 115 uint32_t rowsPerImage; 116 }; 117 118 struct TextureCopy { 119 Ref<TextureBase> texture; 120 uint32_t mipLevel; 121 Origin3D origin; // Texels / array layer 122 Aspect aspect; 123 }; 124 125 struct CopyBufferToBufferCmd { 126 Ref<BufferBase> source; 127 uint64_t sourceOffset; 128 Ref<BufferBase> destination; 129 uint64_t destinationOffset; 130 uint64_t size; 131 }; 132 133 struct CopyBufferToTextureCmd { 134 BufferCopy source; 135 TextureCopy destination; 136 Extent3D copySize; // Texels 137 }; 138 139 struct CopyTextureToBufferCmd { 140 TextureCopy source; 141 BufferCopy destination; 142 Extent3D copySize; // Texels 143 }; 144 145 struct CopyTextureToTextureCmd { 146 TextureCopy source; 147 TextureCopy destination; 148 Extent3D copySize; // Texels 149 }; 150 151 struct DispatchCmd { 152 uint32_t x; 153 uint32_t y; 154 uint32_t z; 155 }; 156 157 struct DispatchIndirectCmd { 158 Ref<BufferBase> indirectBuffer; 159 uint64_t indirectOffset; 160 }; 161 162 struct DrawCmd { 163 uint32_t vertexCount; 164 uint32_t instanceCount; 165 uint32_t firstVertex; 166 uint32_t firstInstance; 167 }; 168 169 struct DrawIndexedCmd { 170 uint32_t indexCount; 171 uint32_t instanceCount; 172 uint32_t firstIndex; 173 int32_t baseVertex; 174 uint32_t firstInstance; 175 }; 176 177 struct DrawIndirectCmd { 178 Ref<BufferBase> indirectBuffer; 179 uint64_t indirectOffset; 180 }; 181 182 struct DrawIndexedIndirectCmd { 183 Ref<BufferBase> indirectBuffer; 184 uint64_t indirectOffset; 185 }; 186 187 struct EndComputePassCmd {}; 188 189 struct EndOcclusionQueryCmd { 190 Ref<QuerySetBase> querySet; 191 uint32_t queryIndex; 192 }; 193 194 struct EndRenderPassCmd {}; 195 196 struct ExecuteBundlesCmd { 197 uint32_t count; 198 }; 199 200 struct ClearBufferCmd { 201 Ref<BufferBase> buffer; 202 uint64_t offset; 203 uint64_t size; 204 }; 205 206 struct InsertDebugMarkerCmd { 207 uint32_t length; 208 }; 209 210 struct PopDebugGroupCmd {}; 211 212 struct PushDebugGroupCmd { 213 uint32_t length; 214 }; 215 216 struct ResolveQuerySetCmd { 217 Ref<QuerySetBase> querySet; 218 uint32_t firstQuery; 219 uint32_t queryCount; 220 Ref<BufferBase> destination; 221 uint64_t destinationOffset; 222 }; 223 224 struct SetComputePipelineCmd { 225 Ref<ComputePipelineBase> pipeline; 226 }; 227 228 struct SetRenderPipelineCmd { 229 Ref<RenderPipelineBase> pipeline; 230 }; 231 232 struct SetStencilReferenceCmd { 233 uint32_t reference; 234 }; 235 236 struct SetViewportCmd { 237 float x, y, width, height, minDepth, maxDepth; 238 }; 239 240 struct SetScissorRectCmd { 241 uint32_t x, y, width, height; 242 }; 243 244 struct SetBlendConstantCmd { 245 Color color; 246 }; 247 248 struct SetBindGroupCmd { 249 BindGroupIndex index; 250 Ref<BindGroupBase> group; 251 uint32_t dynamicOffsetCount; 252 }; 253 254 struct SetIndexBufferCmd { 255 Ref<BufferBase> buffer; 256 wgpu::IndexFormat format; 257 uint64_t offset; 258 uint64_t size; 259 }; 260 261 struct SetVertexBufferCmd { 262 VertexBufferSlot slot; 263 Ref<BufferBase> buffer; 264 uint64_t offset; 265 uint64_t size; 266 }; 267 268 struct WriteBufferCmd { 269 Ref<BufferBase> buffer; 270 uint64_t offset; 271 uint64_t size; 272 }; 273 274 struct WriteTimestampCmd { 275 Ref<QuerySetBase> querySet; 276 uint32_t queryIndex; 277 }; 278 279 // This needs to be called before the CommandIterator is freed so that the Ref<> present in 280 // the commands have a chance to run their destructor and remove internal references. 281 class CommandIterator; 282 void FreeCommands(CommandIterator* commands); 283 284 // Helper function to allow skipping over a command when it is unimplemented, while still 285 // consuming the correct amount of data from the command iterator. 286 void SkipCommand(CommandIterator* commands, Command type); 287 288 } // namespace dawn_native 289 290 #endif // DAWNNATIVE_COMMANDS_H_ 291