-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation of IPipelineCreationAPIDispatcher
Because slang-gfx doesn't provide a fine granularity APIs such that we can time the spirv generation phase and Vulkan pipeline creation phase, we have to use gfx::IPipelineCreationAPIDispatcher callback interface so that the gfx will call it when creating pipeline. We simply call Vulkan pipeline creation inside the callback function and measure the time so that we can get the time of Vulkan driver compiling the spirv code.
- Loading branch information
1 parent
c3493b4
commit a7f71b6
Showing
5 changed files
with
212 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "DeviceWrapper.h" | ||
|
||
|
||
Device::Device() | ||
{ | ||
slang::createGlobalSession(m_slangGlobalSession.writeRef()); | ||
m_pProgramManager = std::make_unique<ProgramManager>(this); | ||
|
||
gfx::IDevice::Desc gfxDesc = {}; | ||
gfxDesc.deviceType = gfx::DeviceType::Vulkan; | ||
gfxDesc.slang.slangGlobalSession = m_slangGlobalSession; | ||
gfxDesc.shaderCache.maxEntryCount = 1000; | ||
gfxDesc.shaderCache.shaderCachePath = nullptr; | ||
|
||
std::vector<void*> extendedDescs; | ||
// Add extended desc for root parameter attribute. | ||
gfx::D3D12DeviceExtendedDesc extDesc = {}; | ||
extDesc.rootParameterShaderAttributeName = "root"; | ||
extendedDescs.push_back(&extDesc); | ||
|
||
gfxDesc.extendedDescCount = extendedDescs.size(); | ||
gfxDesc.extendedDescs = extendedDescs.data(); | ||
|
||
gfx::AdapterList adapters = gfx::gfxGetAdapters(gfxDesc.deviceType); | ||
if (adapters.getCount() == 0) | ||
{ | ||
assert(!"No GPU found"); | ||
} | ||
|
||
// Try to create device on specific GPU. | ||
gfxDesc.adapterLUID = &adapters.getAdapters()[0].luid; | ||
|
||
mpAPIDispatcher.reset(new PipelineCreationAPIDispatcher()); | ||
gfxDesc.apiCommandDispatcher = static_cast<ISlangUnknown*>(mpAPIDispatcher.get()); | ||
|
||
if (SLANG_FAILED(gfx::gfxCreateDevice(&gfxDesc, m_gfxDevice.writeRef()))) | ||
{ | ||
printf("Failed to create device on GPU 0 (%s).", adapters.getAdapters()[0].name); | ||
} | ||
|
||
if (SLANG_FAILED(gfx::gfxSetDebugCallback(&gGFXDebugCallBack))) | ||
{ | ||
printf("Failed to setup debug callback\n"); | ||
} | ||
else | ||
{ | ||
gfx::gfxEnableDebugLayer(); | ||
} | ||
|
||
// Otherwise try create device on any available GPU. | ||
if (!m_gfxDevice) | ||
{ | ||
gfxDesc.adapterLUID = nullptr; | ||
if (SLANG_FAILED(gfx::gfxCreateDevice(&gfxDesc, m_gfxDevice.writeRef()))) | ||
assert(!"Failed to create device"); | ||
} | ||
|
||
gfx::ITransientResourceHeap::Desc transientHeapDesc = {}; | ||
transientHeapDesc.flags = gfx::ITransientResourceHeap::Flags::AllowResizing; | ||
transientHeapDesc.constantBufferSize = 16 * 1024 * 1024; | ||
transientHeapDesc.samplerDescriptorCount = 2048; | ||
transientHeapDesc.uavDescriptorCount = 1000000; | ||
transientHeapDesc.srvDescriptorCount = 1000000; | ||
transientHeapDesc.constantBufferDescriptorCount = 1000000; | ||
transientHeapDesc.accelerationStructureDescriptorCount = 1000000; | ||
if (SLANG_FAILED(m_gfxDevice->createTransientResourceHeap(transientHeapDesc, m_transientResourceHeaps.writeRef()))) { | ||
assert(!"Fail to create transient source heaps"); | ||
} | ||
} | ||
|
||
Device::~Device() | ||
{ | ||
m_pProgramManager.reset(); | ||
m_gfxDevice.setNull(); | ||
m_transientResourceHeaps.setNull(); | ||
mpAPIDispatcher.reset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters