Skip to content

Commit

Permalink
Minor fixes for formatting and present seperator (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoecker authored May 16, 2024
1 parent cc9606b commit 2aaba74
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 30 deletions.
4 changes: 2 additions & 2 deletions DxDispatch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ target_link_libraries(
wil
d3d12
directml
dxgi
)

if(TARGET_WSL)
Expand Down Expand Up @@ -157,7 +156,8 @@ set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT dxdispatch)

if(WIN32)
if(TARGET_WINDOWS)
target_compile_definitions(dxdispatchImpl PRIVATE DX_PRESENT_SEPARATOR=1)
target_compile_definitions(dxdispatchImpl PRIVATE INCLUDE_DXGI=1)
target_link_libraries(dxdispatchImpl PRIVATE dxgi)
endif()
target_sources(dxdispatchImpl PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/dxdispatchImpl.rc)
target_link_libraries(dxdispatchImpl PRIVATE version.lib)
Expand Down
4 changes: 0 additions & 4 deletions DxDispatch/src/dxdispatch/CommandLineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,11 @@ CommandLineArgs::CommandLineArgs(int argc, char** argv)
"Name used for PIX capture files.",
cxxopts::value<std::string>()->default_value("dxdispatch")
)
#if defined(DX_PRESENT_SEPARATOR)
(
"present_separator",
"Injects present after each full inference pass, giving debugging tools a notion of frames.",
cxxopts::value<bool>()
)
#endif
;

// ONNX OPTIONS
Expand Down Expand Up @@ -369,12 +367,10 @@ CommandLineArgs::CommandLineArgs(int argc, char** argv)
m_disableAgilitySDK = result["disable_agility_sdk"].as<bool>();
}

#if defined(DX_PRESENT_SEPARATOR)
if (result.count("present_separator"))
{
m_presentSeparator = result["present_separator"].as<bool>();
}
#endif

if (result.count("print_hlsl_disassembly"))
{
Expand Down
5 changes: 0 additions & 5 deletions DxDispatch/src/dxdispatch/CommandLineArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ class CommandLineArgs
PixCaptureType GetPixCaptureType() const { return m_pixCaptureType; }
const std::string& PixCaptureName() const { return m_pixCaptureName; }

#if defined(DX_PRESENT_SEPARATOR)
bool GetPresentSeparator() const { return m_presentSeparator; }
#endif

bool GetUavBarrierAfterDispatch() const { return m_uavBarrierAfterDispatch; }
bool GetAliasingBarrierAfterDispatch() const { return m_aliasingBarrierAfterDispatch; }
bool PrintCommands() const { return m_commandPrinting; }
Expand Down Expand Up @@ -90,9 +87,7 @@ class CommandLineArgs
bool m_setStablePowerState = false;
bool m_preferCustomHeaps = true;
bool m_disableAgilitySDK = false;
#if defined(DX_PRESENT_SEPARATOR)
bool m_presentSeparator = false;
#endif
bool m_uavBarrierAfterDispatch = true;
bool m_aliasingBarrierAfterDispatch = false;
DML_FEATURE_LEVEL m_dmlFeatureLevel = DML_FEATURE_LEVEL_5_0;
Expand Down
23 changes: 12 additions & 11 deletions DxDispatch/src/dxdispatch/Device.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include "pch.h"
#include "Device.h"

#if defined(DX_PRESENT_SEPARATOR)
#include <dxgi1_6.h>
#endif

using Microsoft::WRL::ComPtr;

// {0059DA69-B561-43D9-A39B-3355074B1082}
Expand Down Expand Up @@ -63,6 +59,7 @@ Device::Device(
bool disableBackgroundProcessing,
bool setStablePowerState,
bool preferCustomHeaps,
bool usePresentSeparator,
uint32_t maxGpuTimeMeasurements,
std::shared_ptr<PixCaptureHelper> pixCaptureHelper,
std::shared_ptr<D3d12Module> d3dModule,
Expand Down Expand Up @@ -232,8 +229,9 @@ Device::Device(
IID_GRAPHICS_PPV_ARGS(m_queue.ReleaseAndGetAddressOf())));
m_commandListType = queueDesc.Type;

#if defined(DX_PRESENT_SEPARATOR)
#if defined(INCLUDE_DXGI)
// Create dummy swapchain for frame indication
if (usePresentSeparator)
{
ComPtr<IDXGIFactory2> factory;
THROW_IF_FAILED(CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, IID_PPV_ARGS(&factory)));
Expand All @@ -250,8 +248,11 @@ Device::Device(
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
const auto HR = factory->CreateSwapChainForComposition(m_queue.Get(), &desc, nullptr, m_dummySwapChain.GetAddressOf());
THROW_IF_FAILED(HR);
const auto hr = factory->CreateSwapChainForComposition(m_queue.Get(), &desc, nullptr, m_dummySwapChain.GetAddressOf());
if (FAILED(hr))
{
m_logger->LogWarning("Creating dummy swap chain for present seperator failed");
}
}
#endif

Expand Down Expand Up @@ -791,12 +792,12 @@ void Device::ClearShaderCaches()
}
}

