| 423 | } |
| 424 | |
| 425 | Device::Device(const Desc& desc) : mDesc(desc) |
| 426 | { |
| 427 | if (mDesc.enableAftermath) |
| 428 | { |
| 429 | #if FALCOR_HAS_AFTERMATH |
| 430 | // Aftermath is incompatible with debug layers, so lets disable them. |
| 431 | mDesc.enableDebugLayer = false; |
| 432 | enableAftermath(); |
| 433 | #else |
| 434 | logWarning("Falcor was compiled without Aftermath support. Aftermath is disabled"); |
| 435 | #endif |
| 436 | } |
| 437 | |
| 438 | // Create a global slang session passed to GFX and used for compiling programs in ProgramManager. |
| 439 | slang::createGlobalSession(mSlangGlobalSession.writeRef()); |
| 440 | |
| 441 | if (mDesc.type == Type::Default) |
| 442 | mDesc.type = getDefaultDeviceType(); |
| 443 | |
| 444 | #if !FALCOR_HAS_D3D12 |
| 445 | if (mDesc.type == Type::D3D12) |
| 446 | FALCOR_THROW("D3D12 device not supported."); |
| 447 | #endif |
| 448 | #if !FALCOR_HAS_VULKAN |
| 449 | if (mDesc.type == Type::Vulkan) |
| 450 | FALCOR_THROW("Vulkan device not supported."); |
| 451 | #endif |
| 452 | |
| 453 | gfx::IDevice::Desc gfxDesc = {}; |
| 454 | gfxDesc.deviceType = getGfxDeviceType(mDesc.type); |
| 455 | gfxDesc.slang.slangGlobalSession = mSlangGlobalSession; |
| 456 | |
| 457 | // Setup shader cache. |
| 458 | gfxDesc.shaderCache.maxEntryCount = mDesc.maxShaderCacheEntryCount; |
| 459 | if (mDesc.shaderCachePath == "") |
| 460 | { |
| 461 | gfxDesc.shaderCache.shaderCachePath = nullptr; |
| 462 | } |
| 463 | else |
| 464 | { |
| 465 | gfxDesc.shaderCache.shaderCachePath = mDesc.shaderCachePath.c_str(); |
| 466 | // If the supplied shader cache path does not exist, we will need to create it before creating the device. |
| 467 | if (std::filesystem::exists(mDesc.shaderCachePath)) |
| 468 | { |
| 469 | if (!std::filesystem::is_directory(mDesc.shaderCachePath)) |
| 470 | FALCOR_THROW("Shader cache path {} exists and is not a directory", mDesc.shaderCachePath); |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | std::filesystem::create_directories(mDesc.shaderCachePath); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | std::vector<void*> extendedDescs; |
| 479 | // Add extended desc for root parameter attribute. |
| 480 | gfx::D3D12DeviceExtendedDesc extDesc = {}; |
| 481 | extDesc.rootParameterShaderAttributeName = "root"; |
| 482 | extendedDescs.push_back(&extDesc); |