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 #ifndef DAWNNATIVE_COMMANDENCODER_H_ 16 #define DAWNNATIVE_COMMANDENCODER_H_ 17 18 #include "dawn_native/dawn_platform.h" 19 20 #include "dawn_native/EncodingContext.h" 21 #include "dawn_native/Error.h" 22 #include "dawn_native/ObjectBase.h" 23 #include "dawn_native/PassResourceUsage.h" 24 25 #include <string> 26 27 namespace dawn_native { 28 29 class CommandEncoder final : public ApiObjectBase { 30 public: 31 CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor* descriptor); 32 33 ObjectType GetType() const override; 34 35 CommandIterator AcquireCommands(); 36 CommandBufferResourceUsage AcquireResourceUsages(); 37 38 void TrackUsedQuerySet(QuerySetBase* querySet); 39 void TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex); 40 41 // Dawn API 42 ComputePassEncoder* APIBeginComputePass(const ComputePassDescriptor* descriptor); 43 RenderPassEncoder* APIBeginRenderPass(const RenderPassDescriptor* descriptor); 44 45 void APICopyBufferToBuffer(BufferBase* source, 46 uint64_t sourceOffset, 47 BufferBase* destination, 48 uint64_t destinationOffset, 49 uint64_t size); 50 void APICopyBufferToTexture(const ImageCopyBuffer* source, 51 const ImageCopyTexture* destination, 52 const Extent3D* copySize); 53 void APICopyTextureToBuffer(const ImageCopyTexture* source, 54 const ImageCopyBuffer* destination, 55 const Extent3D* copySize); 56 void APICopyTextureToTexture(const ImageCopyTexture* source, 57 const ImageCopyTexture* destination, 58 const Extent3D* copySize); 59 void APICopyTextureToTextureInternal(const ImageCopyTexture* source, 60 const ImageCopyTexture* destination, 61 const Extent3D* copySize); 62 void APIClearBuffer(BufferBase* destination, uint64_t destinationOffset, uint64_t size); 63 64 void APIInjectValidationError(const char* message); 65 void APIInsertDebugMarker(const char* groupLabel); 66 void APIPopDebugGroup(); 67 void APIPushDebugGroup(const char* groupLabel); 68 69 void APIResolveQuerySet(QuerySetBase* querySet, 70 uint32_t firstQuery, 71 uint32_t queryCount, 72 BufferBase* destination, 73 uint64_t destinationOffset); 74 void APIWriteBuffer(BufferBase* buffer, 75 uint64_t bufferOffset, 76 const uint8_t* data, 77 uint64_t size); 78 void APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex); 79 80 CommandBufferBase* APIFinish(const CommandBufferDescriptor* descriptor = nullptr); 81 82 private: 83 void DestroyImpl() override; 84 ResultOrError<Ref<CommandBufferBase>> FinishInternal( 85 const CommandBufferDescriptor* descriptor); 86 87 // Helper to be able to implement both APICopyTextureToTexture and 88 // APICopyTextureToTextureInternal. The only difference between both 89 // copies, is that the Internal one will also check internal usage. 90 template <bool Internal> 91 void APICopyTextureToTextureHelper(const ImageCopyTexture* source, 92 const ImageCopyTexture* destination, 93 const Extent3D* copySize); 94 95 MaybeError ValidateFinish() const; 96 97 EncodingContext mEncodingContext; 98 std::set<BufferBase*> mTopLevelBuffers; 99 std::set<TextureBase*> mTopLevelTextures; 100 std::set<QuerySetBase*> mUsedQuerySets; 101 102 uint64_t mDebugGroupStackSize = 0; 103 }; 104 105 } // namespace dawn_native 106 107 #endif // DAWNNATIVE_COMMANDENCODER_H_ 108