67 | 67 |
|
68 | 68 |
virtual void DILIGENT_CALL_TYPE AttachToVulkanDevice(const VkInstance& Instance,
|
69 | 69 |
const VkPhysicalDevice& PhysicalDevice,
|
|
70 |
const VkPhysicalDeviceFeatures& DeviceFeatures,
|
70 | 71 |
const VkDevice& LogicalDevice,
|
71 | 72 |
const VkQueue& Queue,
|
72 | 73 |
uint32_t QueueFamilyIndex,
|
|
300 | 301 |
RayQueryFeats.rayQuery != VK_FALSE, RayTracing2, "Inline ray tracing is");
|
301 | 302 |
// clang-format on
|
302 | 303 |
#undef FeatureSupport
|
|
304 |
#undef ENABLE_FEATURE
|
303 | 305 |
|
304 | 306 |
|
305 | 307 |
// To enable some device extensions you must enable instance extension VK_KHR_get_physical_device_properties2
|
|
542 | 544 |
}
|
543 | 545 |
}
|
544 | 546 |
|
545 | |
void EngineFactoryVkImpl::AttachToVulkanDevice(const VkInstance& Instance,
|
546 | |
const VkPhysicalDevice& PhysicalDevice,
|
547 | |
const VkDevice& LogicalDevice,
|
548 | |
const VkQueue& Queue,
|
549 | |
uint32_t QueueFamilyIndex,
|
550 | |
const EngineVkCreateInfo& EngineCI,
|
551 | |
IRenderDevice** ppDevice,
|
552 | |
IDeviceContext** ppContexts)
|
553 | |
{
|
|
547 |
void EngineFactoryVkImpl::AttachToVulkanDevice(const VkInstance& VkInstance,
|
|
548 |
const VkPhysicalDevice& VkPhysicalDevice,
|
|
549 |
const VkPhysicalDeviceFeatures& PhysicalDeviceFeatures,
|
|
550 |
const VkDevice& VkLogicalDevice,
|
|
551 |
const VkQueue& Queue,
|
|
552 |
uint32_t QueueFamilyIndex,
|
|
553 |
const EngineVkCreateInfo& _EngineCI,
|
|
554 |
IRenderDevice** ppDevice,
|
|
555 |
IDeviceContext** ppContexts)
|
|
556 |
{
|
|
557 |
EngineVkCreateInfo EngineCI = _EngineCI;
|
|
558 |
|
554 | 559 |
auto& RawMemAllocator = GetRawAllocator();
|
555 | 560 |
|
556 | |
auto VulkanInstance = VulkanUtilities::VulkanInstance::Create(Instance, nullptr);
|
557 | |
auto VulkanPhysicalDevice = VulkanUtilities::VulkanPhysicalDevice::Create(PhysicalDevice, *VulkanInstance);
|
558 | |
|
559 | |
VkPipelineStageFlags PipelineStages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT;
|
560 | |
auto VulkanLogicalDevice = VulkanUtilities::VulkanLogicalDevice::Create(*VulkanPhysicalDevice, LogicalDevice, PipelineStages, nullptr);
|
|
561 |
auto Instance = VulkanUtilities::VulkanInstance::Create(VkInstance, reinterpret_cast<VkAllocationCallbacks*>(EngineCI.pVkAllocator));
|
|
562 |
auto vkAllocator = Instance->GetVkAllocator();
|
|
563 |
|
|
564 |
auto PhysicalDevice = VulkanUtilities::VulkanPhysicalDevice::Create(VkPhysicalDevice, *Instance);
|
|
565 |
auto LogicalDevice = VulkanUtilities::VulkanLogicalDevice::Create(*PhysicalDevice, VkLogicalDevice, PhysicalDeviceFeatures, vkAllocator);
|
|
566 |
|
|
567 |
auto GetFeatureState = [](DEVICE_FEATURE_STATE RequestedState, bool IsFeatureSupported, const char* FeatureName)
|
|
568 |
{
|
|
569 |
switch (RequestedState)
|
|
570 |
{
|
|
571 |
case DEVICE_FEATURE_STATE_DISABLED:
|
|
572 |
return DEVICE_FEATURE_STATE_DISABLED;
|
|
573 |
|
|
574 |
case DEVICE_FEATURE_STATE_ENABLED:
|
|
575 |
{
|
|
576 |
if (IsFeatureSupported)
|
|
577 |
return DEVICE_FEATURE_STATE_ENABLED;
|
|
578 |
else
|
|
579 |
LOG_ERROR_AND_THROW(FeatureName, " not supported by this device");
|
|
580 |
}
|
|
581 |
|
|
582 |
case DEVICE_FEATURE_STATE_OPTIONAL:
|
|
583 |
return IsFeatureSupported ? DEVICE_FEATURE_STATE_ENABLED : DEVICE_FEATURE_STATE_DISABLED;
|
|
584 |
|
|
585 |
default:
|
|
586 |
UNEXPECTED("Unexpected feature state");
|
|
587 |
return DEVICE_FEATURE_STATE_DISABLED;
|
|
588 |
}
|
|
589 |
};
|
|
590 |
|
|
591 |
#define ENABLE_FEATURE(vkFeature, State, FeatureName) \
|
|
592 |
do \
|
|
593 |
{ \
|
|
594 |
State = \
|
|
595 |
GetFeatureState(State, PhysicalDeviceFeatures.vkFeature != VK_FALSE, FeatureName); \
|
|
596 |
} while (false)
|
|
597 |
auto ImageCubeArrayFeature = DEVICE_FEATURE_STATE_OPTIONAL;
|
|
598 |
auto SamplerAnisotropyFeature = DEVICE_FEATURE_STATE_OPTIONAL;
|
|
599 |
// clang-format off
|
|
600 |
ENABLE_FEATURE(geometryShader, EngineCI.Features.GeometryShaders, "Geometry shaders are");
|
|
601 |
ENABLE_FEATURE(tessellationShader, EngineCI.Features.Tessellation, "Tessellation is");
|
|
602 |
ENABLE_FEATURE(pipelineStatisticsQuery, EngineCI.Features.PipelineStatisticsQueries, "Pipeline statistics queries are");
|
|
603 |
ENABLE_FEATURE(occlusionQueryPrecise, EngineCI.Features.OcclusionQueries, "Occlusion queries are");
|
|
604 |
ENABLE_FEATURE(imageCubeArray, ImageCubeArrayFeature, "Image cube arrays are");
|
|
605 |
ENABLE_FEATURE(fillModeNonSolid, EngineCI.Features.WireframeFill, "Wireframe fill is");
|
|
606 |
ENABLE_FEATURE(samplerAnisotropy, SamplerAnisotropyFeature, "Anisotropic texture filtering is");
|
|
607 |
ENABLE_FEATURE(depthBiasClamp, EngineCI.Features.DepthBiasClamp, "Depth bias clamp is");
|
|
608 |
ENABLE_FEATURE(depthClamp, EngineCI.Features.DepthClamp, "Depth clamp is");
|
|
609 |
ENABLE_FEATURE(independentBlend, EngineCI.Features.IndependentBlend, "Independent blend is");
|
|
610 |
ENABLE_FEATURE(dualSrcBlend, EngineCI.Features.DualSourceBlend, "Dual-source blend is");
|
|
611 |
ENABLE_FEATURE(multiViewport, EngineCI.Features.MultiViewport, "Multiviewport is");
|
|
612 |
ENABLE_FEATURE(textureCompressionBC, EngineCI.Features.TextureCompressionBC, "BC texture compression is");
|
|
613 |
ENABLE_FEATURE(vertexPipelineStoresAndAtomics, EngineCI.Features.VertexPipelineUAVWritesAndAtomics, "Vertex pipeline UAV writes and atomics are");
|
|
614 |
ENABLE_FEATURE(fragmentStoresAndAtomics, EngineCI.Features.PixelUAVWritesAndAtomics, "Pixel UAV writes and atomics are");
|
|
615 |
ENABLE_FEATURE(shaderStorageImageExtendedFormats, EngineCI.Features.TextureUAVExtendedFormats, "Texture UAV extended formats are");
|
|
616 |
// clang-format on
|
|
617 |
#undef ENABLE_FEATURE
|
|
618 |
|
561 | 619 |
RefCntAutoPtr<CommandQueueVkImpl> pCmdQueueVk{
|
562 | |
NEW_RC_OBJ(RawMemAllocator, "CommandQueueVk instance", CommandQueueVkImpl)(VulkanLogicalDevice, Queue, QueueFamilyIndex)};
|
|
620 |
NEW_RC_OBJ(RawMemAllocator, "CommandQueueVk instance", CommandQueueVkImpl)(LogicalDevice, Queue, QueueFamilyIndex)};
|
563 | 621 |
std::array<ICommandQueueVk*, 1> CommandQueues = {{pCmdQueueVk}};
|
564 | 622 |
|
565 | 623 |
OnRenderDeviceCreated = [&](RenderDeviceVkImpl* pRenderDeviceVk)
|
|
574 | 632 |
};
|
575 | 633 |
|
576 | 634 |
AttachToVulkanDevice(
|
577 | |
VulkanInstance,
|
578 | |
std::move(VulkanPhysicalDevice),
|
579 | |
VulkanLogicalDevice,
|
|
635 |
Instance,
|
|
636 |
std::move(PhysicalDevice),
|
|
637 |
LogicalDevice,
|
580 | 638 |
CommandQueues.size(), CommandQueues.data(),
|
581 | 639 |
EngineCI,
|
582 | 640 |
ppDevice,
|