Refactor subresource related variables to a struct - backend
This patch put subresource related variables like baseMipLevel, levelCount, baseArrayLayer, layerCount into a single struct at backends. Bug: dawn:157 Change-Id: I50c6bb0ed8ae7a184506c23cab4b64a472bbd75e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23163 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
parent
8a5325ca9a
commit
ee7debf44d
|
@ -163,20 +163,18 @@ namespace dawn_native { namespace d3d12 {
|
||||||
TextureViewBase* view =
|
TextureViewBase* view =
|
||||||
static_cast<TextureViewBase*>(mBindings[index][binding]);
|
static_cast<TextureViewBase*>(mBindings[index][binding]);
|
||||||
ToBackend(view->GetTexture())
|
ToBackend(view->GetTexture())
|
||||||
->TrackUsageAndTransitionNow(
|
->TrackUsageAndTransitionNow(commandContext,
|
||||||
commandContext, kReadonlyStorageTexture,
|
kReadonlyStorageTexture,
|
||||||
view->GetBaseMipLevel(), view->GetLevelCount(),
|
view->GetSubresourceRange());
|
||||||
view->GetBaseArrayLayer(), view->GetLayerCount());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case wgpu::BindingType::WriteonlyStorageTexture: {
|
case wgpu::BindingType::WriteonlyStorageTexture: {
|
||||||
TextureViewBase* view =
|
TextureViewBase* view =
|
||||||
static_cast<TextureViewBase*>(mBindings[index][binding]);
|
static_cast<TextureViewBase*>(mBindings[index][binding]);
|
||||||
ToBackend(view->GetTexture())
|
ToBackend(view->GetTexture())
|
||||||
->TrackUsageAndTransitionNow(
|
->TrackUsageAndTransitionNow(commandContext,
|
||||||
commandContext, wgpu::TextureUsage::Storage,
|
wgpu::TextureUsage::Storage,
|
||||||
view->GetBaseMipLevel(), view->GetLevelCount(),
|
view->GetSubresourceRange());
|
||||||
view->GetBaseArrayLayer(), view->GetLayerCount());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case wgpu::BindingType::StorageTexture:
|
case wgpu::BindingType::StorageTexture:
|
||||||
|
@ -435,14 +433,12 @@ namespace dawn_native { namespace d3d12 {
|
||||||
Texture* resolveTexture = ToBackend(resolveTarget->GetTexture());
|
Texture* resolveTexture = ToBackend(resolveTarget->GetTexture());
|
||||||
|
|
||||||
// Transition the usages of the color attachment and resolve target.
|
// Transition the usages of the color attachment and resolve target.
|
||||||
colorTexture->TrackUsageAndTransitionNow(
|
colorTexture->TrackUsageAndTransitionNow(commandContext,
|
||||||
commandContext, D3D12_RESOURCE_STATE_RESOLVE_SOURCE,
|
D3D12_RESOURCE_STATE_RESOLVE_SOURCE,
|
||||||
colorView->GetBaseMipLevel(), colorView->GetLevelCount(),
|
colorView->GetSubresourceRange());
|
||||||
colorView->GetBaseArrayLayer(), colorView->GetLayerCount());
|
resolveTexture->TrackUsageAndTransitionNow(commandContext,
|
||||||
resolveTexture->TrackUsageAndTransitionNow(
|
D3D12_RESOURCE_STATE_RESOLVE_DEST,
|
||||||
commandContext, D3D12_RESOURCE_STATE_RESOLVE_DEST,
|
resolveTarget->GetSubresourceRange());
|
||||||
resolveTarget->GetBaseMipLevel(), resolveTarget->GetLevelCount(),
|
|
||||||
resolveTarget->GetBaseArrayLayer(), resolveTarget->GetLayerCount());
|
|
||||||
|
|
||||||
// Do MSAA resolve with ResolveSubResource().
|
// Do MSAA resolve with ResolveSubResource().
|
||||||
ID3D12Resource* colorTextureHandle = colorTexture->GetD3D12Resource();
|
ID3D12Resource* colorTextureHandle = colorTexture->GetD3D12Resource();
|
||||||
|
@ -591,8 +587,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
buffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopySrc);
|
buffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopySrc);
|
||||||
texture->TrackUsageAndTransitionNow(commandContext, wgpu::TextureUsage::CopyDst,
|
texture->TrackUsageAndTransitionNow(commandContext, wgpu::TextureUsage::CopyDst,
|
||||||
copy->destination.mipLevel, 1,
|
subresource);
|
||||||
copy->destination.arrayLayer, 1);
|
|
||||||
|
|
||||||
auto copySplit = ComputeTextureCopySplit(
|
auto copySplit = ComputeTextureCopySplit(
|
||||||
copy->destination.origin, copy->copySize, texture->GetFormat(),
|
copy->destination.origin, copy->copySize, texture->GetFormat(),
|
||||||
|
@ -626,13 +621,12 @@ namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D);
|
ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D);
|
||||||
ASSERT(copy->copySize.depth == 1);
|
ASSERT(copy->copySize.depth == 1);
|
||||||
texture->EnsureSubresourceContentInitialized(
|
SubresourceRange subresource = SubresourceRange::SingleSubresource(
|
||||||
commandContext, SubresourceRange::SingleSubresource(
|
copy->source.mipLevel, copy->source.arrayLayer);
|
||||||
copy->source.mipLevel, copy->source.arrayLayer));
|
texture->EnsureSubresourceContentInitialized(commandContext, subresource);
|
||||||
|
|
||||||
texture->TrackUsageAndTransitionNow(commandContext, wgpu::TextureUsage::CopySrc,
|
texture->TrackUsageAndTransitionNow(commandContext, wgpu::TextureUsage::CopySrc,
|
||||||
copy->source.mipLevel, 1,
|
subresource);
|
||||||
copy->source.arrayLayer, 1);
|
|
||||||
buffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
|
buffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
|
||||||
|
|
||||||
TextureCopySplit copySplit = ComputeTextureCopySplit(
|
TextureCopySplit copySplit = ComputeTextureCopySplit(
|
||||||
|
@ -692,12 +686,10 @@ namespace dawn_native { namespace d3d12 {
|
||||||
copy->destination.arrayLayer,
|
copy->destination.arrayLayer,
|
||||||
copy->copySize.depth));
|
copy->copySize.depth));
|
||||||
}
|
}
|
||||||
source->TrackUsageAndTransitionNow(
|
source->TrackUsageAndTransitionNow(commandContext, wgpu::TextureUsage::CopySrc,
|
||||||
commandContext, wgpu::TextureUsage::CopySrc, copy->source.mipLevel, 1,
|
srcRange);
|
||||||
copy->source.arrayLayer, copy->copySize.depth);
|
destination->TrackUsageAndTransitionNow(commandContext,
|
||||||
destination->TrackUsageAndTransitionNow(
|
wgpu::TextureUsage::CopyDst, dstRange);
|
||||||
commandContext, wgpu::TextureUsage::CopyDst, copy->destination.mipLevel, 1,
|
|
||||||
copy->destination.arrayLayer, copy->copySize.depth);
|
|
||||||
|
|
||||||
if (CanUseCopyResource(source, destination, copy->copySize)) {
|
if (CanUseCopyResource(source, destination, copy->copySize)) {
|
||||||
commandList->CopyResource(destination->GetD3D12Resource(),
|
commandList->CopyResource(destination->GetD3D12Resource(),
|
||||||
|
@ -886,10 +878,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
resolveDestinationTexture->TrackUsageAndTransitionNow(
|
resolveDestinationTexture->TrackUsageAndTransitionNow(
|
||||||
commandContext, D3D12_RESOURCE_STATE_RESOLVE_DEST,
|
commandContext, D3D12_RESOURCE_STATE_RESOLVE_DEST,
|
||||||
resolveDestinationView->GetBaseMipLevel(),
|
resolveDestinationView->GetSubresourceRange());
|
||||||
resolveDestinationView->GetLevelCount(),
|
|
||||||
resolveDestinationView->GetBaseArrayLayer(),
|
|
||||||
resolveDestinationView->GetLayerCount());
|
|
||||||
|
|
||||||
renderPassBuilder->SetRenderTargetEndingAccessResolve(i, attachmentInfo.storeOp,
|
renderPassBuilder->SetRenderTargetEndingAccessResolve(i, attachmentInfo.storeOp,
|
||||||
view, resolveDestinationView);
|
view, resolveDestinationView);
|
||||||
|
|
|
@ -549,32 +549,24 @@ namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
void Texture::TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void Texture::TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
wgpu::TextureUsage usage,
|
wgpu::TextureUsage usage,
|
||||||
uint32_t mipLevel,
|
const SubresourceRange& range) {
|
||||||
uint32_t levelCount,
|
TrackUsageAndTransitionNow(commandContext, D3D12TextureUsage(usage, GetFormat()), range);
|
||||||
uint32_t arrayLayer,
|
|
||||||
uint32_t layerCount) {
|
|
||||||
TrackUsageAndTransitionNow(commandContext, D3D12TextureUsage(usage, GetFormat()), mipLevel,
|
|
||||||
levelCount, arrayLayer, layerCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void Texture::TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
wgpu::TextureUsage usage) {
|
wgpu::TextureUsage usage) {
|
||||||
TrackUsageAndTransitionNow(commandContext, D3D12TextureUsage(usage, GetFormat()), 0,
|
TrackUsageAndTransitionNow(commandContext, D3D12TextureUsage(usage, GetFormat()),
|
||||||
GetNumMipLevels(), 0, GetArrayLayers());
|
GetAllSubresources());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void Texture::TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
D3D12_RESOURCE_STATES newState) {
|
D3D12_RESOURCE_STATES newState) {
|
||||||
TrackUsageAndTransitionNow(commandContext, newState, 0, GetNumMipLevels(), 0,
|
TrackUsageAndTransitionNow(commandContext, newState, GetAllSubresources());
|
||||||
GetArrayLayers());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void Texture::TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
D3D12_RESOURCE_STATES newState,
|
D3D12_RESOURCE_STATES newState,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range) {
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount) {
|
|
||||||
if (mResourceAllocation.GetInfo().mMethod != AllocationMethod::kExternal) {
|
if (mResourceAllocation.GetInfo().mMethod != AllocationMethod::kExternal) {
|
||||||
// Track the underlying heap to ensure residency.
|
// Track the underlying heap to ensure residency.
|
||||||
Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap());
|
Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap());
|
||||||
|
@ -582,10 +574,9 @@ namespace dawn_native { namespace d3d12 {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<D3D12_RESOURCE_BARRIER> barriers;
|
std::vector<D3D12_RESOURCE_BARRIER> barriers;
|
||||||
barriers.reserve(levelCount * layerCount);
|
barriers.reserve(range.levelCount * range.layerCount);
|
||||||
|
|
||||||
TransitionUsageAndGetResourceBarrier(commandContext, &barriers, newState, baseMipLevel,
|
TransitionUsageAndGetResourceBarrier(commandContext, &barriers, newState, range);
|
||||||
levelCount, baseArrayLayer, layerCount);
|
|
||||||
if (barriers.size()) {
|
if (barriers.size()) {
|
||||||
commandContext->GetCommandList()->ResourceBarrier(barriers.size(), barriers.data());
|
commandContext->GetCommandList()->ResourceBarrier(barriers.size(), barriers.data());
|
||||||
}
|
}
|
||||||
|
@ -687,17 +678,14 @@ namespace dawn_native { namespace d3d12 {
|
||||||
CommandRecordingContext* commandContext,
|
CommandRecordingContext* commandContext,
|
||||||
std::vector<D3D12_RESOURCE_BARRIER>* barriers,
|
std::vector<D3D12_RESOURCE_BARRIER>* barriers,
|
||||||
D3D12_RESOURCE_STATES newState,
|
D3D12_RESOURCE_STATES newState,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range) {
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount) {
|
|
||||||
HandleTransitionSpecialCases(commandContext);
|
HandleTransitionSpecialCases(commandContext);
|
||||||
|
|
||||||
const Serial pendingCommandSerial = ToBackend(GetDevice())->GetPendingCommandSerial();
|
const Serial pendingCommandSerial = ToBackend(GetDevice())->GetPendingCommandSerial();
|
||||||
for (uint32_t arrayLayer = 0; arrayLayer < layerCount; ++arrayLayer) {
|
for (uint32_t arrayLayer = 0; arrayLayer < range.layerCount; ++arrayLayer) {
|
||||||
for (uint32_t mipLevel = 0; mipLevel < levelCount; ++mipLevel) {
|
for (uint32_t mipLevel = 0; mipLevel < range.levelCount; ++mipLevel) {
|
||||||
uint32_t index =
|
uint32_t index = GetSubresourceIndex(range.baseMipLevel + mipLevel,
|
||||||
GetSubresourceIndex(baseMipLevel + mipLevel, baseArrayLayer + arrayLayer);
|
range.baseArrayLayer + arrayLayer);
|
||||||
|
|
||||||
TransitionSingleSubresource(barriers, newState, index, pendingCommandSerial);
|
TransitionSingleSubresource(barriers, newState, index, pendingCommandSerial);
|
||||||
}
|
}
|
||||||
|
@ -797,9 +785,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
if (GetFormat().isRenderable) {
|
if (GetFormat().isRenderable) {
|
||||||
if (GetFormat().HasDepthOrStencil()) {
|
if (GetFormat().HasDepthOrStencil()) {
|
||||||
TrackUsageAndTransitionNow(commandContext, D3D12_RESOURCE_STATE_DEPTH_WRITE,
|
TrackUsageAndTransitionNow(commandContext, D3D12_RESOURCE_STATE_DEPTH_WRITE, range);
|
||||||
range.baseMipLevel, range.levelCount,
|
|
||||||
range.baseArrayLayer, range.layerCount);
|
|
||||||
|
|
||||||
D3D12_CLEAR_FLAGS clearFlags = {};
|
D3D12_CLEAR_FLAGS clearFlags = {};
|
||||||
|
|
||||||
|
@ -836,8 +822,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TrackUsageAndTransitionNow(commandContext, D3D12_RESOURCE_STATE_RENDER_TARGET,
|
TrackUsageAndTransitionNow(commandContext, D3D12_RESOURCE_STATE_RENDER_TARGET,
|
||||||
range.baseMipLevel, range.levelCount,
|
range);
|
||||||
range.baseArrayLayer, range.layerCount);
|
|
||||||
|
|
||||||
const float clearColorRGBA[4] = {fClearColor, fClearColor, fClearColor,
|
const float clearColorRGBA[4] = {fClearColor, fClearColor, fClearColor,
|
||||||
fClearColor};
|
fClearColor};
|
||||||
|
@ -882,9 +867,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
uploader->Allocate(bufferSize, device->GetPendingCommandSerial()));
|
uploader->Allocate(bufferSize, device->GetPendingCommandSerial()));
|
||||||
memset(uploadHandle.mappedBuffer, clearColor, bufferSize);
|
memset(uploadHandle.mappedBuffer, clearColor, bufferSize);
|
||||||
|
|
||||||
TrackUsageAndTransitionNow(commandContext, D3D12_RESOURCE_STATE_COPY_DEST,
|
TrackUsageAndTransitionNow(commandContext, D3D12_RESOURCE_STATE_COPY_DEST, range);
|
||||||
range.baseMipLevel, range.levelCount, range.baseArrayLayer,
|
|
||||||
range.layerCount);
|
|
||||||
|
|
||||||
for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount;
|
for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount;
|
||||||
++level) {
|
++level) {
|
||||||
|
|
|
@ -63,16 +63,10 @@ namespace dawn_native { namespace d3d12 {
|
||||||
const std::vector<wgpu::TextureUsage>& subresourceUsages);
|
const std::vector<wgpu::TextureUsage>& subresourceUsages);
|
||||||
void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
wgpu::TextureUsage usage,
|
wgpu::TextureUsage usage,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range);
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount);
|
|
||||||
void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
D3D12_RESOURCE_STATES newState,
|
D3D12_RESOURCE_STATES newState,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range);
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount);
|
|
||||||
void TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
wgpu::TextureUsage usage);
|
wgpu::TextureUsage usage);
|
||||||
void TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
void TrackAllUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||||
|
@ -98,10 +92,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
void TransitionUsageAndGetResourceBarrier(CommandRecordingContext* commandContext,
|
void TransitionUsageAndGetResourceBarrier(CommandRecordingContext* commandContext,
|
||||||
std::vector<D3D12_RESOURCE_BARRIER>* barrier,
|
std::vector<D3D12_RESOURCE_BARRIER>* barrier,
|
||||||
D3D12_RESOURCE_STATES newState,
|
D3D12_RESOURCE_STATES newState,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range);
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount);
|
|
||||||
|
|
||||||
void TransitionSingleSubresource(std::vector<D3D12_RESOURCE_BARRIER>* barriers,
|
void TransitionSingleSubresource(std::vector<D3D12_RESOURCE_BARRIER>* barriers,
|
||||||
D3D12_RESOURCE_STATES subresourceNewState,
|
D3D12_RESOURCE_STATES subresourceNewState,
|
||||||
|
|
|
@ -460,9 +460,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
ToBackend(src.buffer)
|
ToBackend(src.buffer)
|
||||||
->TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopySrc);
|
->TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopySrc);
|
||||||
ToBackend(dst.texture)
|
ToBackend(dst.texture)
|
||||||
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopyDst,
|
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopyDst, range);
|
||||||
subresource.mipLevel, 1, subresource.baseArrayLayer,
|
|
||||||
1);
|
|
||||||
VkBuffer srcBuffer = ToBackend(src.buffer)->GetHandle();
|
VkBuffer srcBuffer = ToBackend(src.buffer)->GetHandle();
|
||||||
VkImage dstImage = ToBackend(dst.texture)->GetHandle();
|
VkImage dstImage = ToBackend(dst.texture)->GetHandle();
|
||||||
|
|
||||||
|
@ -485,16 +483,13 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
ASSERT(src.texture->GetDimension() == wgpu::TextureDimension::e2D);
|
ASSERT(src.texture->GetDimension() == wgpu::TextureDimension::e2D);
|
||||||
ASSERT(copy->copySize.depth == 1);
|
ASSERT(copy->copySize.depth == 1);
|
||||||
|
SubresourceRange range = SubresourceRange::SingleSubresource(
|
||||||
|
subresource.mipLevel, subresource.baseArrayLayer);
|
||||||
ToBackend(src.texture)
|
ToBackend(src.texture)
|
||||||
->EnsureSubresourceContentInitialized(
|
->EnsureSubresourceContentInitialized(recordingContext, range);
|
||||||
recordingContext,
|
|
||||||
SubresourceRange::SingleSubresource(subresource.mipLevel,
|
|
||||||
subresource.baseArrayLayer));
|
|
||||||
|
|
||||||
ToBackend(src.texture)
|
ToBackend(src.texture)
|
||||||
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopySrc,
|
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopySrc, range);
|
||||||
subresource.mipLevel, 1, subresource.baseArrayLayer,
|
|
||||||
1);
|
|
||||||
ToBackend(dst.buffer)
|
ToBackend(dst.buffer)
|
||||||
->TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopyDst);
|
->TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopyDst);
|
||||||
|
|
||||||
|
@ -538,10 +533,10 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
ToBackend(src.texture)
|
ToBackend(src.texture)
|
||||||
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopySrc,
|
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopySrc,
|
||||||
src.mipLevel, 1, src.arrayLayer, copy->copySize.depth);
|
srcRange);
|
||||||
ToBackend(dst.texture)
|
ToBackend(dst.texture)
|
||||||
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopyDst,
|
->TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopyDst,
|
||||||
dst.mipLevel, 1, dst.arrayLayer, copy->copySize.depth);
|
dstRange);
|
||||||
|
|
||||||
// In some situations we cannot do texture-to-texture copies with vkCmdCopyImage
|
// In some situations we cannot do texture-to-texture copies with vkCmdCopyImage
|
||||||
// because as Vulkan SPEC always validates image copies with the virtual size of
|
// because as Vulkan SPEC always validates image copies with the virtual size of
|
||||||
|
|
|
@ -213,10 +213,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
const VkImage& image,
|
const VkImage& image,
|
||||||
wgpu::TextureUsage lastUsage,
|
wgpu::TextureUsage lastUsage,
|
||||||
wgpu::TextureUsage usage,
|
wgpu::TextureUsage usage,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range) {
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount) {
|
|
||||||
VkImageMemoryBarrier barrier;
|
VkImageMemoryBarrier barrier;
|
||||||
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
barrier.pNext = nullptr;
|
barrier.pNext = nullptr;
|
||||||
|
@ -226,10 +223,10 @@ namespace dawn_native { namespace vulkan {
|
||||||
barrier.newLayout = VulkanImageLayout(usage, format);
|
barrier.newLayout = VulkanImageLayout(usage, format);
|
||||||
barrier.image = image;
|
barrier.image = image;
|
||||||
barrier.subresourceRange.aspectMask = VulkanAspectMask(format);
|
barrier.subresourceRange.aspectMask = VulkanAspectMask(format);
|
||||||
barrier.subresourceRange.baseMipLevel = baseMipLevel;
|
barrier.subresourceRange.baseMipLevel = range.baseMipLevel;
|
||||||
barrier.subresourceRange.levelCount = levelCount;
|
barrier.subresourceRange.levelCount = range.levelCount;
|
||||||
barrier.subresourceRange.baseArrayLayer = baseArrayLayer;
|
barrier.subresourceRange.baseArrayLayer = range.baseArrayLayer;
|
||||||
barrier.subresourceRange.layerCount = layerCount;
|
barrier.subresourceRange.layerCount = range.layerCount;
|
||||||
|
|
||||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
|
@ -682,9 +679,9 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
if (mExternalState == ExternalState::PendingAcquire) {
|
if (mExternalState == ExternalState::PendingAcquire) {
|
||||||
if (barriers->size() == transitionBarrierStart) {
|
if (barriers->size() == transitionBarrierStart) {
|
||||||
barriers->push_back(BuildMemoryBarrier(GetFormat(), mHandle,
|
barriers->push_back(BuildMemoryBarrier(
|
||||||
wgpu::TextureUsage::None,
|
GetFormat(), mHandle, wgpu::TextureUsage::None, wgpu::TextureUsage::None,
|
||||||
wgpu::TextureUsage::None, 0, 1, 0, 1));
|
SubresourceRange::SingleSubresource(0, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer texture from external queue to graphics queue
|
// Transfer texture from external queue to graphics queue
|
||||||
|
@ -696,9 +693,9 @@ namespace dawn_native { namespace vulkan {
|
||||||
mExternalState = ExternalState::Acquired;
|
mExternalState = ExternalState::Acquired;
|
||||||
} else if (mExternalState == ExternalState::PendingRelease) {
|
} else if (mExternalState == ExternalState::PendingRelease) {
|
||||||
if (barriers->size() == transitionBarrierStart) {
|
if (barriers->size() == transitionBarrierStart) {
|
||||||
barriers->push_back(BuildMemoryBarrier(GetFormat(), mHandle,
|
barriers->push_back(BuildMemoryBarrier(
|
||||||
wgpu::TextureUsage::None,
|
GetFormat(), mHandle, wgpu::TextureUsage::None, wgpu::TextureUsage::None,
|
||||||
wgpu::TextureUsage::None, 0, 1, 0, 1));
|
SubresourceRange::SingleSubresource(0, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer texture from graphics queue to external queue
|
// Transfer texture from graphics queue to external queue
|
||||||
|
@ -727,7 +724,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
void Texture::TransitionFullUsage(CommandRecordingContext* recordingContext,
|
void Texture::TransitionFullUsage(CommandRecordingContext* recordingContext,
|
||||||
wgpu::TextureUsage usage) {
|
wgpu::TextureUsage usage) {
|
||||||
TransitionUsageNow(recordingContext, usage, 0, GetNumMipLevels(), 0, GetArrayLayers());
|
TransitionUsageNow(recordingContext, usage, GetAllSubresources());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::TransitionUsageForPass(CommandRecordingContext* recordingContext,
|
void Texture::TransitionUsageForPass(CommandRecordingContext* recordingContext,
|
||||||
|
@ -756,8 +753,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
}
|
}
|
||||||
|
|
||||||
imageBarriers->push_back(BuildMemoryBarrier(format, mHandle, mSubresourceLastUsages[0],
|
imageBarriers->push_back(BuildMemoryBarrier(format, mHandle, mSubresourceLastUsages[0],
|
||||||
textureUsages.usage, 0, GetNumMipLevels(),
|
textureUsages.usage, GetAllSubresources()));
|
||||||
0, GetArrayLayers()));
|
|
||||||
allLastUsages = mSubresourceLastUsages[0];
|
allLastUsages = mSubresourceLastUsages[0];
|
||||||
allUsages = textureUsages.usage;
|
allUsages = textureUsages.usage;
|
||||||
for (uint32_t i = 0; i < subresourceCount; ++i) {
|
for (uint32_t i = 0; i < subresourceCount; ++i) {
|
||||||
|
@ -779,7 +775,8 @@ namespace dawn_native { namespace vulkan {
|
||||||
}
|
}
|
||||||
imageBarriers->push_back(BuildMemoryBarrier(
|
imageBarriers->push_back(BuildMemoryBarrier(
|
||||||
format, mHandle, mSubresourceLastUsages[index],
|
format, mHandle, mSubresourceLastUsages[index],
|
||||||
textureUsages.subresourceUsages[index], mipLevel, 1, arrayLayer, 1));
|
textureUsages.subresourceUsages[index],
|
||||||
|
SubresourceRange::SingleSubresource(mipLevel, arrayLayer)));
|
||||||
allLastUsages |= mSubresourceLastUsages[index];
|
allLastUsages |= mSubresourceLastUsages[index];
|
||||||
allUsages |= textureUsages.subresourceUsages[index];
|
allUsages |= textureUsages.subresourceUsages[index];
|
||||||
mSubresourceLastUsages[index] = textureUsages.subresourceUsages[index];
|
mSubresourceLastUsages[index] = textureUsages.subresourceUsages[index];
|
||||||
|
@ -799,10 +796,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
void Texture::TransitionUsageNow(CommandRecordingContext* recordingContext,
|
void Texture::TransitionUsageNow(CommandRecordingContext* recordingContext,
|
||||||
wgpu::TextureUsage usage,
|
wgpu::TextureUsage usage,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range) {
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount) {
|
|
||||||
std::vector<VkImageMemoryBarrier> barriers;
|
std::vector<VkImageMemoryBarrier> barriers;
|
||||||
const Format& format = GetFormat();
|
const Format& format = GetFormat();
|
||||||
|
|
||||||
|
@ -816,29 +810,32 @@ namespace dawn_native { namespace vulkan {
|
||||||
// are the same, then we can use one barrier to do state transition for all subresources.
|
// are the same, then we can use one barrier to do state transition for all subresources.
|
||||||
// Note that if the texture has only one mip level and one array slice, it will fall into
|
// Note that if the texture has only one mip level and one array slice, it will fall into
|
||||||
// this category.
|
// this category.
|
||||||
bool isAllSubresourcesCovered = levelCount * layerCount == subresourceCount;
|
bool isAllSubresourcesCovered = range.levelCount * range.layerCount == subresourceCount;
|
||||||
if (mSameLastUsagesAcrossSubresources && isAllSubresourcesCovered) {
|
if (mSameLastUsagesAcrossSubresources && isAllSubresourcesCovered) {
|
||||||
ASSERT(baseMipLevel == 0 && baseArrayLayer == 0);
|
ASSERT(range.baseMipLevel == 0 && range.baseArrayLayer == 0);
|
||||||
if (CanReuseWithoutBarrier(mSubresourceLastUsages[0], usage)) {
|
if (CanReuseWithoutBarrier(mSubresourceLastUsages[0], usage)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
barriers.push_back(BuildMemoryBarrier(format, mHandle, mSubresourceLastUsages[0], usage,
|
barriers.push_back(
|
||||||
0, levelCount, 0, layerCount));
|
BuildMemoryBarrier(format, mHandle, mSubresourceLastUsages[0], usage, range));
|
||||||
allLastUsages = mSubresourceLastUsages[0];
|
allLastUsages = mSubresourceLastUsages[0];
|
||||||
for (uint32_t i = 0; i < subresourceCount; ++i) {
|
for (uint32_t i = 0; i < subresourceCount; ++i) {
|
||||||
mSubresourceLastUsages[i] = usage;
|
mSubresourceLastUsages[i] = usage;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (uint32_t layer = baseArrayLayer; layer < baseArrayLayer + layerCount; ++layer) {
|
for (uint32_t layer = range.baseArrayLayer;
|
||||||
for (uint32_t level = baseMipLevel; level < baseMipLevel + levelCount; ++level) {
|
layer < range.baseArrayLayer + range.layerCount; ++layer) {
|
||||||
|
for (uint32_t level = range.baseMipLevel;
|
||||||
|
level < range.baseMipLevel + range.levelCount; ++level) {
|
||||||
uint32_t index = GetSubresourceIndex(level, layer);
|
uint32_t index = GetSubresourceIndex(level, layer);
|
||||||
|
|
||||||
if (CanReuseWithoutBarrier(mSubresourceLastUsages[index], usage)) {
|
if (CanReuseWithoutBarrier(mSubresourceLastUsages[index], usage)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
barriers.push_back(BuildMemoryBarrier(
|
barriers.push_back(
|
||||||
format, mHandle, mSubresourceLastUsages[index], usage, level, 1, layer, 1));
|
BuildMemoryBarrier(format, mHandle, mSubresourceLastUsages[index], usage,
|
||||||
|
SubresourceRange::SingleSubresource(level, layer)));
|
||||||
allLastUsages |= mSubresourceLastUsages[index];
|
allLastUsages |= mSubresourceLastUsages[index];
|
||||||
mSubresourceLastUsages[index] = usage;
|
mSubresourceLastUsages[index] = usage;
|
||||||
}
|
}
|
||||||
|
@ -866,8 +863,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
uint8_t clearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0 : 1;
|
uint8_t clearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0 : 1;
|
||||||
float fClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.f : 1.f;
|
float fClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.f : 1.f;
|
||||||
|
|
||||||
TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopyDst, range.baseMipLevel,
|
TransitionUsageNow(recordingContext, wgpu::TextureUsage::CopyDst, range);
|
||||||
range.levelCount, range.baseArrayLayer, range.layerCount);
|
|
||||||
if (GetFormat().isRenderable) {
|
if (GetFormat().isRenderable) {
|
||||||
VkImageSubresourceRange imageRange = {};
|
VkImageSubresourceRange imageRange = {};
|
||||||
imageRange.aspectMask = GetVkAspectMask();
|
imageRange.aspectMask = GetVkAspectMask();
|
||||||
|
|
|
@ -69,10 +69,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
void TransitionUsageNow(CommandRecordingContext* recordingContext,
|
void TransitionUsageNow(CommandRecordingContext* recordingContext,
|
||||||
wgpu::TextureUsage usage,
|
wgpu::TextureUsage usage,
|
||||||
uint32_t baseMipLevel,
|
const SubresourceRange& range);
|
||||||
uint32_t levelCount,
|
|
||||||
uint32_t baseArrayLayer,
|
|
||||||
uint32_t layerCount);
|
|
||||||
void TransitionUsageForPass(CommandRecordingContext* recordingContext,
|
void TransitionUsageForPass(CommandRecordingContext* recordingContext,
|
||||||
const PassTextureUsage& textureUsages,
|
const PassTextureUsage& textureUsages,
|
||||||
std::vector<VkImageMemoryBarrier>* imageBarriers,
|
std::vector<VkImageMemoryBarrier>* imageBarriers,
|
||||||
|
|
Loading…
Reference in New Issue