Dawn: update for API changes (Buffer).
CreateBufferMapped() is now CreateBuffer() with a mappedAtCreation flag. MapReadAsync() and MapWriteAsync() are now MapAsync(). Change-Id: I98e8513ed9acf73515b7960d437c1fde5e80c03a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/306536 Commit-Queue: Stephen White <senorblanco@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
5ba6534884
commit
e393c61a15
@ -44,10 +44,9 @@ GrDawnBuffer::GrDawnBuffer(GrDawnGpu* gpu, size_t sizeInBytes, GrGpuBufferType t
|
||||
if (fMappable == Mappable::kNot || fMappable == Mappable::kReadOnly) {
|
||||
fBuffer = this->getDawnGpu()->device().CreateBuffer(&bufferDesc);
|
||||
} else {
|
||||
wgpu::CreateBufferMappedResult result =
|
||||
this->getDawnGpu()->device().CreateBufferMapped(&bufferDesc);
|
||||
fBuffer = result.buffer;
|
||||
fMapPtr = result.data;
|
||||
bufferDesc.mappedAtCreation = true;
|
||||
fBuffer = this->getDawnGpu()->device().CreateBuffer(&bufferDesc);
|
||||
fMapPtr = fBuffer.GetMappedRange();
|
||||
}
|
||||
|
||||
this->registerWithCache(SkBudgeted::kYes);
|
||||
@ -104,27 +103,21 @@ GrDawnGpu* GrDawnBuffer::getDawnGpu() const {
|
||||
return static_cast<GrDawnGpu*>(this->getGpu());
|
||||
}
|
||||
|
||||
static void callback_read(WGPUBufferMapAsyncStatus status,
|
||||
const void* data,
|
||||
uint64_t dataLength,
|
||||
void* userData) {
|
||||
GrDawnBuffer* buffer = static_cast<GrDawnBuffer*>(userData);
|
||||
buffer->setMapPtr(const_cast<void*>(data));
|
||||
static void callback_read(WGPUBufferMapAsyncStatus status, void* userData) {
|
||||
auto buffer = static_cast<GrDawnBuffer*>(userData);
|
||||
buffer->setMapPtr(const_cast<void*>(buffer->get().GetConstMappedRange()));
|
||||
}
|
||||
|
||||
static void callback_write(WGPUBufferMapAsyncStatus status,
|
||||
void* data,
|
||||
uint64_t dataLength,
|
||||
void* userData) {
|
||||
GrDawnBuffer* buffer = static_cast<GrDawnBuffer*>(userData);
|
||||
buffer->setMapPtr(data);
|
||||
static void callback_write(WGPUBufferMapAsyncStatus status, void* userData) {
|
||||
auto buffer = static_cast<GrDawnBuffer*>(userData);
|
||||
buffer->setMapPtr(buffer->get().GetMappedRange());
|
||||
}
|
||||
|
||||
void GrDawnBuffer::mapWriteAsync() {
|
||||
SkASSERT(!this->isMapped());
|
||||
fBuffer.MapWriteAsync(callback_write, this);
|
||||
fBuffer.MapAsync(wgpu::MapMode::Write, 0, 0, callback_write, this);
|
||||
}
|
||||
void GrDawnBuffer::mapReadAsync() {
|
||||
SkASSERT(!this->isMapped());
|
||||
fBuffer.MapReadAsync(callback_read, this);
|
||||
fBuffer.MapAsync(wgpu::MapMode::Read, 0, 0, callback_read, this);
|
||||
}
|
||||
|
@ -561,9 +561,8 @@ bool GrDawnGpu::onCopySurface(GrSurface* dst,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void callback(WGPUBufferMapAsyncStatus status, const void* data, uint64_t dataLength,
|
||||
void* userdata) {
|
||||
(*reinterpret_cast<const void**>(userdata)) = data;
|
||||
static void callback(WGPUBufferMapAsyncStatus status, void* userdata) {
|
||||
*static_cast<bool*>(userdata) = true;
|
||||
}
|
||||
|
||||
bool GrDawnGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int height,
|
||||
@ -600,11 +599,12 @@ bool GrDawnGpu::onReadPixels(GrSurface* surface, int left, int top, int width, i
|
||||
this->getCopyEncoder().CopyTextureToBuffer(&srcTexture, &dstBuffer, ©Size);
|
||||
this->submitToGpu(true);
|
||||
|
||||
const void *readPixelsPtr = nullptr;
|
||||
buf.MapReadAsync(callback, &readPixelsPtr);
|
||||
while (!readPixelsPtr) {
|
||||
bool mapped = false;
|
||||
buf.MapAsync(wgpu::MapMode::Read, 0, 0, callback, &mapped);
|
||||
while (!mapped) {
|
||||
device().Tick();
|
||||
}
|
||||
const void* readPixelsPtr = buf.GetConstMappedRange();
|
||||
|
||||
if (rowBytes == origRowBytes) {
|
||||
memcpy(buffer, readPixelsPtr, origSizeInBytes);
|
||||
|
Loading…
Reference in New Issue
Block a user