Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 1 | // Copyright 2019 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 | #include "dawn_native/CommandEncoder.h" |
| 16 | |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 17 | #include "common/BitSetIterator.h" |
| 18 | #include "dawn_native/BindGroup.h" |
| 19 | #include "dawn_native/Buffer.h" |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 20 | #include "dawn_native/CommandBuffer.h" |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 21 | #include "dawn_native/CommandBufferStateTracker.h" |
Austin Eng | 3318caa | 2019-08-13 00:22:28 +0000 | [diff] [blame] | 22 | #include "dawn_native/CommandValidation.h" |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 23 | #include "dawn_native/Commands.h" |
| 24 | #include "dawn_native/ComputePassEncoder.h" |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 25 | #include "dawn_native/Device.h" |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 26 | #include "dawn_native/ErrorData.h" |
Hao Li | 5191adc | 2020-07-01 10:48:16 +0000 | [diff] [blame] | 27 | #include "dawn_native/QuerySet.h" |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 28 | #include "dawn_native/RenderPassEncoder.h" |
| 29 | #include "dawn_native/RenderPipeline.h" |
Jiawei Shao | 51c347a | 2019-12-12 01:29:01 +0000 | [diff] [blame] | 30 | #include "dawn_native/ValidationUtils_autogen.h" |
Austin Eng | 73d5bb5 | 2019-10-28 23:15:40 +0000 | [diff] [blame] | 31 | #include "dawn_platform/DawnPlatform.h" |
Austin Eng | d4ce736 | 2019-08-13 19:00:34 +0000 | [diff] [blame] | 32 | #include "dawn_platform/tracing/TraceEvent.h" |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 33 | |
Corentin Wallez | e51f8dd | 2020-02-18 02:44:05 +0000 | [diff] [blame] | 34 | #include <cmath> |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 35 | #include <map> |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 36 | |
| 37 | namespace dawn_native { |
| 38 | |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 39 | namespace { |
| 40 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 41 | MaybeError ValidateB2BCopyAlignment(uint64_t dataSize, |
| 42 | uint64_t srcOffset, |
| 43 | uint64_t dstOffset) { |
Yan, Shaobo | 738567f | 2019-02-27 02:46:27 +0000 | [diff] [blame] | 44 | // Copy size must be a multiple of 4 bytes on macOS. |
| 45 | if (dataSize % 4 != 0) { |
| 46 | return DAWN_VALIDATION_ERROR("Copy size must be a multiple of 4 bytes"); |
| 47 | } |
| 48 | |
| 49 | // SourceOffset and destinationOffset must be multiples of 4 bytes on macOS. |
| 50 | if (srcOffset % 4 != 0 || dstOffset % 4 != 0) { |
| 51 | return DAWN_VALIDATION_ERROR( |
| 52 | "Source offset and destination offset must be multiples of 4 bytes"); |
| 53 | } |
| 54 | |
| 55 | return {}; |
| 56 | } |
| 57 | |
Jiawei Shao | 081d5c2 | 2019-03-04 12:01:59 +0000 | [diff] [blame] | 58 | MaybeError ValidateTextureSampleCountInCopyCommands(const TextureBase* texture) { |
| 59 | if (texture->GetSampleCount() > 1) { |
| 60 | return DAWN_VALIDATION_ERROR("The sample count of textures must be 1"); |
| 61 | } |
| 62 | |
| 63 | return {}; |
| 64 | } |
| 65 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 66 | MaybeError ValidateEntireSubresourceCopied(const TextureCopyView& src, |
| 67 | const TextureCopyView& dst, |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 68 | const Extent3D& copySize) { |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 69 | Extent3D srcSize = src.texture->GetSize(); |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 70 | |
Austin Eng | 2dfc42d | 2020-06-01 16:19:02 +0000 | [diff] [blame] | 71 | ASSERT(src.texture->GetDimension() == wgpu::TextureDimension::e2D && |
| 72 | dst.texture->GetDimension() == wgpu::TextureDimension::e2D); |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 73 | if (dst.origin.x != 0 || dst.origin.y != 0 || srcSize.width != copySize.width || |
| 74 | srcSize.height != copySize.height) { |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 75 | return DAWN_VALIDATION_ERROR( |
| 76 | "The entire subresource must be copied when using a depth/stencil texture or " |
| 77 | "when samples are greater than 1."); |
| 78 | } |
| 79 | |
| 80 | return {}; |
| 81 | } |
| 82 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 83 | MaybeError ValidateTextureToTextureCopyRestrictions(const TextureCopyView& src, |
| 84 | const TextureCopyView& dst, |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 85 | const Extent3D& copySize) { |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 86 | const uint32_t srcSamples = src.texture->GetSampleCount(); |
| 87 | const uint32_t dstSamples = dst.texture->GetSampleCount(); |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 88 | |
| 89 | if (srcSamples != dstSamples) { |
| 90 | return DAWN_VALIDATION_ERROR( |
| 91 | "Source and destination textures must have matching sample counts."); |
| 92 | } else if (srcSamples > 1) { |
| 93 | // D3D12 requires entire subresource to be copied when using CopyTextureRegion when |
| 94 | // samples > 1. |
| 95 | DAWN_TRY(ValidateEntireSubresourceCopied(src, dst, copySize)); |
| 96 | } |
| 97 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 98 | if (src.texture->GetFormat().format != dst.texture->GetFormat().format) { |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 99 | // Metal requires texture-to-texture copies be the same format |
| 100 | return DAWN_VALIDATION_ERROR("Source and destination texture formats must match."); |
Corentin Wallez | a92f83b | 2019-06-21 10:16:15 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 103 | if (src.texture->GetFormat().HasDepthOrStencil()) { |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 104 | // D3D12 requires entire subresource to be copied when using CopyTextureRegion is |
| 105 | // used with depth/stencil. |
| 106 | DAWN_TRY(ValidateEntireSubresourceCopied(src, dst, copySize)); |
| 107 | } |
| 108 | |
Jiawei Shao | e472c45 | 2020-06-08 11:30:01 +0000 | [diff] [blame] | 109 | if (src.texture == dst.texture && src.mipLevel == dst.mipLevel) { |
| 110 | ASSERT(src.texture->GetDimension() == wgpu::TextureDimension::e2D && |
| 111 | dst.texture->GetDimension() == wgpu::TextureDimension::e2D); |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 112 | if (IsRangeOverlapped(src.origin.z, dst.origin.z, copySize.depth)) { |
Jiawei Shao | e472c45 | 2020-06-08 11:30:01 +0000 | [diff] [blame] | 113 | return DAWN_VALIDATION_ERROR( |
| 114 | "Copy subresources cannot be overlapped when copying within the same " |
| 115 | "texture."); |
| 116 | } |
| 117 | } |
| 118 | |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 119 | return {}; |
| 120 | } |
| 121 | |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 122 | MaybeError ValidateCanUseAs(const BufferBase* buffer, wgpu::BufferUsage usage) { |
Corentin Wallez | 1f6c8c4 | 2019-10-23 11:57:41 +0000 | [diff] [blame] | 123 | ASSERT(wgpu::HasZeroOrOneBits(usage)); |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 124 | if (!(buffer->GetUsage() & usage)) { |
| 125 | return DAWN_VALIDATION_ERROR("buffer doesn't have the required usage."); |
| 126 | } |
| 127 | |
| 128 | return {}; |
| 129 | } |
| 130 | |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 131 | MaybeError ValidateCanUseAs(const TextureBase* texture, wgpu::TextureUsage usage) { |
Corentin Wallez | 1f6c8c4 | 2019-10-23 11:57:41 +0000 | [diff] [blame] | 132 | ASSERT(wgpu::HasZeroOrOneBits(usage)); |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 133 | if (!(texture->GetUsage() & usage)) { |
| 134 | return DAWN_VALIDATION_ERROR("texture doesn't have the required usage."); |
| 135 | } |
| 136 | |
| 137 | return {}; |
| 138 | } |
| 139 | |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 140 | MaybeError ValidateAttachmentArrayLayersAndLevelCount(const TextureViewBase* attachment) { |
| 141 | // Currently we do not support layered rendering. |
| 142 | if (attachment->GetLayerCount() > 1) { |
| 143 | return DAWN_VALIDATION_ERROR( |
| 144 | "The layer count of the texture view used as attachment cannot be greater than " |
| 145 | "1"); |
| 146 | } |
| 147 | |
| 148 | if (attachment->GetLevelCount() > 1) { |
| 149 | return DAWN_VALIDATION_ERROR( |
| 150 | "The mipmap level count of the texture view used as attachment cannot be " |
| 151 | "greater than 1"); |
| 152 | } |
| 153 | |
| 154 | return {}; |
| 155 | } |
| 156 | |
| 157 | MaybeError ValidateOrSetAttachmentSize(const TextureViewBase* attachment, |
| 158 | uint32_t* width, |
| 159 | uint32_t* height) { |
| 160 | const Extent3D& textureSize = attachment->GetTexture()->GetSize(); |
| 161 | const uint32_t attachmentWidth = textureSize.width >> attachment->GetBaseMipLevel(); |
| 162 | const uint32_t attachmentHeight = textureSize.height >> attachment->GetBaseMipLevel(); |
| 163 | |
| 164 | if (*width == 0) { |
| 165 | DAWN_ASSERT(*height == 0); |
| 166 | *width = attachmentWidth; |
| 167 | *height = attachmentHeight; |
| 168 | DAWN_ASSERT(*width != 0 && *height != 0); |
| 169 | } else if (*width != attachmentWidth || *height != attachmentHeight) { |
| 170 | return DAWN_VALIDATION_ERROR("Attachment size mismatch"); |
| 171 | } |
| 172 | |
| 173 | return {}; |
| 174 | } |
| 175 | |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 176 | MaybeError ValidateOrSetColorAttachmentSampleCount(const TextureViewBase* colorAttachment, |
| 177 | uint32_t* sampleCount) { |
| 178 | if (*sampleCount == 0) { |
| 179 | *sampleCount = colorAttachment->GetTexture()->GetSampleCount(); |
| 180 | DAWN_ASSERT(*sampleCount != 0); |
| 181 | } else if (*sampleCount != colorAttachment->GetTexture()->GetSampleCount()) { |
| 182 | return DAWN_VALIDATION_ERROR("Color attachment sample counts mismatch"); |
| 183 | } |
| 184 | |
| 185 | return {}; |
| 186 | } |
| 187 | |
| 188 | MaybeError ValidateResolveTarget( |
| 189 | const DeviceBase* device, |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 190 | const RenderPassColorAttachmentDescriptor& colorAttachment) { |
| 191 | if (colorAttachment.resolveTarget == nullptr) { |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 192 | return {}; |
| 193 | } |
| 194 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 195 | const TextureViewBase* resolveTarget = colorAttachment.resolveTarget; |
| 196 | const TextureViewBase* attachment = colorAttachment.attachment; |
| 197 | DAWN_TRY(device->ValidateObject(colorAttachment.resolveTarget)); |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 198 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 199 | if (!attachment->GetTexture()->IsMultisampledTexture()) { |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 200 | return DAWN_VALIDATION_ERROR( |
| 201 | "Cannot set resolve target when the sample count of the color attachment is 1"); |
| 202 | } |
| 203 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 204 | if (resolveTarget->GetTexture()->IsMultisampledTexture()) { |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 205 | return DAWN_VALIDATION_ERROR("Cannot use multisampled texture as resolve target"); |
| 206 | } |
| 207 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 208 | if (resolveTarget->GetLayerCount() > 1) { |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 209 | return DAWN_VALIDATION_ERROR( |
| 210 | "The array layer count of the resolve target must be 1"); |
| 211 | } |
| 212 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 213 | if (resolveTarget->GetLevelCount() > 1) { |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 214 | return DAWN_VALIDATION_ERROR("The mip level count of the resolve target must be 1"); |
| 215 | } |
| 216 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 217 | uint32_t colorAttachmentBaseMipLevel = attachment->GetBaseMipLevel(); |
| 218 | const Extent3D& colorTextureSize = attachment->GetTexture()->GetSize(); |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 219 | uint32_t colorAttachmentWidth = colorTextureSize.width >> colorAttachmentBaseMipLevel; |
| 220 | uint32_t colorAttachmentHeight = colorTextureSize.height >> colorAttachmentBaseMipLevel; |
| 221 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 222 | uint32_t resolveTargetBaseMipLevel = resolveTarget->GetBaseMipLevel(); |
| 223 | const Extent3D& resolveTextureSize = resolveTarget->GetTexture()->GetSize(); |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 224 | uint32_t resolveTargetWidth = resolveTextureSize.width >> resolveTargetBaseMipLevel; |
| 225 | uint32_t resolveTargetHeight = resolveTextureSize.height >> resolveTargetBaseMipLevel; |
| 226 | if (colorAttachmentWidth != resolveTargetWidth || |
| 227 | colorAttachmentHeight != resolveTargetHeight) { |
| 228 | return DAWN_VALIDATION_ERROR( |
| 229 | "The size of the resolve target must be the same as the color attachment"); |
| 230 | } |
| 231 | |
Corentin Wallez | 1f6c8c4 | 2019-10-23 11:57:41 +0000 | [diff] [blame] | 232 | wgpu::TextureFormat resolveTargetFormat = resolveTarget->GetFormat().format; |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 233 | if (resolveTargetFormat != attachment->GetFormat().format) { |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 234 | return DAWN_VALIDATION_ERROR( |
| 235 | "The format of the resolve target must be the same as the color attachment"); |
| 236 | } |
| 237 | |
| 238 | return {}; |
| 239 | } |
| 240 | |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 241 | MaybeError ValidateRenderPassColorAttachment( |
| 242 | const DeviceBase* device, |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 243 | const RenderPassColorAttachmentDescriptor& colorAttachment, |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 244 | uint32_t* width, |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 245 | uint32_t* height, |
| 246 | uint32_t* sampleCount) { |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 247 | DAWN_TRY(device->ValidateObject(colorAttachment.attachment)); |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 248 | |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 249 | const TextureViewBase* attachment = colorAttachment.attachment; |
Corentin Wallez | a92f83b | 2019-06-21 10:16:15 +0000 | [diff] [blame] | 250 | if (!attachment->GetFormat().IsColor() || !attachment->GetFormat().isRenderable) { |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 251 | return DAWN_VALIDATION_ERROR( |
| 252 | "The format of the texture view used as color attachment is not color " |
| 253 | "renderable"); |
| 254 | } |
| 255 | |
Jiawei Shao | 51c347a | 2019-12-12 01:29:01 +0000 | [diff] [blame] | 256 | DAWN_TRY(ValidateLoadOp(colorAttachment.loadOp)); |
| 257 | DAWN_TRY(ValidateStoreOp(colorAttachment.storeOp)); |
| 258 | |
| 259 | if (colorAttachment.loadOp == wgpu::LoadOp::Clear) { |
| 260 | if (std::isnan(colorAttachment.clearColor.r) || |
| 261 | std::isnan(colorAttachment.clearColor.g) || |
| 262 | std::isnan(colorAttachment.clearColor.b) || |
| 263 | std::isnan(colorAttachment.clearColor.a)) { |
| 264 | return DAWN_VALIDATION_ERROR("Color clear value cannot contain NaN"); |
| 265 | } |
| 266 | } |
| 267 | |
Jiawei Shao | 1e1c13e | 2019-03-11 18:41:02 +0000 | [diff] [blame] | 268 | DAWN_TRY(ValidateOrSetColorAttachmentSampleCount(attachment, sampleCount)); |
| 269 | |
| 270 | DAWN_TRY(ValidateResolveTarget(device, colorAttachment)); |
| 271 | |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 272 | DAWN_TRY(ValidateAttachmentArrayLayersAndLevelCount(attachment)); |
| 273 | DAWN_TRY(ValidateOrSetAttachmentSize(attachment, width, height)); |
| 274 | |
| 275 | return {}; |
| 276 | } |
| 277 | |
| 278 | MaybeError ValidateRenderPassDepthStencilAttachment( |
| 279 | const DeviceBase* device, |
| 280 | const RenderPassDepthStencilAttachmentDescriptor* depthStencilAttachment, |
| 281 | uint32_t* width, |
Jiawei Shao | 9313117 | 2019-03-15 05:16:41 +0000 | [diff] [blame] | 282 | uint32_t* height, |
| 283 | uint32_t* sampleCount) { |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 284 | DAWN_ASSERT(depthStencilAttachment != nullptr); |
| 285 | |
| 286 | DAWN_TRY(device->ValidateObject(depthStencilAttachment->attachment)); |
| 287 | |
| 288 | const TextureViewBase* attachment = depthStencilAttachment->attachment; |
Corentin Wallez | a92f83b | 2019-06-21 10:16:15 +0000 | [diff] [blame] | 289 | if (!attachment->GetFormat().HasDepthOrStencil() || |
| 290 | !attachment->GetFormat().isRenderable) { |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 291 | return DAWN_VALIDATION_ERROR( |
| 292 | "The format of the texture view used as depth stencil attachment is not a " |
| 293 | "depth stencil format"); |
| 294 | } |
| 295 | |
Jiawei Shao | 51c347a | 2019-12-12 01:29:01 +0000 | [diff] [blame] | 296 | DAWN_TRY(ValidateLoadOp(depthStencilAttachment->depthLoadOp)); |
| 297 | DAWN_TRY(ValidateLoadOp(depthStencilAttachment->stencilLoadOp)); |
| 298 | DAWN_TRY(ValidateStoreOp(depthStencilAttachment->depthStoreOp)); |
| 299 | DAWN_TRY(ValidateStoreOp(depthStencilAttachment->stencilStoreOp)); |
| 300 | |
Brandon Jones | 7695afc | 2020-07-10 23:13:58 +0000 | [diff] [blame] | 301 | if (attachment->GetAspect() == wgpu::TextureAspect::All && |
| 302 | attachment->GetFormat().HasStencil() && |
| 303 | depthStencilAttachment->depthReadOnly != depthStencilAttachment->stencilReadOnly) { |
| 304 | return DAWN_VALIDATION_ERROR( |
| 305 | "depthReadOnly and stencilReadOnly must be the same when texture aspect is " |
| 306 | "'all'"); |
| 307 | } |
| 308 | |
| 309 | if (depthStencilAttachment->depthReadOnly && |
| 310 | (depthStencilAttachment->depthLoadOp != wgpu::LoadOp::Load || |
| 311 | depthStencilAttachment->depthStoreOp != wgpu::StoreOp::Store)) { |
| 312 | return DAWN_VALIDATION_ERROR( |
| 313 | "depthLoadOp must be load and depthStoreOp must be store when depthReadOnly " |
| 314 | "is true."); |
| 315 | } |
| 316 | |
| 317 | if (depthStencilAttachment->stencilReadOnly && |
| 318 | (depthStencilAttachment->stencilLoadOp != wgpu::LoadOp::Load || |
| 319 | depthStencilAttachment->stencilStoreOp != wgpu::StoreOp::Store)) { |
| 320 | return DAWN_VALIDATION_ERROR( |
| 321 | "stencilLoadOp must be load and stencilStoreOp must be store when " |
| 322 | "stencilReadOnly " |
| 323 | "is true."); |
| 324 | } |
| 325 | |
Jiawei Shao | 51c347a | 2019-12-12 01:29:01 +0000 | [diff] [blame] | 326 | if (depthStencilAttachment->depthLoadOp == wgpu::LoadOp::Clear && |
| 327 | std::isnan(depthStencilAttachment->clearDepth)) { |
| 328 | return DAWN_VALIDATION_ERROR("Depth clear value cannot be NaN"); |
| 329 | } |
| 330 | |
Natasha Lee | cf0e9d9 | 2019-09-25 13:08:28 +0000 | [diff] [blame] | 331 | // This validates that the depth storeOp and stencil storeOps are the same |
| 332 | if (depthStencilAttachment->depthStoreOp != depthStencilAttachment->stencilStoreOp) { |
| 333 | return DAWN_VALIDATION_ERROR( |
| 334 | "The depth storeOp and stencil storeOp are not the same"); |
| 335 | } |
| 336 | |
Jiawei Shao | 9313117 | 2019-03-15 05:16:41 +0000 | [diff] [blame] | 337 | // *sampleCount == 0 must only happen when there is no color attachment. In that case we |
| 338 | // do not need to validate the sample count of the depth stencil attachment. |
Jiawei Shao | 54e4d47 | 2019-03-19 01:12:01 +0000 | [diff] [blame] | 339 | const uint32_t depthStencilSampleCount = attachment->GetTexture()->GetSampleCount(); |
| 340 | if (*sampleCount != 0) { |
| 341 | if (depthStencilSampleCount != *sampleCount) { |
| 342 | return DAWN_VALIDATION_ERROR("Depth stencil attachment sample counts mismatch"); |
| 343 | } |
| 344 | } else { |
| 345 | *sampleCount = depthStencilSampleCount; |
Jiawei Shao | 9313117 | 2019-03-15 05:16:41 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 348 | DAWN_TRY(ValidateAttachmentArrayLayersAndLevelCount(attachment)); |
| 349 | DAWN_TRY(ValidateOrSetAttachmentSize(attachment, width, height)); |
| 350 | |
| 351 | return {}; |
| 352 | } |
| 353 | |
Jiawei Shao | 54e4d47 | 2019-03-19 01:12:01 +0000 | [diff] [blame] | 354 | MaybeError ValidateRenderPassDescriptor(const DeviceBase* device, |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 355 | const RenderPassDescriptor* descriptor, |
Jiawei Shao | 54e4d47 | 2019-03-19 01:12:01 +0000 | [diff] [blame] | 356 | uint32_t* width, |
| 357 | uint32_t* height, |
| 358 | uint32_t* sampleCount) { |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 359 | if (descriptor->colorAttachmentCount > kMaxColorAttachments) { |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 360 | return DAWN_VALIDATION_ERROR("Setting color attachments out of bounds"); |
| 361 | } |
| 362 | |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 363 | for (uint32_t i = 0; i < descriptor->colorAttachmentCount; ++i) { |
| 364 | DAWN_TRY(ValidateRenderPassColorAttachment(device, descriptor->colorAttachments[i], |
Jiawei Shao | 54e4d47 | 2019-03-19 01:12:01 +0000 | [diff] [blame] | 365 | width, height, sampleCount)); |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 368 | if (descriptor->depthStencilAttachment != nullptr) { |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 369 | DAWN_TRY(ValidateRenderPassDepthStencilAttachment( |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 370 | device, descriptor->depthStencilAttachment, width, height, sampleCount)); |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Kai Ninomiya | 53405b5 | 2020-07-11 03:15:16 +0000 | [diff] [blame^] | 373 | if (descriptor->occlusionQuerySet != nullptr) { |
| 374 | return DAWN_VALIDATION_ERROR("occlusionQuerySet not implemented"); |
| 375 | } |
| 376 | |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 377 | if (descriptor->colorAttachmentCount == 0 && |
| 378 | descriptor->depthStencilAttachment == nullptr) { |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 379 | return DAWN_VALIDATION_ERROR("Cannot use render pass with no attachments."); |
| 380 | } |
| 381 | |
| 382 | return {}; |
| 383 | } |
| 384 | |
Corentin Wallez | 4b90c47 | 2019-07-10 20:43:13 +0000 | [diff] [blame] | 385 | MaybeError ValidateComputePassDescriptor(const DeviceBase* device, |
| 386 | const ComputePassDescriptor* descriptor) { |
| 387 | return {}; |
| 388 | } |
| 389 | |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 390 | ResultOrError<TextureCopyView> FixTextureCopyView(DeviceBase* device, |
| 391 | const TextureCopyView* view) { |
| 392 | TextureCopyView fixedView = *view; |
| 393 | |
| 394 | if (view->arrayLayer != 0) { |
| 395 | if (view->origin.z != 0) { |
| 396 | return DAWN_VALIDATION_ERROR("arrayLayer and origin.z cannot both be != 0"); |
| 397 | } else { |
| 398 | fixedView.origin.z = fixedView.arrayLayer; |
| 399 | fixedView.arrayLayer = 1; |
| 400 | device->EmitDeprecationWarning( |
| 401 | "wgpu::TextureCopyView::arrayLayer is deprecated in favor of " |
| 402 | "::origin::z"); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | return fixedView; |
| 407 | } |
| 408 | |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 409 | } // namespace |
| 410 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 411 | CommandEncoder::CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor*) |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 412 | : ObjectBase(device), mEncodingContext(device, this) { |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 415 | CommandBufferResourceUsage CommandEncoder::AcquireResourceUsages() { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 416 | return CommandBufferResourceUsage{mEncodingContext.AcquirePassUsages(), |
Hao Li | 5191adc | 2020-07-01 10:48:16 +0000 | [diff] [blame] | 417 | std::move(mTopLevelBuffers), std::move(mTopLevelTextures), |
| 418 | std::move(mUsedQuerySets)}; |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 421 | CommandIterator CommandEncoder::AcquireCommands() { |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 422 | return mEncodingContext.AcquireCommands(); |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Hao Li | 5191adc | 2020-07-01 10:48:16 +0000 | [diff] [blame] | 425 | void CommandEncoder::TrackUsedQuerySet(QuerySetBase* querySet) { |
| 426 | mUsedQuerySets.insert(querySet); |
| 427 | } |
| 428 | |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 429 | // Implementation of the API's command recording methods |
| 430 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 431 | ComputePassEncoder* CommandEncoder::BeginComputePass(const ComputePassDescriptor* descriptor) { |
Jiawei Shao | b47470d | 2019-03-05 01:02:47 +0000 | [diff] [blame] | 432 | DeviceBase* device = GetDevice(); |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 433 | |
| 434 | bool success = |
| 435 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
| 436 | DAWN_TRY(ValidateComputePassDescriptor(device, descriptor)); |
| 437 | |
| 438 | allocator->Allocate<BeginComputePassCmd>(Command::BeginComputePass); |
| 439 | |
| 440 | return {}; |
| 441 | }); |
| 442 | |
| 443 | if (success) { |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 444 | ComputePassEncoder* passEncoder = |
| 445 | new ComputePassEncoder(device, this, &mEncodingContext); |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 446 | mEncodingContext.EnterPass(passEncoder); |
| 447 | return passEncoder; |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 450 | return ComputePassEncoder::MakeError(device, this, &mEncodingContext); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 453 | RenderPassEncoder* CommandEncoder::BeginRenderPass(const RenderPassDescriptor* descriptor) { |
Jiawei Shao | b2c5023 | 2019-02-27 09:21:56 +0000 | [diff] [blame] | 454 | DeviceBase* device = GetDevice(); |
| 455 | |
Jiawei Shao | 64fcf39 | 2020-04-22 00:55:43 +0000 | [diff] [blame] | 456 | PassResourceUsageTracker usageTracker(PassType::Render); |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 457 | bool success = |
| 458 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
| 459 | uint32_t width = 0; |
| 460 | uint32_t height = 0; |
| 461 | uint32_t sampleCount = 0; |
| 462 | |
| 463 | DAWN_TRY(ValidateRenderPassDescriptor(device, descriptor, &width, &height, |
| 464 | &sampleCount)); |
| 465 | |
| 466 | ASSERT(width > 0 && height > 0 && sampleCount > 0); |
| 467 | |
| 468 | BeginRenderPassCmd* cmd = |
| 469 | allocator->Allocate<BeginRenderPassCmd>(Command::BeginRenderPass); |
| 470 | |
Austin Eng | b98f0fa | 2019-07-26 19:08:18 +0000 | [diff] [blame] | 471 | cmd->attachmentState = device->GetOrCreateAttachmentState(descriptor); |
| 472 | |
| 473 | for (uint32_t i : IterateBitSet(cmd->attachmentState->GetColorAttachmentsMask())) { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 474 | TextureViewBase* view = descriptor->colorAttachments[i].attachment; |
| 475 | TextureViewBase* resolveTarget = descriptor->colorAttachments[i].resolveTarget; |
| 476 | |
| 477 | cmd->colorAttachments[i].view = view; |
| 478 | cmd->colorAttachments[i].resolveTarget = resolveTarget; |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 479 | cmd->colorAttachments[i].loadOp = descriptor->colorAttachments[i].loadOp; |
| 480 | cmd->colorAttachments[i].storeOp = descriptor->colorAttachments[i].storeOp; |
Austin Eng | b98f0fa | 2019-07-26 19:08:18 +0000 | [diff] [blame] | 481 | cmd->colorAttachments[i].clearColor = |
Corentin Wallez | a838c7d | 2019-09-20 22:59:47 +0000 | [diff] [blame] | 482 | descriptor->colorAttachments[i].clearColor; |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 483 | |
Yunchao He | 23428ea | 2020-05-04 17:10:49 +0000 | [diff] [blame] | 484 | usageTracker.TextureViewUsedAs(view, wgpu::TextureUsage::OutputAttachment); |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 485 | |
| 486 | if (resolveTarget != nullptr) { |
Yunchao He | 23428ea | 2020-05-04 17:10:49 +0000 | [diff] [blame] | 487 | usageTracker.TextureViewUsedAs(resolveTarget, |
| 488 | wgpu::TextureUsage::OutputAttachment); |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 489 | } |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Austin Eng | b98f0fa | 2019-07-26 19:08:18 +0000 | [diff] [blame] | 492 | if (cmd->attachmentState->HasDepthStencilAttachment()) { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 493 | TextureViewBase* view = descriptor->depthStencilAttachment->attachment; |
| 494 | |
| 495 | cmd->depthStencilAttachment.view = view; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 496 | cmd->depthStencilAttachment.clearDepth = |
| 497 | descriptor->depthStencilAttachment->clearDepth; |
| 498 | cmd->depthStencilAttachment.clearStencil = |
| 499 | descriptor->depthStencilAttachment->clearStencil; |
| 500 | cmd->depthStencilAttachment.depthLoadOp = |
| 501 | descriptor->depthStencilAttachment->depthLoadOp; |
| 502 | cmd->depthStencilAttachment.depthStoreOp = |
| 503 | descriptor->depthStencilAttachment->depthStoreOp; |
| 504 | cmd->depthStencilAttachment.stencilLoadOp = |
| 505 | descriptor->depthStencilAttachment->stencilLoadOp; |
| 506 | cmd->depthStencilAttachment.stencilStoreOp = |
| 507 | descriptor->depthStencilAttachment->stencilStoreOp; |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 508 | |
Yunchao He | 23428ea | 2020-05-04 17:10:49 +0000 | [diff] [blame] | 509 | usageTracker.TextureViewUsedAs(view, wgpu::TextureUsage::OutputAttachment); |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | cmd->width = width; |
| 513 | cmd->height = height; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 514 | |
| 515 | return {}; |
| 516 | }); |
| 517 | |
| 518 | if (success) { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 519 | RenderPassEncoder* passEncoder = |
| 520 | new RenderPassEncoder(device, this, &mEncodingContext, std::move(usageTracker)); |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 521 | mEncodingContext.EnterPass(passEncoder); |
| 522 | return passEncoder; |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 525 | return RenderPassEncoder::MakeError(device, this, &mEncodingContext); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 528 | void CommandEncoder::CopyBufferToBuffer(BufferBase* source, |
| 529 | uint64_t sourceOffset, |
| 530 | BufferBase* destination, |
| 531 | uint64_t destinationOffset, |
| 532 | uint64_t size) { |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 533 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 534 | if (GetDevice()->IsValidationEnabled()) { |
| 535 | DAWN_TRY(GetDevice()->ValidateObject(source)); |
| 536 | DAWN_TRY(GetDevice()->ValidateObject(destination)); |
| 537 | |
Jiawei Shao | 2ae84e9 | 2020-05-19 00:11:11 +0000 | [diff] [blame] | 538 | if (source == destination) { |
| 539 | return DAWN_VALIDATION_ERROR( |
| 540 | "Source and destination cannot be the same buffer."); |
| 541 | } |
| 542 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 543 | DAWN_TRY(ValidateCopySizeFitsInBuffer(source, sourceOffset, size)); |
| 544 | DAWN_TRY(ValidateCopySizeFitsInBuffer(destination, destinationOffset, size)); |
| 545 | DAWN_TRY(ValidateB2BCopyAlignment(size, sourceOffset, destinationOffset)); |
| 546 | |
| 547 | DAWN_TRY(ValidateCanUseAs(source, wgpu::BufferUsage::CopySrc)); |
| 548 | DAWN_TRY(ValidateCanUseAs(destination, wgpu::BufferUsage::CopyDst)); |
| 549 | |
| 550 | mTopLevelBuffers.insert(source); |
| 551 | mTopLevelBuffers.insert(destination); |
| 552 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 553 | |
Corentin Wallez | 90ad1a3 | 2020-06-11 11:23:35 +0000 | [diff] [blame] | 554 | // Skip noop copies. Some backends validation rules disallow them. |
| 555 | if (size != 0) { |
| 556 | CopyBufferToBufferCmd* copy = |
| 557 | allocator->Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer); |
| 558 | copy->source = source; |
| 559 | copy->sourceOffset = sourceOffset; |
| 560 | copy->destination = destination; |
| 561 | copy->destinationOffset = destinationOffset; |
| 562 | copy->size = size; |
| 563 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 564 | |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 565 | return {}; |
| 566 | }); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 569 | void CommandEncoder::CopyBufferToTexture(const BufferCopyView* source, |
| 570 | const TextureCopyView* destination, |
| 571 | const Extent3D* copySize) { |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 572 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 573 | // TODO(dawn:22): Remove once migration from GPUTextureCopyView.arrayLayer to |
| 574 | // GPUTextureCopyView.origin.z is done. |
| 575 | TextureCopyView fixedDest; |
| 576 | DAWN_TRY_ASSIGN(fixedDest, FixTextureCopyView(GetDevice(), destination)); |
| 577 | destination = &fixedDest; |
| 578 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 579 | if (GetDevice()->IsValidationEnabled()) { |
Tomek Ponitka | 0f5d496 | 2020-07-07 10:18:51 +0000 | [diff] [blame] | 580 | DAWN_TRY(ValidateBufferCopyView(GetDevice(), *source)); |
| 581 | DAWN_TRY(ValidateCanUseAs(source->buffer, wgpu::BufferUsage::CopySrc)); |
| 582 | |
| 583 | DAWN_TRY(ValidateTextureCopyView(GetDevice(), *destination)); |
| 584 | DAWN_TRY(ValidateCanUseAs(destination->texture, wgpu::TextureUsage::CopyDst)); |
| 585 | DAWN_TRY(ValidateTextureSampleCountInCopyCommands(destination->texture)); |
| 586 | |
| 587 | TextureDataLayout sourceAsTextureDataLayout; |
| 588 | sourceAsTextureDataLayout.offset = source->offset; |
| 589 | sourceAsTextureDataLayout.bytesPerRow = source->bytesPerRow; |
| 590 | sourceAsTextureDataLayout.rowsPerImage = source->rowsPerImage; |
| 591 | |
| 592 | DAWN_TRY(ValidateLinearTextureData(sourceAsTextureDataLayout, |
| 593 | source->buffer->GetSize(), |
| 594 | destination->texture->GetFormat(), *copySize)); |
| 595 | DAWN_TRY(ValidateTextureCopyRange(*destination, *copySize)); |
| 596 | |
| 597 | mTopLevelBuffers.insert(source->buffer); |
| 598 | mTopLevelTextures.insert(destination->texture); |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 599 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 600 | |
Corentin Wallez | e4f8e19 | 2020-05-29 07:28:38 +0000 | [diff] [blame] | 601 | // Compute default value for rowsPerImage |
Corentin Wallez | ecabfe8 | 2020-05-13 17:26:05 +0000 | [diff] [blame] | 602 | uint32_t defaultedRowsPerImage = source->rowsPerImage; |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 603 | if (defaultedRowsPerImage == 0) { |
| 604 | defaultedRowsPerImage = copySize->height; |
| 605 | } |
| 606 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 607 | // Record the copy command. |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 608 | CopyBufferToTextureCmd* copy = |
| 609 | allocator->Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture); |
Corentin Wallez | ecabfe8 | 2020-05-13 17:26:05 +0000 | [diff] [blame] | 610 | copy->source.buffer = source->buffer; |
| 611 | copy->source.offset = source->offset; |
Corentin Wallez | e4f8e19 | 2020-05-29 07:28:38 +0000 | [diff] [blame] | 612 | copy->source.bytesPerRow = source->bytesPerRow; |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 613 | copy->source.rowsPerImage = defaultedRowsPerImage; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 614 | copy->destination.texture = destination->texture; |
| 615 | copy->destination.origin = destination->origin; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 616 | copy->destination.mipLevel = destination->mipLevel; |
Corentin Wallez | ff90599 | 2020-06-26 11:07:00 +0000 | [diff] [blame] | 617 | copy->copySize = *copySize; |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 618 | |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 619 | return {}; |
| 620 | }); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 623 | void CommandEncoder::CopyTextureToBuffer(const TextureCopyView* source, |
| 624 | const BufferCopyView* destination, |
| 625 | const Extent3D* copySize) { |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 626 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 627 | // TODO(dawn:22): Remove once migration from GPUTextureCopyView.arrayLayer to |
| 628 | // GPUTextureCopyView.origin.z is done. |
| 629 | TextureCopyView fixedSrc; |
| 630 | DAWN_TRY_ASSIGN(fixedSrc, FixTextureCopyView(GetDevice(), source)); |
| 631 | source = &fixedSrc; |
| 632 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 633 | if (GetDevice()->IsValidationEnabled()) { |
Tomek Ponitka | 0f5d496 | 2020-07-07 10:18:51 +0000 | [diff] [blame] | 634 | DAWN_TRY(ValidateTextureCopyView(GetDevice(), *source)); |
| 635 | DAWN_TRY(ValidateCanUseAs(source->texture, wgpu::TextureUsage::CopySrc)); |
| 636 | DAWN_TRY(ValidateTextureSampleCountInCopyCommands(source->texture)); |
| 637 | |
| 638 | DAWN_TRY(ValidateBufferCopyView(GetDevice(), *destination)); |
| 639 | DAWN_TRY(ValidateCanUseAs(destination->buffer, wgpu::BufferUsage::CopyDst)); |
| 640 | |
| 641 | TextureDataLayout dstAsTextureDataLayout; |
| 642 | dstAsTextureDataLayout.offset = destination->offset; |
| 643 | dstAsTextureDataLayout.bytesPerRow = destination->bytesPerRow; |
| 644 | dstAsTextureDataLayout.rowsPerImage = destination->rowsPerImage; |
| 645 | |
| 646 | DAWN_TRY(ValidateLinearTextureData(dstAsTextureDataLayout, |
| 647 | destination->buffer->GetSize(), |
| 648 | source->texture->GetFormat(), *copySize)); |
| 649 | DAWN_TRY(ValidateTextureCopyRange(*source, *copySize)); |
| 650 | |
| 651 | mTopLevelTextures.insert(source->texture); |
| 652 | mTopLevelBuffers.insert(destination->buffer); |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 653 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 654 | |
Corentin Wallez | e4f8e19 | 2020-05-29 07:28:38 +0000 | [diff] [blame] | 655 | // Compute default value for rowsPerImage |
Corentin Wallez | ecabfe8 | 2020-05-13 17:26:05 +0000 | [diff] [blame] | 656 | uint32_t defaultedRowsPerImage = destination->rowsPerImage; |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 657 | if (defaultedRowsPerImage == 0) { |
| 658 | defaultedRowsPerImage = copySize->height; |
| 659 | } |
| 660 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 661 | // Record the copy command. |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 662 | CopyTextureToBufferCmd* copy = |
| 663 | allocator->Allocate<CopyTextureToBufferCmd>(Command::CopyTextureToBuffer); |
| 664 | copy->source.texture = source->texture; |
| 665 | copy->source.origin = source->origin; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 666 | copy->source.mipLevel = source->mipLevel; |
Corentin Wallez | ecabfe8 | 2020-05-13 17:26:05 +0000 | [diff] [blame] | 667 | copy->destination.buffer = destination->buffer; |
| 668 | copy->destination.offset = destination->offset; |
Corentin Wallez | e4f8e19 | 2020-05-29 07:28:38 +0000 | [diff] [blame] | 669 | copy->destination.bytesPerRow = destination->bytesPerRow; |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 670 | copy->destination.rowsPerImage = defaultedRowsPerImage; |
Corentin Wallez | ff90599 | 2020-06-26 11:07:00 +0000 | [diff] [blame] | 671 | copy->copySize = *copySize; |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 672 | |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 673 | return {}; |
| 674 | }); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 677 | void CommandEncoder::CopyTextureToTexture(const TextureCopyView* source, |
| 678 | const TextureCopyView* destination, |
| 679 | const Extent3D* copySize) { |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 680 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
Corentin Wallez | 984493d | 2020-06-16 03:05:17 +0000 | [diff] [blame] | 681 | // TODO(dawn:22): Remove once migration from GPUTextureCopyView.arrayLayer to |
| 682 | // GPUTextureCopyView.origin.z is done. |
| 683 | TextureCopyView fixedSrc; |
| 684 | DAWN_TRY_ASSIGN(fixedSrc, FixTextureCopyView(GetDevice(), source)); |
| 685 | source = &fixedSrc; |
| 686 | TextureCopyView fixedDest; |
| 687 | DAWN_TRY_ASSIGN(fixedDest, FixTextureCopyView(GetDevice(), destination)); |
| 688 | destination = &fixedDest; |
| 689 | |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 690 | if (GetDevice()->IsValidationEnabled()) { |
| 691 | DAWN_TRY(GetDevice()->ValidateObject(source->texture)); |
| 692 | DAWN_TRY(GetDevice()->ValidateObject(destination->texture)); |
| 693 | |
| 694 | DAWN_TRY( |
| 695 | ValidateTextureToTextureCopyRestrictions(*source, *destination, *copySize)); |
| 696 | |
Tomek Ponitka | 0f5d496 | 2020-07-07 10:18:51 +0000 | [diff] [blame] | 697 | DAWN_TRY(ValidateTextureCopyRange(*source, *copySize)); |
| 698 | DAWN_TRY(ValidateTextureCopyRange(*destination, *copySize)); |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 699 | |
Tomek Ponitka | 0f5d496 | 2020-07-07 10:18:51 +0000 | [diff] [blame] | 700 | DAWN_TRY(ValidateTextureCopyView(GetDevice(), *source)); |
| 701 | DAWN_TRY(ValidateTextureCopyView(GetDevice(), *destination)); |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 702 | |
| 703 | DAWN_TRY(ValidateCanUseAs(source->texture, wgpu::TextureUsage::CopySrc)); |
| 704 | DAWN_TRY(ValidateCanUseAs(destination->texture, wgpu::TextureUsage::CopyDst)); |
| 705 | |
| 706 | mTopLevelTextures.insert(source->texture); |
| 707 | mTopLevelTextures.insert(destination->texture); |
| 708 | } |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 709 | |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 710 | CopyTextureToTextureCmd* copy = |
| 711 | allocator->Allocate<CopyTextureToTextureCmd>(Command::CopyTextureToTexture); |
| 712 | copy->source.texture = source->texture; |
| 713 | copy->source.origin = source->origin; |
| 714 | copy->source.mipLevel = source->mipLevel; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 715 | copy->destination.texture = destination->texture; |
| 716 | copy->destination.origin = destination->origin; |
| 717 | copy->destination.mipLevel = destination->mipLevel; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 718 | copy->copySize = *copySize; |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 719 | |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 720 | return {}; |
| 721 | }); |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 724 | void CommandEncoder::InsertDebugMarker(const char* groupLabel) { |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 725 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
| 726 | InsertDebugMarkerCmd* cmd = |
| 727 | allocator->Allocate<InsertDebugMarkerCmd>(Command::InsertDebugMarker); |
| 728 | cmd->length = strlen(groupLabel); |
| 729 | |
| 730 | char* label = allocator->AllocateData<char>(cmd->length + 1); |
| 731 | memcpy(label, groupLabel, cmd->length + 1); |
| 732 | |
| 733 | return {}; |
| 734 | }); |
| 735 | } |
| 736 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 737 | void CommandEncoder::PopDebugGroup() { |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 738 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
| 739 | allocator->Allocate<PopDebugGroupCmd>(Command::PopDebugGroup); |
| 740 | |
| 741 | return {}; |
| 742 | }); |
| 743 | } |
| 744 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 745 | void CommandEncoder::PushDebugGroup(const char* groupLabel) { |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 746 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
| 747 | PushDebugGroupCmd* cmd = |
| 748 | allocator->Allocate<PushDebugGroupCmd>(Command::PushDebugGroup); |
| 749 | cmd->length = strlen(groupLabel); |
| 750 | |
| 751 | char* label = allocator->AllocateData<char>(cmd->length + 1); |
| 752 | memcpy(label, groupLabel, cmd->length + 1); |
| 753 | |
| 754 | return {}; |
| 755 | }); |
| 756 | } |
| 757 | |
Hao Li | 5191adc | 2020-07-01 10:48:16 +0000 | [diff] [blame] | 758 | void CommandEncoder::WriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) { |
| 759 | mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { |
| 760 | if (GetDevice()->IsValidationEnabled()) { |
| 761 | DAWN_TRY(GetDevice()->ValidateObject(querySet)); |
| 762 | DAWN_TRY(ValidateTimestampQuery(querySet, queryIndex)); |
| 763 | TrackUsedQuerySet(querySet); |
| 764 | } |
| 765 | |
| 766 | WriteTimestampCmd* cmd = |
| 767 | allocator->Allocate<WriteTimestampCmd>(Command::WriteTimestamp); |
| 768 | cmd->querySet = querySet; |
| 769 | cmd->queryIndex = queryIndex; |
| 770 | |
| 771 | return {}; |
| 772 | }); |
| 773 | } |
| 774 | |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 775 | CommandBufferBase* CommandEncoder::Finish(const CommandBufferDescriptor* descriptor) { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 776 | DeviceBase* device = GetDevice(); |
| 777 | // Even if mEncodingContext.Finish() validation fails, calling it will mutate the internal |
| 778 | // state of the encoding context. The internal state is set to finished, and subsequent |
| 779 | // calls to encode commands will generate errors. |
| 780 | if (device->ConsumedError(mEncodingContext.Finish()) || |
Natasha Lee | 2dd9ed0 | 2020-01-31 19:26:49 +0000 | [diff] [blame] | 781 | device->ConsumedError(device->ValidateIsAlive()) || |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 782 | (device->IsValidationEnabled() && |
| 783 | device->ConsumedError(ValidateFinish(mEncodingContext.GetIterator(), |
| 784 | mEncodingContext.GetPassUsages())))) { |
| 785 | return CommandBufferBase::MakeError(device); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 786 | } |
| 787 | ASSERT(!IsError()); |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 788 | return device->CreateCommandBuffer(this, descriptor); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 791 | // Implementation of the command buffer validation that can be precomputed before submit |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 792 | MaybeError CommandEncoder::ValidateFinish(CommandIterator* commands, |
| 793 | const PerPassUsages& perPassUsages) const { |
Corentin Wallez | 321c122 | 2019-11-13 17:00:37 +0000 | [diff] [blame] | 794 | TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "CommandEncoder::ValidateFinish"); |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 795 | DAWN_TRY(GetDevice()->ValidateObject(this)); |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 796 | |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 797 | for (const PassResourceUsage& passUsage : perPassUsages) { |
| 798 | DAWN_TRY(ValidatePassResourceUsage(passUsage)); |
| 799 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 800 | |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 801 | uint64_t debugGroupStackSize = 0; |
| 802 | |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 803 | commands->Reset(); |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 804 | Command type; |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 805 | while (commands->NextCommandId(&type)) { |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 806 | switch (type) { |
| 807 | case Command::BeginComputePass: { |
Austin Eng | fde9490 | 2019-07-24 18:15:24 +0000 | [diff] [blame] | 808 | commands->NextCommand<BeginComputePassCmd>(); |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 809 | DAWN_TRY(ValidateComputePass(commands)); |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 810 | break; |
| 811 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 812 | |
| 813 | case Command::BeginRenderPass: { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 814 | const BeginRenderPassCmd* cmd = commands->NextCommand<BeginRenderPassCmd>(); |
| 815 | DAWN_TRY(ValidateRenderPass(commands, cmd)); |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 816 | break; |
| 817 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 818 | |
| 819 | case Command::CopyBufferToBuffer: { |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 820 | commands->NextCommand<CopyBufferToBufferCmd>(); |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 821 | break; |
| 822 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 823 | |
| 824 | case Command::CopyBufferToTexture: { |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 825 | commands->NextCommand<CopyBufferToTextureCmd>(); |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 826 | break; |
| 827 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 828 | |
| 829 | case Command::CopyTextureToBuffer: { |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 830 | commands->NextCommand<CopyTextureToBufferCmd>(); |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 831 | break; |
| 832 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 833 | |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 834 | case Command::CopyTextureToTexture: { |
Corentin Wallez | ecf9347 | 2020-05-05 08:33:55 +0000 | [diff] [blame] | 835 | commands->NextCommand<CopyTextureToTextureCmd>(); |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 836 | break; |
| 837 | } |
Brandon Jones | d3d3aa0 | 2019-03-26 11:06:23 +0000 | [diff] [blame] | 838 | |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 839 | case Command::InsertDebugMarker: { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 840 | const InsertDebugMarkerCmd* cmd = commands->NextCommand<InsertDebugMarkerCmd>(); |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 841 | commands->NextData<char>(cmd->length + 1); |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 842 | break; |
| 843 | } |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 844 | |
| 845 | case Command::PopDebugGroup: { |
| 846 | commands->NextCommand<PopDebugGroupCmd>(); |
| 847 | DAWN_TRY(ValidateCanPopDebugGroup(debugGroupStackSize)); |
| 848 | debugGroupStackSize--; |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 849 | break; |
| 850 | } |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 851 | |
| 852 | case Command::PushDebugGroup: { |
Austin Eng | 4b0b7a5 | 2019-11-21 22:09:41 +0000 | [diff] [blame] | 853 | const PushDebugGroupCmd* cmd = commands->NextCommand<PushDebugGroupCmd>(); |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 854 | commands->NextData<char>(cmd->length + 1); |
| 855 | debugGroupStackSize++; |
Corentin Wallez | e831653 | 2020-04-02 16:45:17 +0000 | [diff] [blame] | 856 | break; |
| 857 | } |
Hao Li | 5191adc | 2020-07-01 10:48:16 +0000 | [diff] [blame] | 858 | |
| 859 | case Command::WriteTimestamp: { |
| 860 | commands->NextCommand<WriteTimestampCmd>(); |
| 861 | break; |
| 862 | } |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 863 | default: |
| 864 | return DAWN_VALIDATION_ERROR("Command disallowed outside of a pass"); |
| 865 | } |
| 866 | } |
| 867 | |
Corentin Wallez | b8ea84c | 2019-09-10 08:20:40 +0000 | [diff] [blame] | 868 | DAWN_TRY(ValidateFinalDebugGroupStackSize(debugGroupStackSize)); |
| 869 | |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 870 | return {}; |
| 871 | } |
| 872 | |
Corentin Wallez | e1f0d4e | 2019-02-15 12:54:08 +0000 | [diff] [blame] | 873 | } // namespace dawn_native |