Skip to content

Commit

Permalink
[d3d9] Use image transition instead of copies for hazardous resources
Browse files Browse the repository at this point in the history
  • Loading branch information
misyltoad committed Jun 15, 2019
1 parent cd44deb commit 88e5369
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
8 changes: 0 additions & 8 deletions src/d3d9/d3d9_common_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@ namespace dxvk {
if (likely(m_views.Hazardous))
return true;

DxvkImageCreateInfo imageInfo = m_image->info();
imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL;

Rc<DxvkImage> newImage = m_device->GetDXVKDevice()->createImage(imageInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
m_device->CopyImage(m_image, newImage);
m_image = newImage;

m_views.Hazardous = true;

return false;
}

Expand Down
39 changes: 17 additions & 22 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4025,7 +4025,9 @@ namespace dxvk {
continue;

if (tex == rt) {
if (tex->MarkHazardous()) {
if (tex->MarkHazardous() && tex->GetImage()->info().layout != VK_IMAGE_LAYOUT_GENERAL) {
TransitionImage(tex, tex->GetImage()->info().layout, VK_IMAGE_LAYOUT_GENERAL);

BindTexture(i);
m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
}
Expand Down Expand Up @@ -4868,29 +4870,22 @@ namespace dxvk {
}


void D3D9DeviceEx::CopyImage(Rc<DxvkImage> srcImage, Rc<DxvkImage> dstImage) {
const DxvkFormatInfo* dstFormatInfo = imageFormatInfo(dstImage->info().format);
const DxvkFormatInfo* srcFormatInfo = imageFormatInfo(srcImage->info().format);
void D3D9DeviceEx::TransitionImage(D3D9CommonTexture* pResource, VkImageLayout OldLayout, VkImageLayout NewLayout) {
Rc<DxvkImage> image = pResource->GetImage();
const DxvkFormatInfo* formatInfo = imageFormatInfo(image->info().format);

for (uint32_t i = 0; i < srcImage->info().mipLevels; i++) {
VkImageSubresourceLayers dstLayers = { dstFormatInfo->aspectMask, i, 0, dstImage->info().numLayers };
VkImageSubresourceLayers srcLayers = { srcFormatInfo->aspectMask, i, 0, srcImage->info().numLayers };
VkImageSubresourceRange range = { formatInfo->aspectMask, 0, image->info().mipLevels, 0, image->info().numLayers };

VkExtent3D extent = srcImage->mipLevelExtent(i);

EmitCs([
cDstImage = dstImage,
cSrcImage = srcImage,
cDstLayers = dstLayers,
cSrcLayers = srcLayers,
cExtent = extent
] (DxvkContext* ctx) {
ctx->copyImage(
cDstImage, cDstLayers, VkOffset3D { 0, 0, 0 },
cSrcImage, cSrcLayers, VkOffset3D { 0, 0, 0 },
cExtent);
});
}
EmitCs([
cImage = image,
cSubresources = range,
cOldLayout = OldLayout,
cNewLayout = NewLayout
] (DxvkContext* ctx) {
ctx->transformImage(
cImage, cSubresources,
cOldLayout, cNewLayout);
});
}

}
2 changes: 1 addition & 1 deletion src/d3d9/d3d9_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ namespace dxvk {

void ResolveZ();

void CopyImage(Rc<DxvkImage> srcImage, Rc<DxvkImage> dstImage);
void TransitionImage(D3D9CommonTexture* pResource, VkImageLayout OldLayout, VkImageLayout NewLayout);

private:

Expand Down

0 comments on commit 88e5369

Please sign in to comment.