Skip to content

Commit be73a46

Browse files
Vulkan: enable host image copy if supported, but only initialize textures on UMA
1 parent 54da9eb commit be73a46

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

Graphics/GraphicsEngine/include/RenderDeviceBase.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ DeviceFeatures EnableDeviceFeatures(const DeviceFeatures& SupportedFeatures,
7373
const DeviceFeatures& RequestedFeatures) noexcept(false);
7474

7575
DeviceFeaturesVk EnableDeviceFeaturesVk(const DeviceFeaturesVk& SupportedFeatures,
76-
const DeviceFeaturesVk& RequestedFeatures,
77-
bool IsUMA) noexcept(false);
76+
const DeviceFeaturesVk& RequestedFeatures) noexcept(false);
7877

7978
/// Checks sparse texture format support and returns the component type
8079
COMPONENT_TYPE CheckSparseTextureFormatSupport(TEXTURE_FORMAT TexFormat,

Graphics/GraphicsEngine/src/RenderDeviceBase.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,12 @@ DeviceFeatures EnableDeviceFeatures(const DeviceFeatures& SupportedFeatures,
128128
}
129129

130130
DeviceFeaturesVk EnableDeviceFeaturesVk(const DeviceFeaturesVk& SupportedFeatures,
131-
const DeviceFeaturesVk& RequestedFeatures,
132-
bool IsUMA) noexcept(false)
131+
const DeviceFeaturesVk& RequestedFeatures) noexcept(false)
133132
{
134133
DeviceFeaturesVk EnabledFeatures;
135134

136135
ENABLE_FEATURE(DynamicRendering, "VK_KHR_dynamic_rendering is");
137-
if (RequestedFeatures.HostImageCopy == DEVICE_FEATURE_STATE_OPTIONAL && SupportedFeatures.HostImageCopy != DEVICE_FEATURE_STATE_DISABLED)
138-
{
139-
// Only enable VK_EXT_host_image_copy if the device is UMA.
140-
// On discrete GPUs, textures with VK_IMAGE_USAGE_HOST_TRANSFER_BIT usage are allocated in a host-visible
141-
// device local memory that is very scarce.
142-
EnabledFeatures.HostImageCopy = IsUMA ? DEVICE_FEATURE_STATE_ENABLED : DEVICE_FEATURE_STATE_DISABLED;
143-
}
144-
else
145-
{
146-
ENABLE_FEATURE(HostImageCopy, "VK_EXT_host_image_copy is");
147-
}
136+
ENABLE_FEATURE(HostImageCopy, "VK_EXT_host_image_copy is");
148137

149138
ASSERT_SIZEOF(DeviceFeaturesVk, 2, "Did you add a new feature to DeviceFeaturesVk? Please handle its status here (if necessary).");
150139

Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En
754754
VerifyEngineCreateInfo(EngineCI, AdapterInfo);
755755
const DeviceFeatures EnabledFeatures = EnableDeviceFeatures(AdapterInfo.Features, EngineCI.Features);
756756
const DeviceFeaturesVk AdapterFeaturesVk = PhysicalDeviceFeaturesToDeviceFeaturesVk(PhysicalDevice->GetExtFeatures(), DEVICE_FEATURE_STATE_OPTIONAL);
757-
const DeviceFeaturesVk EnabledFeaturesVk = EnableDeviceFeaturesVk(AdapterFeaturesVk, EngineCI.FeaturesVk, PhysicalDevice->IsUMA());
757+
const DeviceFeaturesVk EnabledFeaturesVk = EnableDeviceFeaturesVk(AdapterFeaturesVk, EngineCI.FeaturesVk);
758758

759759
std::vector<VkDeviceQueueGlobalPriorityCreateInfoEXT> QueueGlobalPriority;
760760
std::vector<VkDeviceQueueCreateInfo> QueueInfos;

Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,20 @@ VkImageLayout VkImageLayoutFromUsage(VkImageUsageFlags Usage)
170170
return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
171171
}
172172

173-
bool CheckHostImageCopySupport(const VulkanUtilities::VulkanLogicalDevice& LogicalDevice,
174-
const VulkanUtilities::VulkanPhysicalDevice& PhysicalDevice,
175-
const VkImageCreateInfo& ImageCI)
173+
bool CheckHostImageInitialization(const VulkanUtilities::VulkanLogicalDevice& LogicalDevice,
174+
const VulkanUtilities::VulkanPhysicalDevice& PhysicalDevice,
175+
const VkImageCreateInfo& ImageCI)
176176
{
177177
if (!LogicalDevice.GetEnabledExtFeatures().HostImageCopy.hostImageCopy)
178178
return false;
179179

180+
if (!PhysicalDevice.IsUMA())
181+
{
182+
// On discrete GPUs, textures with VK_IMAGE_USAGE_HOST_TRANSFER_BIT usage are allocated in a host-visible
183+
// device-local memory that is very scarce.
184+
return false;
185+
}
186+
180187
VkFormatProperties3 vkFormatProps3{};
181188
VkFormatProperties VkFormatProps = PhysicalDevice.GetPhysicalDeviceFormatProperties(ImageCI.format, &vkFormatProps3);
182189
(void)VkFormatProps;
@@ -236,9 +243,9 @@ TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters,
236243

237244
VkImageCreateInfo ImageCI = TextureDescToVkImageCreateInfo(m_Desc, pRenderDeviceVk);
238245

239-
const bool InitContent = pInitData != nullptr && pInitData->pSubResources != nullptr && pInitData->NumSubresources > 0;
240-
const bool UseHostImageCopy = InitContent && CheckHostImageCopySupport(LogicalDevice, pRenderDeviceVk->GetPhysicalDevice(), ImageCI);
241-
if (UseHostImageCopy)
246+
const bool InitContent = pInitData != nullptr && pInitData->pSubResources != nullptr && pInitData->NumSubresources > 0;
247+
const bool UseHostInitialization = InitContent && CheckHostImageInitialization(LogicalDevice, pRenderDeviceVk->GetPhysicalDevice(), ImageCI);
248+
if (UseHostInitialization)
242249
ImageCI.usage |= VK_IMAGE_USAGE_HOST_TRANSFER_BIT;
243250

244251
const std::vector<uint32_t> QueueFamilyIndices = PlatformMisc::CountOneBits(m_Desc.ImmediateContextMask) > 1 ?
@@ -288,7 +295,7 @@ TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters,
288295
if (InitContent)
289296
{
290297
bool InitializedOnHost = false;
291-
if (UseHostImageCopy)
298+
if (UseHostInitialization)
292299
{
293300
InitializedOnHost = InitializeContentOnHost(*pInitData, FmtAttribs, ImageCI);
294301
}

0 commit comments

Comments
 (0)