mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-29 17:52:18 +01:00
[dxgi] Added proper initialization of the swap chain back buffer
This commit is contained in:
parent
57821db900
commit
7de5a727ad
@ -100,6 +100,16 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
void DxgiPresenter::initBackBuffer(const Rc<DxvkImage>& image) {
|
||||
m_context->beginRecording(
|
||||
m_device->createCommandList());
|
||||
m_context->initImage(image, nullptr);
|
||||
m_device->submitCommandList(
|
||||
m_context->endRecording(),
|
||||
nullptr, nullptr);
|
||||
}
|
||||
|
||||
|
||||
void DxgiPresenter::presentImage(const Rc<DxvkImageView>& view) {
|
||||
m_context->beginRecording(
|
||||
m_device->createCommandList());
|
||||
|
@ -27,6 +27,13 @@ namespace dxvk {
|
||||
|
||||
~DxgiPresenter();
|
||||
|
||||
/**
|
||||
* \brief Initializes back buffer image
|
||||
* \param [in] image Back buffer image
|
||||
*/
|
||||
void initBackBuffer(
|
||||
const Rc<DxvkImage>& image);
|
||||
|
||||
/**
|
||||
* \brief Renders image to the screen
|
||||
* \param [in] view Source image view
|
||||
|
@ -331,14 +331,15 @@ namespace dxvk {
|
||||
| VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
||||
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
imageInfo.stages = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
|
||||
| VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
|
||||
| VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT
|
||||
| VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
|
||||
// | VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
|
||||
// | VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT
|
||||
// | VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
|
||||
| VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
|
||||
| VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
|
||||
| VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
|
||||
| VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
imageInfo.access = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
|
||||
| VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
||||
| VK_ACCESS_TRANSFER_WRITE_BIT
|
||||
| VK_ACCESS_TRANSFER_READ_BIT
|
||||
| VK_ACCESS_SHADER_READ_BIT;
|
||||
@ -368,6 +369,10 @@ namespace dxvk {
|
||||
// that the device can use to access the image.
|
||||
if (FAILED(m_device->WrapSwapChainBackBuffer(resource.ptr(), &m_desc, &m_backBufferIface)))
|
||||
throw DxvkError("DxgiSwapChain::createBackBuffer: Failed to create back buffer interface");
|
||||
|
||||
// Initialize the image properly so that
|
||||
// it can be used in a DXVK context
|
||||
m_presenter->initBackBuffer(m_backBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -242,10 +242,10 @@ namespace dxvk {
|
||||
uint32_t imageMemoryBarrierCount,
|
||||
const VkImageMemoryBarrier* pImageMemoryBarriers) {
|
||||
m_vkd->vkCmdPipelineBarrier(m_buffer,
|
||||
dstStageMask, srcStageMask, dependencyFlags,
|
||||
memoryBarrierCount, pMemoryBarriers,
|
||||
srcStageMask, dstStageMask, dependencyFlags,
|
||||
memoryBarrierCount, pMemoryBarriers,
|
||||
bufferMemoryBarrierCount, pBufferMemoryBarriers,
|
||||
imageMemoryBarrierCount, pImageMemoryBarriers);
|
||||
imageMemoryBarrierCount, pImageMemoryBarriers);
|
||||
}
|
||||
|
||||
|
||||
|
@ -220,7 +220,7 @@ namespace dxvk {
|
||||
sr.baseMipLevel = 0;
|
||||
sr.levelCount = info.mipLevels;
|
||||
sr.baseArrayLayer = 0;
|
||||
sr.levelCount = info.numLayers;
|
||||
sr.layerCount = info.numLayers;
|
||||
|
||||
m_barriers.initImage(image, sr,
|
||||
VK_IMAGE_LAYOUT_GENERAL,
|
||||
|
@ -48,23 +48,38 @@ public:
|
||||
if (FAILED(m_factory->CreateSwapChain(m_device.ptr(), &swapDesc, &m_swapChain)))
|
||||
throw DxvkError("Failed to create DXGI swap chain");
|
||||
|
||||
if (FAILED(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&m_buffer))))
|
||||
throw DxvkError("Failed to get swap chain back buffer");
|
||||
|
||||
if (FAILED(m_device->CreateRenderTargetView(m_buffer.ptr(), nullptr, &m_bufferView)))
|
||||
throw DxvkError("Failed to create render target view");
|
||||
|
||||
}
|
||||
|
||||
|
||||
~TriangleApp() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void run() {
|
||||
FLOAT color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
m_context->OMSetRenderTargets(1, &m_bufferView, nullptr);
|
||||
m_context->ClearRenderTargetView(m_bufferView.ptr(), color);
|
||||
m_swapChain->Present(0, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Com<IDXGIFactory> m_factory;
|
||||
Com<IDXGIAdapter> m_adapter;
|
||||
Com<ID3D11Device> m_device;
|
||||
Com<ID3D11DeviceContext> m_context;
|
||||
Com<IDXGISwapChain> m_swapChain;
|
||||
Com<IDXGIFactory> m_factory;
|
||||
Com<IDXGIAdapter> m_adapter;
|
||||
Com<ID3D11Device> m_device;
|
||||
Com<ID3D11DeviceContext> m_context;
|
||||
Com<IDXGISwapChain> m_swapChain;
|
||||
|
||||
Com<ID3D11Texture2D> m_buffer;
|
||||
Com<ID3D11RenderTargetView> m_bufferView;
|
||||
|
||||
D3D_FEATURE_LEVEL m_featureLevel;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user