Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/dawn/native/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <iterator>

#include "dawn/native/CommandBuffer.h"

#include "dawn/native/Buffer.h"
Expand All @@ -45,6 +47,7 @@ CommandBufferBase::CommandBufferBase(CommandEncoder* encoder,
mCommands(encoder->AcquireCommands()),
mResourceUsages(encoder->AcquireResourceUsages()),
mIndirectDrawMetadata(encoder->AcquireIndirectDrawMetadata()),
mTemporaryTexturesForEarlyDestroy(encoder->AcquireTemporaryTexturesForEarlyDestroy()),
mEncoderLabel(encoder->GetLabel()) {
GetObjectTrackingList()->Track(this);
}
Expand Down Expand Up @@ -105,6 +108,20 @@ const ityp::vector<PassIndex, IndirectDrawMetadata>& CommandBufferBase::GetIndir
return mIndirectDrawMetadata;
}

void CommandBufferBase::ExtractTemporaryTexturesForEarlyDestroy(
std::vector<Ref<TextureBase>>* temporaryTexturesForEarlyDestroy) {
if (mTemporaryTexturesForEarlyDestroy.empty()) {
return;
}

temporaryTexturesForEarlyDestroy->insert(temporaryTexturesForEarlyDestroy->end(),
std::make_move_iterator(
mTemporaryTexturesForEarlyDestroy.begin()),
std::make_move_iterator(
mTemporaryTexturesForEarlyDestroy.end()));
mTemporaryTexturesForEarlyDestroy.clear();
}

CommandIterator* CommandBufferBase::GetCommandIteratorForTesting() {
return &mCommands;
}
Expand Down
3 changes: 3 additions & 0 deletions src/dawn/native/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class CommandBufferBase : public ApiObjectBase {
const CommandBufferResourceUsage& GetResourceUsages() const;

const ityp::vector<PassIndex, IndirectDrawMetadata>& GetIndirectDrawMetadata();
void ExtractTemporaryTexturesForEarlyDestroy(
std::vector<Ref<TextureBase>>* temporaryTexturesForEarlyDestroy);

CommandIterator* GetCommandIteratorForTesting();

Expand All @@ -81,6 +83,7 @@ class CommandBufferBase : public ApiObjectBase {

CommandBufferResourceUsage mResourceUsages;
ityp::vector<PassIndex, IndirectDrawMetadata> mIndirectDrawMetadata;
std::vector<Ref<TextureBase>> mTemporaryTexturesForEarlyDestroy;
std::string mEncoderLabel;
};

Expand Down
8 changes: 8 additions & 0 deletions src/dawn/native/CommandEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,10 +1278,18 @@ CommandIterator CommandEncoder::AcquireCommands() {
return mEncodingContext.AcquireCommands();
}

std::vector<Ref<TextureBase>> CommandEncoder::AcquireTemporaryTexturesForEarlyDestroy() {
return std::move(mTemporaryTexturesForEarlyDestroy);
}

void CommandEncoder::TrackUsedQuerySet(QuerySetBase* querySet) {
mUsedQuerySets.insert(querySet);
}

void CommandEncoder::TrackTemporaryTextureForEarlyDestroy(Ref<TextureBase> texture) {
mTemporaryTexturesForEarlyDestroy.push_back(std::move(texture));
}

ityp::vector<PassIndex, IndirectDrawMetadata> CommandEncoder::AcquireIndirectDrawMetadata() {
return mEncodingContext.AcquireIndirectDrawMetadata();
}
Expand Down
3 changes: 3 additions & 0 deletions src/dawn/native/CommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class CommandEncoder final : public ApiObjectBase {
CommandIterator AcquireCommands();
CommandBufferResourceUsage AcquireResourceUsages();
ityp::vector<PassIndex, IndirectDrawMetadata> AcquireIndirectDrawMetadata();
std::vector<Ref<TextureBase>> AcquireTemporaryTexturesForEarlyDestroy();

void TrackUsedQuerySet(QuerySetBase* querySet);
void TrackTemporaryTextureForEarlyDestroy(Ref<TextureBase> texture);

// Dawn API
ComputePassEncoder* APIBeginComputePass(const ComputePassDescriptor* descriptor);
Expand Down Expand Up @@ -144,6 +146,7 @@ class CommandEncoder final : public ApiObjectBase {
absl::flat_hash_set<BufferBase*> mTopLevelBuffers;
absl::flat_hash_set<TextureBase*> mTopLevelTextures;
absl::flat_hash_set<QuerySetBase*> mUsedQuerySets;
std::vector<Ref<TextureBase>> mTemporaryTexturesForEarlyDestroy;

uint64_t mDebugGroupStackSize = 0;

Expand Down
1 change: 1 addition & 0 deletions src/dawn/native/RenderPassWorkaroundsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ MaybeError RenderPassWorkaroundsHelper::Initialize(
DAWN_ASSERT(device->IsLockedByCurrentThreadIfNeeded());

DAWN_TRY_ASSIGN(temporaryResolveTexture, device->CreateTexture(&descriptor));
encoder->TrackTemporaryTextureForEarlyDestroy(temporaryResolveTexture);

TextureViewDescriptor viewDescriptor = {};
DAWN_TRY_ASSIGN(
Expand Down
21 changes: 19 additions & 2 deletions src/dawn/native/vulkan/QueueVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,23 @@ MaybeError Queue::Initialize() {

MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, "CommandBufferVk::RecordCommands");
DAWN_ASSERT(mPendingTexturesToDestroyOnSubmit.empty());
CommandRecordingContext* recordingContext = GetPendingRecordingContext();
for (uint32_t i = 0; i < commandCount; ++i) {
DAWN_TRY(ToBackend(commands[i])->RecordCommands(recordingContext));
MaybeError recordResult = ToBackend(commands[i])->RecordCommands(recordingContext);
if (recordResult.IsError()) {
mPendingTexturesToDestroyOnSubmit.clear();
return recordResult;
}
commands[i]->ExtractTemporaryTexturesForEarlyDestroy(&mPendingTexturesToDestroyOnSubmit);
}
TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferVk::RecordCommands");

DAWN_TRY(SubmitPendingCommandsImpl());
MaybeError submitResult = SubmitPendingCommandsImpl();
if (submitResult.IsError()) {
mPendingTexturesToDestroyOnSubmit.clear();
return submitResult;
}

return {};
}
Expand Down Expand Up @@ -346,6 +356,13 @@ MaybeError Queue::SubmitPendingCommandsImpl() {
});
TRACE_EVENT_END0(device->GetPlatform(), Recording, "vkQueueSubmit");

// Destroy temporary resolve textures while the pending serial still refers to this submit.
// Otherwise command-buffer teardown schedules their Vulkan memory release on the next serial.
for (auto& texture : mPendingTexturesToDestroyOnSubmit) {
texture->Destroy();
}
mPendingTexturesToDestroyOnSubmit.clear();

// Enqueue the semaphores before incrementing the serial, so that they can be deleted as
// soon as the current submission is finished.
for (VkSemaphore semaphore : mRecordingContext.waitSemaphores) {
Expand Down
1 change: 1 addition & 0 deletions src/dawn/native/vulkan/QueueVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Queue final : public QueueBase {
MutexProtected<std::vector<CommandPoolAndBuffer>> mUnusedCommands;
// There is always a valid recording context stored in mRecordingContext
CommandRecordingContext mRecordingContext;
std::vector<Ref<TextureBase>> mPendingTexturesToDestroyOnSubmit;

uint32_t mQueueFamily = 0;
VkQueue mQueue = VK_NULL_HANDLE;
Expand Down
Loading