Skip to content

Commit

Permalink
[d3d9] Only add meta image usage after determining layout
Browse files Browse the repository at this point in the history
  • Loading branch information
K0bin authored and doitsujin committed Sep 22, 2024
1 parent c7cf0a7 commit 07e7781
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
25 changes: 16 additions & 9 deletions src/d3d9/d3d9_common_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ namespace dxvk {

DecodeMultiSampleType(m_device->GetDXVKDevice(), m_desc.MultiSample, m_desc.MultisampleQuality, &imageInfo.sampleCount);

// We need SAMPLED_BIT for StretchRect.
// However, StretchRect does not allow stretching for DS formats,
// so unless we need to resolve, it should always hit code paths that only need TRANSFER_BIT.
if (!m_desc.IsAttachmentOnly || !IsDepthStencilFormat(m_desc.Format) || imageInfo.sampleCount != VK_SAMPLE_COUNT_1_BIT)
if (!m_desc.IsAttachmentOnly)
imageInfo.usage |= VK_IMAGE_USAGE_SAMPLED_BIT;

// The image must be marked as mutable if it can be reinterpreted
Expand Down Expand Up @@ -387,7 +384,7 @@ namespace dxvk {
// For some formats, we need to enable render target
// capabilities if available, but these should
// in no way affect the default image layout
imageInfo.usage |= EnableMetaCopyUsage(imageInfo.format, imageInfo.tiling);
imageInfo.usage |= EnableMetaCopyUsage(imageInfo.format, imageInfo.tiling, imageInfo.sampleCount);

// Check if we can actually create the image
if (!CheckImageSupport(&imageInfo, imageInfo.tiling)) {
Expand Down Expand Up @@ -464,7 +461,8 @@ namespace dxvk {

VkImageUsageFlags D3D9CommonTexture::EnableMetaCopyUsage(
VkFormat Format,
VkImageTiling Tiling) const {
VkImageTiling Tiling,
VkSampleCountFlags SampleCount) const {
VkFormatFeatureFlags2 requestedFeatures = 0;

if (Format == VK_FORMAT_D16_UNORM || Format == VK_FORMAT_D32_SFLOAT)
Expand All @@ -473,6 +471,12 @@ namespace dxvk {
if (Format == VK_FORMAT_R16_UNORM || Format == VK_FORMAT_R32_SFLOAT)
requestedFeatures |= VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT;

// We need SAMPLED_BIT for StretchRect.
// However, StretchRect does not allow stretching for DS formats,
// so unless we need to resolve, it should always hit code paths that only need TRANSFER_BIT.
if (!IsDepthStencilFormat(m_desc.Format) || SampleCount != VK_SAMPLE_COUNT_1_BIT)
requestedFeatures |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT;

if (!requestedFeatures)
return 0;

Expand All @@ -482,12 +486,15 @@ namespace dxvk {
requestedFeatures &= Tiling == VK_IMAGE_TILING_OPTIMAL
? properties.optimal
: properties.linear;

VkImageUsageFlags requestedUsage = 0;


if (requestedFeatures & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT)
requestedUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;

if (requestedFeatures & VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT)
requestedUsage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;

if (requestedFeatures & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT)
requestedUsage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

Expand Down
3 changes: 2 additions & 1 deletion src/d3d9/d3d9_common_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ namespace dxvk {

VkImageUsageFlags EnableMetaCopyUsage(
VkFormat Format,
VkImageTiling Tiling) const;
VkImageTiling Tiling,
VkSampleCountFlags SampleCount) const;

D3D9_COMMON_TEXTURE_MAP_MODE DetermineMapMode() const;

Expand Down

0 comments on commit 07e7781

Please sign in to comment.