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/CommandAllocator.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 struct BeginRenderPassCmd; 30 31 class CommandEncoderBase : public ObjectBase { 32 public: 33 CommandEncoderBase(DeviceBase* device, const CommandEncoderDescriptor* descriptor); 34 ~CommandEncoderBase(); 35 36 CommandIterator AcquireCommands(); 37 CommandBufferResourceUsage AcquireResourceUsages(); 38 39 // Dawn API 40 ComputePassEncoderBase* BeginComputePass(const ComputePassDescriptor* descriptor); 41 RenderPassEncoderBase* BeginRenderPass(const RenderPassDescriptor* descriptor); 42 void CopyBufferToBuffer(BufferBase* source, 43 uint64_t sourceOffset, 44 BufferBase* destination, 45 uint64_t destinationOffset, 46 uint64_t size); 47 void CopyBufferToTexture(const BufferCopyView* source, 48 const TextureCopyView* destination, 49 const Extent3D* copySize); 50 void CopyTextureToBuffer(const TextureCopyView* source, 51 const BufferCopyView* destination, 52 const Extent3D* copySize); 53 void CopyTextureToTexture(const TextureCopyView* source, 54 const TextureCopyView* destination, 55 const Extent3D* copySize); 56 CommandBufferBase* Finish(const CommandBufferDescriptor* descriptor); 57 58 // Functions to interact with the encoders 59 void HandleError(const char* message); 60 void ConsumeError(ErrorData* error); ConsumedError(MaybeError maybeError)61 bool ConsumedError(MaybeError maybeError) { 62 if (DAWN_UNLIKELY(maybeError.IsError())) { 63 ConsumeError(maybeError.AcquireError()); 64 return true; 65 } 66 return false; 67 } 68 69 void PassEnded(); 70 71 private: 72 MaybeError ValidateFinish(const CommandBufferDescriptor* descriptor); 73 MaybeError ValidateComputePass(); 74 MaybeError ValidateRenderPass(BeginRenderPassCmd* renderPass); 75 MaybeError ValidateCanRecordTopLevelCommands() const; 76 77 enum class EncodingState : uint8_t; 78 EncodingState mEncodingState; 79 80 void MoveToIterator(); 81 CommandAllocator mAllocator; 82 CommandIterator mIterator; 83 bool mWasMovedToIterator = false; 84 bool mWereCommandsAcquired = false; 85 86 bool mWereResourceUsagesAcquired = false; 87 CommandBufferResourceUsage mResourceUsages; 88 89 unsigned int mDebugGroupStackSize = 0; 90 91 bool mGotError = false; 92 std::string mErrorMessage; 93 }; 94 95 } // namespace dawn_native 96 97 #endif // DAWNNATIVE_COMMANDENCODER_H_ 98