1 // Copyright 2018 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_DYNAMICUPLOADER_H_ 16 #define DAWNNATIVE_DYNAMICUPLOADER_H_ 17 18 #include "dawn_native/Forward.h" 19 #include "dawn_native/RingBuffer.h" 20 21 // DynamicUploader is the front-end implementation used to manage multiple ring buffers for upload 22 // usage. 23 namespace dawn_native { 24 25 class DynamicUploader { 26 public: 27 DynamicUploader(DeviceBase* device); 28 ~DynamicUploader() = default; 29 30 // We add functions to Create/Release StagingBuffers to the DynamicUploader as there's 31 // currently no place to track the allocated staging buffers such that they're freed after 32 // pending coommands are finished. This should be changed when better resource allocation is 33 // implemented. 34 ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size); 35 void ReleaseStagingBuffer(std::unique_ptr<StagingBufferBase> stagingBuffer); 36 37 ResultOrError<UploadHandle> Allocate(uint32_t requiredSize, uint32_t alignment); 38 void Tick(Serial lastCompletedSerial); 39 40 RingBuffer* GetLargestBuffer(); 41 42 MaybeError CreateAndAppendBuffer(size_t size = kBaseUploadBufferSize); 43 44 bool IsEmpty() const; 45 46 private: 47 // TODO(bryan.bernhart@intel.com): Figure out this value. 48 static constexpr size_t kBaseUploadBufferSize = 64000; 49 50 std::vector<std::unique_ptr<RingBuffer>> mRingBuffers; 51 SerialQueue<std::unique_ptr<StagingBufferBase>> mReleasedStagingBuffers; 52 DeviceBase* mDevice; 53 }; 54 } // namespace dawn_native 55 56 #endif // DAWNNATIVE_DYNAMICUPLOADER_H_ 57