Skip to content

Commit a3fa9c2

Browse files
committed
Revert "[d3d11] Implement DXGI_SWAP_EFFECT_SEQUENTIAL and FLIP_SEQUENTIAL"
This reverts commit 79f6239. Some engines use SEQUENTIAL presentation despite not making use of it, and sparse binding is much slower than expected on Nvidia drivers, which leads to massive performance regressions across the board.
1 parent ff55077 commit a3fa9c2

File tree

3 files changed

+35
-153
lines changed

3 files changed

+35
-153
lines changed

src/d3d11/d3d11_swapchain.cpp

+13-117
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ namespace dxvk {
140140
void** ppBuffer) {
141141
InitReturnPtr(ppBuffer);
142142

143-
if (BufferId > m_backBuffers.size()) {
144-
Logger::err(str::format("D3D11: Invalid buffer index: ", BufferId));
143+
if (BufferId > 0) {
144+
Logger::err("D3D11: GetImage: BufferId > 0 not supported");
145145
return DXGI_ERROR_UNSUPPORTED;
146146
}
147147

148-
return m_backBuffers[BufferId]->QueryInterface(riid, ppBuffer);
148+
return m_backBuffer->QueryInterface(riid, ppBuffer);
149149
}
150150

151151

@@ -396,10 +396,7 @@ namespace dxvk {
396396

397397
if (m_hud != nullptr)
398398
m_hud->render(m_context, info.format, info.imageExtent);
399-
400-
if (!SyncInterval || i == SyncInterval - 1)
401-
RotateBackBuffer();
402-
399+
403400
SubmitPresent(immediateContext, sync, i);
404401
}
405402

@@ -562,25 +559,11 @@ namespace dxvk {
562559

563560

564561
void D3D11SwapChain::CreateBackBuffer() {
565-
bool sequentialPresent = false;
566-
567-
if (IsSequentialSwapChain()) {
568-
if (!(sequentialPresent = SupportsSparseImages())) {
569-
Logger::warn("Sequential present mode requeted, but sparse images not supported"
570-
"by the Vulkan implementation. Falling back to Discard semantics.");
571-
}
572-
}
573-
574562
// Explicitly destroy current swap image before
575563
// creating a new one to free up resources
576-
m_swapImages.clear();
577-
m_backBuffers.clear();
578-
m_swapImageView = nullptr;
579-
580-
uint32_t bufferCount = 1u;
581-
582-
if (sequentialPresent)
583-
bufferCount = m_desc.BufferCount;
564+
m_swapImage = nullptr;
565+
m_swapImageView = nullptr;
566+
m_backBuffer = nullptr;
584567

585568
// Create new back buffer
586569
D3D11_COMMON_TEXTURE_DESC desc;
@@ -609,47 +592,27 @@ namespace dxvk {
609592
if (m_desc.Flags & DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE)
610593
desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
611594

612-
if (sequentialPresent)
613-
desc.MiscFlags |= D3D11_RESOURCE_MISC_TILED;
614-
615595
DXGI_USAGE dxgiUsage = DXGI_USAGE_BACK_BUFFER;
616596

617597
if (m_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD
618598
|| m_desc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD)
619599
dxgiUsage |= DXGI_USAGE_DISCARD_ON_PRESENT;
620600

621-
for (uint32_t i = 0; i < bufferCount; i++) {
622-
m_backBuffers.push_back(new D3D11Texture2D(m_parent, this, &desc, dxgiUsage));
623-
m_swapImages.push_back(GetCommonTexture(m_backBuffers.back().ptr())->GetImage());
624-
625-
dxgiUsage |= DXGI_USAGE_READ_ONLY;
626-
}
627-
628-
// If necessary, create a sparse page allocator
629-
m_sparseFrameIndex = 0;
630-
631-
if (sequentialPresent) {
632-
m_sparsePagesPerImage = m_swapImages.front()->getSparsePageTable()->getPageCount();
633-
634-
m_sparseAllocator = m_device->createSparsePageAllocator();
635-
m_sparseAllocator->setCapacity(m_sparsePagesPerImage * bufferCount);
636-
} else {
637-
m_sparsePagesPerImage = 0;
638-
m_sparseAllocator = nullptr;
639-
}
601+
m_backBuffer = new D3D11Texture2D(m_parent, this, &desc, dxgiUsage);
602+
m_swapImage = GetCommonTexture(m_backBuffer.ptr())->GetImage();
640603

641604
// Create an image view that allows the
642605
// image to be bound as a shader resource.
643606
DxvkImageViewCreateInfo viewInfo;
644607
viewInfo.type = VK_IMAGE_VIEW_TYPE_2D;
645-
viewInfo.format = m_swapImages.front()->info().format;
608+
viewInfo.format = m_swapImage->info().format;
646609
viewInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
647610
viewInfo.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
648611
viewInfo.minLevel = 0;
649612
viewInfo.numLevels = 1;
650613
viewInfo.minLayer = 0;
651614
viewInfo.numLayers = 1;
652-
m_swapImageView = m_device->createImageView(m_swapImages.front(), viewInfo);
615+
m_swapImageView = m_device->createImageView(m_swapImage, viewInfo);
653616

654617
// Initialize the image so that we can use it. Clearing
655618
// to black prevents garbled output for the first frame.
@@ -663,30 +626,8 @@ namespace dxvk {
663626
m_context->beginRecording(
664627
m_device->createCommandList());
665628

666-
for (uint32_t i = 0; i < m_swapImages.size(); i++) {
667-
if (sequentialPresent) {
668-
DxvkSparseBindInfo sparseBind;
669-
sparseBind.dstResource = m_swapImages[i];
670-
sparseBind.srcAllocator = m_sparseAllocator;
671-
672-
for (uint32_t j = 0; j < m_sparsePagesPerImage; j++) {
673-
auto& bind = sparseBind.binds.emplace_back();
674-
bind.mode = DxvkSparseBindMode::Bind;
675-
bind.srcPage = j + i * m_sparsePagesPerImage;
676-
bind.dstPage = j;
677-
}
678-
679-
m_context->updatePageTable(sparseBind,
680-
DxvkSparseBindFlag::SkipSynchronization);
681-
m_context->initSparseImage(m_swapImages[i]);
682-
683-
Rc<DxvkImageView> view = m_device->createImageView(m_swapImages.front(), viewInfo);
684-
m_context->clearRenderTarget(view, VK_IMAGE_ASPECT_COLOR_BIT, VkClearValue());
685-
} else {
686-
m_context->initImage(m_swapImages[i],
687-
subresources, VK_IMAGE_LAYOUT_UNDEFINED);
688-
}
689-
}
629+
m_context->initImage(m_swapImage,
630+
subresources, VK_IMAGE_LAYOUT_UNDEFINED);
690631

691632
m_device->submitCommandList(
692633
m_context->endRecording(),
@@ -797,51 +738,6 @@ namespace dxvk {
797738
}
798739

799740

800-
void D3D11SwapChain::RotateBackBuffer() {
801-
uint32_t bufferCount = m_swapImages.size();
802-
803-
if (bufferCount < 2)
804-
return;
805-
806-
m_sparseFrameIndex += 1;
807-
m_sparseFrameIndex %= bufferCount;
808-
809-
for (uint32_t i = 0; i < bufferCount; i++) {
810-
uint32_t firstImage = (m_sparseFrameIndex + i) % bufferCount;
811-
812-
DxvkSparseBindInfo sparseBind;
813-
sparseBind.dstResource = m_swapImages[i];
814-
sparseBind.srcAllocator = m_sparseAllocator;
815-
816-
for (uint32_t j = 0; j < m_sparsePagesPerImage; j++) {
817-
auto& bind = sparseBind.binds.emplace_back();
818-
bind.mode = DxvkSparseBindMode::Bind;
819-
bind.srcPage = j + firstImage * m_sparsePagesPerImage;
820-
bind.dstPage = j;
821-
}
822-
823-
m_context->updatePageTable(sparseBind, 0);
824-
}
825-
}
826-
827-
828-
bool D3D11SwapChain::IsSequentialSwapChain() const {
829-
return m_desc.SwapEffect == DXGI_SWAP_EFFECT_SEQUENTIAL
830-
|| m_desc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
831-
}
832-
833-
834-
bool D3D11SwapChain::SupportsSparseImages() const {
835-
const auto& properties = m_device->properties().core.properties;
836-
const auto& features = m_device->features().core.features;
837-
838-
return features.sparseBinding
839-
&& features.sparseResidencyImage2D
840-
&& features.sparseResidencyAliased
841-
&& properties.sparseProperties.residencyStandard2DBlockShape;
842-
}
843-
844-
845741
std::string D3D11SwapChain::GetApiName() const {
846742
Com<IDXGIDXVKDevice> device;
847743
m_parent->QueryInterface(__uuidof(IDXGIDXVKDevice), reinterpret_cast<void**>(&device));

src/d3d11/d3d11_swapchain.h

+22-32
Original file line numberDiff line numberDiff line change
@@ -95,46 +95,42 @@ namespace dxvk {
9595

9696
Com<D3D11DXGIDevice, false> m_dxgiDevice;
9797

98-
D3D11Device* m_parent;
99-
Com<IDXGIVkSurfaceFactory> m_surfaceFactory;
98+
D3D11Device* m_parent;
99+
Com<IDXGIVkSurfaceFactory> m_surfaceFactory;
100100

101-
DXGI_SWAP_CHAIN_DESC1 m_desc;
101+
DXGI_SWAP_CHAIN_DESC1 m_desc;
102102

103-
Rc<DxvkDevice> m_device;
104-
Rc<DxvkContext> m_context;
103+
Rc<DxvkDevice> m_device;
104+
Rc<DxvkContext> m_context;
105105

106-
Rc<Presenter> m_presenter;
106+
Rc<Presenter> m_presenter;
107107

108-
uint32_t m_sparseFrameIndex = 0u;
109-
uint32_t m_sparsePagesPerImage = 0u;
110-
Rc<DxvkSparsePageAllocator> m_sparseAllocator;
108+
Rc<DxvkImage> m_swapImage;
109+
Rc<DxvkImageView> m_swapImageView;
110+
Rc<DxvkSwapchainBlitter> m_blitter;
111111

112-
std::vector<Rc<DxvkImage>> m_swapImages;
113-
Rc<DxvkImageView> m_swapImageView;
114-
Rc<DxvkSwapchainBlitter> m_blitter;
112+
Rc<hud::Hud> m_hud;
115113

116-
Rc<hud::Hud> m_hud;
117-
118-
std::vector<Com<D3D11Texture2D, false>> m_backBuffers;
119-
DxvkSubmitStatus m_presentStatus;
114+
Com<D3D11Texture2D, false> m_backBuffer;
115+
DxvkSubmitStatus m_presentStatus;
120116

121117
std::vector<Rc<DxvkImageView>> m_imageViews;
122118

123-
uint64_t m_frameId = DXGI_MAX_SWAP_CHAIN_BUFFERS;
124-
uint32_t m_frameLatency = DefaultFrameLatency;
125-
uint32_t m_frameLatencyCap = 0;
126-
HANDLE m_frameLatencyEvent = nullptr;
127-
Rc<sync::CallbackFence> m_frameLatencySignal;
119+
uint64_t m_frameId = DXGI_MAX_SWAP_CHAIN_BUFFERS;
120+
uint32_t m_frameLatency = DefaultFrameLatency;
121+
uint32_t m_frameLatencyCap = 0;
122+
HANDLE m_frameLatencyEvent = nullptr;
123+
Rc<sync::CallbackFence> m_frameLatencySignal;
128124

129-
bool m_dirty = true;
125+
bool m_dirty = true;
130126

131-
VkColorSpaceKHR m_colorspace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
127+
VkColorSpaceKHR m_colorspace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
132128

133129
std::optional<VkHdrMetadataEXT> m_hdrMetadata;
134-
bool m_dirtyHdrMetadata = true;
130+
bool m_dirtyHdrMetadata = true;
135131

136-
dxvk::mutex m_frameStatisticsLock;
137-
DXGI_VK_FRAME_STATISTICS m_frameStatistics = { };
132+
dxvk::mutex m_frameStatisticsLock;
133+
DXGI_VK_FRAME_STATISTICS m_frameStatistics = { };
138134

139135
HRESULT PresentImage(UINT SyncInterval);
140136

@@ -176,12 +172,6 @@ namespace dxvk {
176172

177173
VkFullScreenExclusiveEXT PickFullscreenMode();
178174

179-
void RotateBackBuffer();
180-
181-
bool IsSequentialSwapChain() const;
182-
183-
bool SupportsSparseImages() const;
184-
185175
std::string GetApiName() const;
186176

187177
};

src/d3d11/d3d11_texture.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ namespace dxvk {
249249

250250
if (imageInfo.sharing.mode == DxvkSharedHandleMode::Export)
251251
ExportImageInfo();
252-
253-
// Hide some internal flags as necessary
254-
if (DxgiUsage & DXGI_USAGE_BACK_BUFFER)
255-
m_desc.MiscFlags &= ~D3D11_RESOURCE_MISC_TILED;
256252
}
257253

258254

0 commit comments

Comments
 (0)