Skip to content

Commit

Permalink
fallback swapchain
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGengYF committed Dec 19, 2024
1 parent 9542f6b commit 63e2587
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/backends/dx/DXApi/LCSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ LCSwapChain::LCSwapChain(
nullptr,
nullptr,
&localSwap));
swapChain = DxPtr(static_cast<IDXGISwapChain4 *>(localSwap), true);

swapChain = DxPtr(static_cast<IDXGISwapChain3*>(localSwap), true);
}
for (uint32_t n = 0; n < frameCount; n++) {
ThrowIfFailed(swapChain->GetBuffer(n, IID_PPV_ARGS(&m_renderTargets[n].rt)));
Expand Down
2 changes: 1 addition & 1 deletion src/backends/dx/DXApi/LCSwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace lc::dx {
class LCSwapChain : public Resource {
public:
vstd::vector<SwapChain> m_renderTargets;
DxPtr<IDXGISwapChain4> swapChain;
DxPtr<IDXGISwapChain3> swapChain;
uint64 frameIndex = 0;
DXGI_FORMAT format;
bool vsync;
Expand Down
43 changes: 23 additions & 20 deletions src/backends/dx/DXApi/dx_hdr_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ DXHDRExt::DisplayCurve EnsureSwapChainColorSpace(
}
DXHDRExt::DisplayChromaticities SetHDRMetaData(
DXGI_COLOR_SPACE_TYPE &colorSpace,
LCSwapChain *swapchain,
IDXGISwapChain4 *swapchain,
DXGI_FORMAT format,
bool hdr_support,
float MaxOutputNits /*=1000.0f*/,
float MinOutputNits /*=0.001f*/,
Expand All @@ -56,7 +57,7 @@ DXHDRExt::DisplayChromaticities SetHDRMetaData(

// Clean the hdr metadata if the display doesn't support HDR
if (!hdr_support) {
ThrowIfFailed(swapchain->swapChain->SetHDRMetaData(DXGI_HDR_METADATA_TYPE_NONE, 0, nullptr));
ThrowIfFailed(swapchain->SetHDRMetaData(DXGI_HDR_METADATA_TYPE_NONE, 0, nullptr));
return {};
}

Expand All @@ -68,7 +69,7 @@ DXHDRExt::DisplayChromaticities SetHDRMetaData(

// Select the chromaticity based on HDR format of the DWM.
DXHDRExt::SwapChainBitDepth hitDepth;
switch (swapchain->format) {
switch (format) {
case DXGI_FORMAT_R10G10B10A2_TYPELESS:
case DXGI_FORMAT_R10G10B10A2_UNORM:
case DXGI_FORMAT_R10G10B10A2_UINT:
Expand All @@ -88,15 +89,15 @@ DXHDRExt::DisplayChromaticities SetHDRMetaData(
break;
}

EnsureSwapChainColorSpace(swapchain->swapChain, colorSpace, hitDepth, hdr_support);
EnsureSwapChainColorSpace(swapchain, colorSpace, hitDepth, hdr_support);
int selectedChroma = 0;
if (swapchain->format == DXGI_FORMAT_R16G16B16A16_FLOAT && colorSpace == DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709) {
if (format == DXGI_FORMAT_R16G16B16A16_FLOAT && colorSpace == DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709) {
selectedChroma = 0;
} else if (hitDepth == DXHDRExt::SwapChainBitDepth::_10 && colorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) {
selectedChroma = 1;
} else {
// Reset the metadata since this is not a supported HDR format.
ThrowIfFailed(swapchain->swapChain->SetHDRMetaData(DXGI_HDR_METADATA_TYPE_NONE, 0, nullptr));
ThrowIfFailed(swapchain->SetHDRMetaData(DXGI_HDR_METADATA_TYPE_NONE, 0, nullptr));
return {};
}

Expand All @@ -116,7 +117,7 @@ DXHDRExt::DisplayChromaticities SetHDRMetaData(
HDR10MetaData.MinMasteringLuminance = static_cast<UINT>(MinOutputNits * 10000.0f);
HDR10MetaData.MaxContentLightLevel = static_cast<UINT16>(MaxCLL);
HDR10MetaData.MaxFrameAverageLightLevel = static_cast<UINT16>(MaxFALL);
ThrowIfFailed(swapchain->swapChain->SetHDRMetaData(DXGI_HDR_METADATA_TYPE_HDR10, sizeof(DXGI_HDR_METADATA_HDR10), &HDR10MetaData));
ThrowIfFailed(swapchain->SetHDRMetaData(DXGI_HDR_METADATA_TYPE_HDR10, sizeof(DXGI_HDR_METADATA_HDR10), &HDR10MetaData));
return *Chroma;
}
}// namespace dx_hdr_ext_detail
Expand Down Expand Up @@ -154,18 +155,20 @@ auto DXHDRExtImpl::set_hdr_meta_data(
float max_cll,
float max_fall,
const DXHDRExt::DisplayChromaticities *custom_chroma) noexcept -> Meta {
DXGI_COLOR_SPACE_TYPE color_space = DXGI_COLOR_SPACE_CUSTOM;
auto chroma = dx_hdr_ext_detail::SetHDRMetaData(
color_space,
reinterpret_cast<LCSwapChain *>(swapchain_handle),
true,
max_output_nits,
min_output_nits,
max_cll,
max_fall,
custom_chroma);
return {
static_cast<ColorSpace>(color_space),
chroma};
// DXGI_COLOR_SPACE_TYPE color_space = DXGI_COLOR_SPACE_CUSTOM;
// auto chroma = dx_hdr_ext_detail::SetHDRMetaData(
// color_space,
// reinterpret_cast<LCSwapChain *>(swapchain_handle),
// true,
// max_output_nits,
// min_output_nits,
// max_cll,
// max_fall,
// custom_chroma);
// return {
// static_cast<ColorSpace>(color_space),
// chroma};
LUISA_ERROR("Not implemented.");
return {};
}
}// namespace lc::dx
2 changes: 1 addition & 1 deletion src/backends/dx/DXRuntime/CommandAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void CommandAllocator::Execute(
}
}
}
void CommandAllocator::ExecuteAndPresent(CommandQueue *queue, ID3D12Fence *fence, uint64 fenceIndex, IDXGISwapChain4 *swapchain, bool vsync) {
void CommandAllocator::ExecuteAndPresent(CommandQueue *queue, ID3D12Fence *fence, uint64 fenceIndex, IDXGISwapChain1 *swapchain, bool vsync) {
auto present = [&]() {
if (vsync) {
ThrowIfFailed(swapchain->Present(1, 0));
Expand Down
2 changes: 1 addition & 1 deletion src/backends/dx/DXRuntime/CommandAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CommandAllocator final : public vstd::IOperatorNewBase {
~CommandAllocator();
CommandBuffer *GetBuffer() const;
void Execute(CommandQueue *queue, ID3D12Fence *fence, uint64 fenceIndex);
void ExecuteAndPresent(CommandQueue *queue, ID3D12Fence *fence, uint64 fenceIndex, IDXGISwapChain4 *swapchain, bool vsync);
void ExecuteAndPresent(CommandQueue *queue, ID3D12Fence *fence, uint64 fenceIndex, IDXGISwapChain1 *swapchain, bool vsync);
void Complete(CommandQueue *queue, ID3D12Fence *fence, uint64 fenceIndex);
DefaultBuffer const *AllocateScratchBuffer(size_t targetSize);
BufferView GetTempReadbackBuffer(uint64 size, size_t align = 0);
Expand Down
2 changes: 1 addition & 1 deletion src/backends/dx/DXRuntime/CommandQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void CommandQueue::ExecuteEmptyCallbacks(AllocatorPtr &&alloc, vstd::vector<vstd
waitCv.notify_one();
}

void CommandQueue::ExecuteAndPresent(AllocatorPtr &&alloc, IDXGISwapChain4 *swapChain, bool vsync) {
void CommandQueue::ExecuteAndPresent(AllocatorPtr &&alloc, IDXGISwapChain1 *swapChain, bool vsync) {
auto curFrame = ++lastFrame;
alloc->ExecuteAndPresent(this, cmdFence.Get(), curFrame, swapChain, vsync);
mtx.lock();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/dx/DXRuntime/CommandQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CommandQueue : vstd::IOperatorNewBase {
void ExecuteCallbacks(AllocatorPtr &&alloc, vstd::vector<vstd::function<void()>> &&callbacks);
void ExecuteEmpty(AllocatorPtr &&alloc);
void ExecuteEmptyCallbacks(AllocatorPtr &&alloc, vstd::vector<vstd::function<void()>> &&callbacks);
void ExecuteAndPresent(AllocatorPtr &&alloc, IDXGISwapChain4 *swapChain, bool vsync);
void ExecuteAndPresent(AllocatorPtr &&alloc, IDXGISwapChain1 *swapChain, bool vsync);
void Complete(uint64 fence);
void Complete();
void ForceSync(
Expand Down

0 comments on commit 63e2587

Please sign in to comment.