Implement buffer lazy initialization before CopyBufferToBuffer

This patch implements buffer lazy initialization before
CopyBufferToBuffer() behind the toggle LazyClearBufferOnFirstUse.
- If the source buffer is not initialized, it will be cleared to 0
  before CopyBufferToBuffer().
- If the destination buffer is not initialized and the copy doesn't
  overwrite the whole buffer, it will be cleared to 0 before
  CopyBufferToBuffer(), otherwise the buffer shouldn't be cleared.

BUG=dawn:414
TEST=dawn_end2end_tests

Change-Id: I3d0512c6376a1ed8928e86f8e56fefebc16910fa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24360
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Jiawei Shao
2020-07-09 09:15:22 +00:00
committed by Commit Bot service account
parent d3bf2188aa
commit dab10eae8a
17 changed files with 339 additions and 50 deletions

View File

@@ -51,7 +51,33 @@ namespace dawn_native { namespace opengl {
return std::max(GetSize(), uint64_t(4u));
}
void Buffer::ClearBufferContentsToZero() {
void Buffer::EnsureDataInitialized() {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
return;
}
InitializeToZero();
}
void Buffer::EnsureDataInitializedAsDestination(uint64_t offset, uint64_t size) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
return;
}
if (IsFullBufferRange(offset, size)) {
SetIsDataInitialized();
} else {
InitializeToZero();
}
}
void Buffer::InitializeToZero() {
ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse));
ASSERT(!IsDataInitialized());
@@ -61,9 +87,9 @@ namespace dawn_native { namespace opengl {
const std::vector<uint8_t> clearValues(size, 0u);
device->gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer);
device->gl.BufferSubData(GL_ARRAY_BUFFER, 0, size, clearValues.data());
device->IncrementLazyClearCountForTesting();
SetIsDataInitialized();
device->IncrementLazyClearCountForTesting();
}
bool Buffer::IsMapWritable() const {

View File

@@ -29,7 +29,8 @@ namespace dawn_native { namespace opengl {
GLuint GetHandle() const;
void ClearBufferContentsToZero();
void EnsureDataInitialized();
void EnsureDataInitializedAsDestination(uint64_t offset, uint64_t size);
private:
~Buffer() override;
@@ -44,6 +45,8 @@ namespace dawn_native { namespace opengl {
void* GetMappedPointerImpl() override;
uint64_t GetAppliedSize() const;
void InitializeToZero();
GLuint mBuffer = 0;
void* mMappedData = nullptr;
};

View File

@@ -493,6 +493,10 @@ namespace dawn_native { namespace opengl {
case Command::CopyBufferToBuffer: {
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
ToBackend(copy->source)->EnsureDataInitialized();
ToBackend(copy->destination)
->EnsureDataInitializedAsDestination(copy->destinationOffset, copy->size);
gl.BindBuffer(GL_PIXEL_PACK_BUFFER, ToBackend(copy->source)->GetHandle());
gl.BindBuffer(GL_PIXEL_UNPACK_BUFFER,
ToBackend(copy->destination)->GetHandle());

View File

@@ -44,16 +44,7 @@ namespace dawn_native { namespace opengl {
size_t size) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
// TODO(jiawei.shao@intel.com): use Toggle::LazyClearResourceOnFirstUse when the support of
// buffer lazy initialization is completed.
if (GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse) &&
!buffer->IsDataInitialized()) {
if (buffer->IsFullBufferRange(bufferOffset, size)) {
buffer->SetIsDataInitialized();
} else {
ToBackend(buffer)->ClearBufferContentsToZero();
}
}
ToBackend(buffer)->EnsureDataInitializedAsDestination(bufferOffset, size);
gl.BindBuffer(GL_ARRAY_BUFFER, ToBackend(buffer)->GetHandle());
gl.BufferSubData(GL_ARRAY_BUFFER, bufferOffset, size, data);