mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 17:35:30 +00:00
Implement Buffer::MapAsync
MapAsync in dawn_native is fully implemented and only missing a couple cleanups that can be done once MapRead/WriteAsync are removed. MapAsync in dawn_wire is left as a pure shim on top of MapRead/WriteAsync and will be transitioned to its own commands in follow-ups. All MapRead/WriteAsync end2end and validation tests are duplicated for MapAsync. Bug: dawn:445 Change-Id: Ib1430b9257149917be19a84f13e0ddd2a8eccc32 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24260 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
92f501dbfd
commit
0d52f800a1
@@ -125,7 +125,37 @@ namespace dawn_native { namespace opengl {
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) {
|
||||
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
|
||||
|
||||
// It is an error to map an empty range in OpenGL. We always have at least a 4-byte buffer
|
||||
// so we extend the range to be 4 bytes.
|
||||
if (size == 0) {
|
||||
if (offset != 0) {
|
||||
offset -= 4;
|
||||
}
|
||||
size = 4;
|
||||
}
|
||||
|
||||
// TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high
|
||||
// version of OpenGL that would let us map the buffer unsynchronized.
|
||||
gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||
void* mappedData = nullptr;
|
||||
if (mode & wgpu::MapMode::Read) {
|
||||
mappedData = gl.MapBufferRange(GL_ARRAY_BUFFER, offset, size, GL_MAP_READ_BIT);
|
||||
} else {
|
||||
ASSERT(mode & wgpu::MapMode::Write);
|
||||
mappedData = gl.MapBufferRange(GL_ARRAY_BUFFER, offset, size, GL_MAP_WRITE_BIT);
|
||||
}
|
||||
|
||||
// The frontend asks that the pointer returned by GetMappedPointerImpl is from the start of
|
||||
// the resource but OpenGL gives us the pointer at offset. Remove the offset.
|
||||
mMappedData = static_cast<uint8_t*>(mappedData) - offset;
|
||||
return {};
|
||||
}
|
||||
|
||||
void* Buffer::GetMappedPointerImpl() {
|
||||
// The mapping offset has already been removed.
|
||||
return mMappedData;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace dawn_native { namespace opengl {
|
||||
// Dawn API
|
||||
MaybeError MapReadAsyncImpl() override;
|
||||
MaybeError MapWriteAsyncImpl() override;
|
||||
MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override;
|
||||
void UnmapImpl() override;
|
||||
void DestroyImpl() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user