2019-01-29 00:10:07 +00:00
|
|
|
// Copyright 2018 The Dawn Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef DAWNNATIVE_DYNAMICUPLOADER_H_
|
|
|
|
#define DAWNNATIVE_DYNAMICUPLOADER_H_
|
|
|
|
|
|
|
|
#include "dawn_native/Forward.h"
|
2019-09-18 22:06:41 +00:00
|
|
|
#include "dawn_native/RingBufferAllocator.h"
|
|
|
|
#include "dawn_native/StagingBuffer.h"
|
2019-01-29 00:10:07 +00:00
|
|
|
|
|
|
|
// DynamicUploader is the front-end implementation used to manage multiple ring buffers for upload
|
|
|
|
// usage.
|
|
|
|
namespace dawn_native {
|
|
|
|
|
2019-09-18 22:06:41 +00:00
|
|
|
struct UploadHandle {
|
|
|
|
uint8_t* mappedBuffer = nullptr;
|
2019-10-18 16:19:00 +00:00
|
|
|
uint64_t startOffset = 0;
|
2019-09-18 22:06:41 +00:00
|
|
|
StagingBufferBase* stagingBuffer = nullptr;
|
|
|
|
};
|
|
|
|
|
2019-01-29 00:10:07 +00:00
|
|
|
class DynamicUploader {
|
|
|
|
public:
|
2019-10-18 16:19:00 +00:00
|
|
|
DynamicUploader(DeviceBase* device, uint64_t size = kBaseUploadBufferSize);
|
2019-01-29 00:10:07 +00:00
|
|
|
~DynamicUploader() = default;
|
|
|
|
|
2019-09-18 22:06:41 +00:00
|
|
|
// We add functions to Release StagingBuffers to the DynamicUploader as there's
|
2019-06-05 16:16:37 +00:00
|
|
|
// currently no place to track the allocated staging buffers such that they're freed after
|
2019-08-28 16:06:50 +00:00
|
|
|
// pending commands are finished. This should be changed when better resource allocation is
|
2019-06-05 16:16:37 +00:00
|
|
|
// implemented.
|
|
|
|
void ReleaseStagingBuffer(std::unique_ptr<StagingBufferBase> stagingBuffer);
|
|
|
|
|
2019-10-18 16:19:00 +00:00
|
|
|
ResultOrError<UploadHandle> Allocate(uint64_t allocationSize, Serial serial);
|
2019-09-18 22:06:41 +00:00
|
|
|
void Deallocate(Serial lastCompletedSerial);
|
2019-01-29 00:10:07 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-15 21:18:40 +00:00
|
|
|
// TODO(bryan.bernhart@intel.com): Figure out this value.
|
2019-10-18 16:19:00 +00:00
|
|
|
static constexpr uint64_t kBaseUploadBufferSize = 64000;
|
2019-02-15 21:18:40 +00:00
|
|
|
|
2019-09-18 22:06:41 +00:00
|
|
|
struct RingBuffer {
|
|
|
|
std::unique_ptr<StagingBufferBase> mStagingBuffer;
|
|
|
|
RingBufferAllocator mAllocator;
|
|
|
|
};
|
|
|
|
|
2019-01-29 00:10:07 +00:00
|
|
|
std::vector<std::unique_ptr<RingBuffer>> mRingBuffers;
|
2019-06-05 16:16:37 +00:00
|
|
|
SerialQueue<std::unique_ptr<StagingBufferBase>> mReleasedStagingBuffers;
|
2019-01-29 00:10:07 +00:00
|
|
|
DeviceBase* mDevice;
|
|
|
|
};
|
|
|
|
} // namespace dawn_native
|
|
|
|
|
2019-06-05 16:16:37 +00:00
|
|
|
#endif // DAWNNATIVE_DYNAMICUPLOADER_H_
|