#if defined(DX_PRESENT_SEPARATOR)
void Device::DummyPreset()
void Device::DummyPresent()
{
#if defined(INCLUDE_DXGI)
if (m_dummySwapChain)
{
m_dummySwapChain->Present(0, 0);
}
}
#endif
#endif
}
9 changes: 4 additions & 5 deletions DxDispatch/src/dxdispatch/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Device
bool disableBackgroundProcessing,
bool setStablePowerState,
bool preferCustomHeaps,
bool usePresentSeparator,
uint32_t maxGpuTimeMeasurements,
std::shared_ptr<PixCaptureHelper> pixCaptureHelper,
std::shared_ptr<D3d12Module> d3dModule,
Expand Down Expand Up @@ -121,9 +122,7 @@ class Device
static uint32_t GetSizeInBytes(DML_TENSOR_DATA_TYPE dataType);
static DXGI_FORMAT GetDxgiFormatFromDmlTensorDataType(DML_TENSOR_DATA_TYPE dataType);

#if defined(DX_PRESENT_SEPARATOR)
void DummyPreset();
#endif
void DummyPresent();

private:
void EnsureDxcInterfaces();
Expand Down Expand Up @@ -163,7 +162,7 @@ class Device
Microsoft::WRL::ComPtr<IDxcCompiler3> m_dxcCompiler;
#endif

#if defined(DX_PRESENT_SEPARATOR)
Microsoft::WRL::ComPtr<struct IDXGISwapChain1> m_dummySwapChain;
#if defined(INCLUDE_DXGI)
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_dummySwapChain;
#endif
};
4 changes: 1 addition & 3 deletions DxDispatch/src/dxdispatch/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,10 @@ void Executor::operator()(const Model::DispatchCommand& command)
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<size_t>(timeToSleep)));
}

#if defined(DX_PRESENT_SEPARATOR)
if (m_commandLineArgs.GetPresentSeparator())
{
m_device->DummyPreset();
m_device->DummyPresent();
}
#endif
}
}
catch (const std::exception& e)
Expand Down
1 change: 1 addition & 0 deletions DxDispatch/src/dxdispatch/dxDispatchWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ HRESULT DxDispatch::RuntimeClassInitialize(
m_options->DisableBackgroundProcessing(),
m_options->SetStablePowerState(),
m_options->PreferCustomHeaps(),
m_options->GetPresentSeparator(),
m_options->MaxGpuTimeMeasurements(),
m_pixCaptureHelper,
m_d3dModule,
Expand Down
3 changes: 3 additions & 0 deletions DxDispatch/src/dxdispatch/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ using IAdapter = IDXGIAdapter;
#endif
#include <dxcapi.h>
#include <WinPixEventRuntime/pix3.h>
#ifdef INCLUDE_DXGI
#include <dxgi1_6.h>
#endif

#define IGraphicsUnknown IUnknown
#define IID_GRAPHICS_PPV_ARGS IID_PPV_ARGS
Expand Down

0 comments on commit 2aaba74

Please sign in to comment.