2017-11-29 20:19:40 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
#include "d3d11_context.h"
|
|
|
|
#include "d3d11_device.h"
|
2018-01-01 20:59:54 +01:00
|
|
|
#include "d3d11_query.h"
|
2017-12-25 20:40:48 +01:00
|
|
|
#include "d3d11_texture.h"
|
2021-05-24 15:01:27 +02:00
|
|
|
#include "d3d11_video.h"
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2017-12-08 22:30:41 +01:00
|
|
|
#include "../dxbc/dxbc_util.h"
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
namespace dxvk {
|
2022-06-30 19:26:26 +02:00
|
|
|
|
2017-10-11 15:32:24 +02:00
|
|
|
D3D11DeviceContext::D3D11DeviceContext(
|
2018-11-20 10:44:04 +01:00
|
|
|
D3D11Device* pParent,
|
|
|
|
const Rc<DxvkDevice>& Device,
|
|
|
|
DxvkCsChunkFlags CsFlags)
|
2021-01-07 20:08:55 +00:00
|
|
|
: D3D11DeviceChild<ID3D11DeviceContext4>(pParent),
|
2018-11-29 20:59:40 +01:00
|
|
|
m_multithread(this, false),
|
2018-06-11 14:29:47 +02:00
|
|
|
m_device (Device),
|
2022-02-12 16:47:40 +01:00
|
|
|
m_staging (Device, StagingBufferSize),
|
2018-11-20 10:44:04 +01:00
|
|
|
m_csFlags (CsFlags),
|
2019-01-10 16:58:01 +01:00
|
|
|
m_csChunk (AllocCsChunk()),
|
|
|
|
m_cmdData (nullptr) {
|
2019-10-13 23:04:15 +02:00
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11DeviceContext::~D3D11DeviceContext() {
|
2017-11-26 14:01:41 +01:00
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-15 18:40:08 +02:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CopyTiles(
|
|
|
|
ID3D11Resource* pTiledResource,
|
|
|
|
const D3D11_TILED_RESOURCE_COORDINATE* pTileRegionStartCoordinate,
|
|
|
|
const D3D11_TILE_REGION_SIZE* pTileRegionSize,
|
|
|
|
ID3D11Buffer* pBuffer,
|
|
|
|
UINT64 BufferStartOffsetInBytes,
|
|
|
|
UINT Flags) {
|
|
|
|
static bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (!std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::CopyTiles: Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11DeviceContext::CopyTileMappings(
|
|
|
|
ID3D11Resource* pDestTiledResource,
|
|
|
|
const D3D11_TILED_RESOURCE_COORDINATE* pDestRegionStartCoordinate,
|
|
|
|
ID3D11Resource* pSourceTiledResource,
|
|
|
|
const D3D11_TILED_RESOURCE_COORDINATE* pSourceRegionStartCoordinate,
|
|
|
|
const D3D11_TILE_REGION_SIZE* pTileRegionSize,
|
|
|
|
UINT Flags) {
|
|
|
|
static bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (!std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::CopyTileMappings: Not implemented");
|
|
|
|
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11DeviceContext::ResizeTilePool(
|
|
|
|
ID3D11Buffer* pTilePool,
|
|
|
|
UINT64 NewSizeInBytes) {
|
|
|
|
static bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (!std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::ResizeTilePool: Not implemented");
|
|
|
|
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::TiledResourceBarrier(
|
|
|
|
ID3D11DeviceChild* pTiledResourceOrViewAccessBeforeBarrier,
|
|
|
|
ID3D11DeviceChild* pTiledResourceOrViewAccessAfterBarrier) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearRenderTargetView(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11RenderTargetView* pRenderTargetView,
|
|
|
|
const FLOAT ColorRGBA[4]) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2017-12-04 13:39:37 +01:00
|
|
|
auto rtv = static_cast<D3D11RenderTargetView*>(pRenderTargetView);
|
2018-02-24 23:39:22 +01:00
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!rtv)
|
2018-02-24 23:39:22 +01:00
|
|
|
return;
|
2017-12-01 00:52:39 +01:00
|
|
|
|
2019-07-17 11:34:21 +02:00
|
|
|
auto view = rtv->GetImageView();
|
|
|
|
auto color = ConvertColorValue(ColorRGBA, view->formatInfo());
|
2017-11-29 20:19:40 +01:00
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
EmitCs([
|
2019-07-17 11:34:21 +02:00
|
|
|
cClearValue = color,
|
|
|
|
cImageView = std::move(view)
|
2018-03-17 17:59:43 +01:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearRenderTarget(
|
2018-07-06 15:01:37 +02:00
|
|
|
cImageView,
|
2018-03-17 17:59:43 +01:00
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
cClearValue);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearUnorderedAccessViewUint(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11UnorderedAccessView* pUnorderedAccessView,
|
|
|
|
const UINT Values[4]) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-02-04 23:57:43 +01:00
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);
|
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!uav)
|
2018-02-24 23:39:22 +01:00
|
|
|
return;
|
|
|
|
|
2018-04-12 23:25:40 +02:00
|
|
|
// Gather UAV format info. We'll use this to determine
|
|
|
|
// whether we need to create a temporary view or not.
|
|
|
|
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
|
|
|
|
uav->GetDesc(&uavDesc);
|
|
|
|
|
|
|
|
VkFormat uavFormat = m_parent->LookupFormat(uavDesc.Format, DXGI_VK_FORMAT_MODE_ANY).Format;
|
|
|
|
VkFormat rawFormat = m_parent->LookupFormat(uavDesc.Format, DXGI_VK_FORMAT_MODE_RAW).Format;
|
|
|
|
|
|
|
|
if (uavFormat != rawFormat && rawFormat == VK_FORMAT_UNDEFINED) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format("D3D11: ClearUnorderedAccessViewUint: No raw format found for ", uavFormat));
|
2018-04-12 23:25:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-03-12 15:47:39 +01:00
|
|
|
|
2018-08-15 18:06:52 +02:00
|
|
|
VkClearValue clearValue;
|
2022-03-12 15:47:39 +01:00
|
|
|
|
2022-04-25 17:34:45 +02:00
|
|
|
// R11G11B10 is a special case since there's no corresponding
|
|
|
|
// integer format with the same bit layout. Use R32 instead.
|
|
|
|
if (uavFormat == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
|
2018-11-10 18:48:44 +01:00
|
|
|
clearValue.color.uint32[0] = ((Values[0] & 0x7FF) << 0)
|
|
|
|
| ((Values[1] & 0x7FF) << 11)
|
|
|
|
| ((Values[2] & 0x3FF) << 22);
|
2022-04-25 17:34:45 +02:00
|
|
|
clearValue.color.uint32[1] = 0;
|
|
|
|
clearValue.color.uint32[2] = 0;
|
|
|
|
clearValue.color.uint32[3] = 0;
|
|
|
|
} else {
|
|
|
|
clearValue.color.uint32[0] = Values[0];
|
|
|
|
clearValue.color.uint32[1] = Values[1];
|
|
|
|
clearValue.color.uint32[2] = Values[2];
|
|
|
|
clearValue.color.uint32[3] = Values[3];
|
2018-11-10 18:48:44 +01:00
|
|
|
}
|
2022-03-12 15:47:39 +01:00
|
|
|
|
2018-02-04 23:57:43 +01:00
|
|
|
if (uav->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
2018-04-12 23:25:40 +02:00
|
|
|
// In case of raw and structured buffers as well as typed
|
|
|
|
// buffers that can be used for atomic operations, we can
|
|
|
|
// use the fast Vulkan buffer clear function.
|
|
|
|
Rc<DxvkBufferView> bufferView = uav->GetBufferView();
|
2018-03-07 16:29:13 +01:00
|
|
|
|
2018-04-11 23:39:12 +02:00
|
|
|
if (bufferView->info().format == VK_FORMAT_R32_UINT
|
|
|
|
|| bufferView->info().format == VK_FORMAT_R32_SINT
|
2022-03-12 15:47:39 +01:00
|
|
|
|| bufferView->info().format == VK_FORMAT_R32_SFLOAT
|
|
|
|
|| bufferView->info().format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
|
2018-03-07 16:29:13 +01:00
|
|
|
EmitCs([
|
2022-03-12 15:47:39 +01:00
|
|
|
cClearValue = clearValue.color.uint32[0],
|
2018-03-07 16:29:13 +01:00
|
|
|
cDstSlice = bufferView->slice()
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBuffer(
|
|
|
|
cDstSlice.buffer(),
|
|
|
|
cDstSlice.offset(),
|
|
|
|
cDstSlice.length(),
|
|
|
|
cClearValue);
|
|
|
|
});
|
|
|
|
} else {
|
2018-04-12 23:25:40 +02:00
|
|
|
// Create a view with an integer format if necessary
|
|
|
|
if (uavFormat != rawFormat) {
|
|
|
|
DxvkBufferViewCreateInfo info = bufferView->info();
|
|
|
|
info.format = rawFormat;
|
|
|
|
|
|
|
|
bufferView = m_device->createBufferView(
|
|
|
|
bufferView->buffer(), info);
|
|
|
|
}
|
2018-04-11 23:39:12 +02:00
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cDstView = bufferView
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(
|
|
|
|
cDstView, 0,
|
|
|
|
cDstView->elementCount(),
|
2018-08-15 18:06:52 +02:00
|
|
|
cClearValue.color);
|
2018-04-11 23:39:12 +02:00
|
|
|
});
|
2018-03-07 16:29:13 +01:00
|
|
|
}
|
2018-02-04 23:57:43 +01:00
|
|
|
} else {
|
2018-04-11 23:39:12 +02:00
|
|
|
Rc<DxvkImageView> imageView = uav->GetImageView();
|
2022-04-25 17:34:45 +02:00
|
|
|
|
|
|
|
// If the clear value is zero, we can use the original view regardless of
|
|
|
|
// the format since the bit pattern will not change in any supported format.
|
|
|
|
bool isZeroClearValue = !(clearValue.color.uint32[0] | clearValue.color.uint32[1]
|
|
|
|
| clearValue.color.uint32[2] | clearValue.color.uint32[3]);
|
|
|
|
|
|
|
|
// Check if we can create an image view with the given raw format. If not,
|
|
|
|
// we'll have to use a fallback using a texel buffer view and buffer copies.
|
|
|
|
bool isViewCompatible = uavFormat == rawFormat;
|
|
|
|
|
|
|
|
if (!isViewCompatible && (imageView->imageInfo().flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) {
|
|
|
|
uint32_t formatCount = imageView->imageInfo().viewFormatCount;
|
|
|
|
isViewCompatible = formatCount == 0;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < formatCount && !isViewCompatible; i++)
|
|
|
|
isViewCompatible = imageView->imageInfo().viewFormats[i] == rawFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isViewCompatible || isZeroClearValue) {
|
|
|
|
// Create a view with an integer format if necessary
|
|
|
|
if (uavFormat != rawFormat && !isZeroClearValue) {
|
|
|
|
DxvkImageViewCreateInfo info = imageView->info();
|
|
|
|
info.format = rawFormat;
|
|
|
|
|
|
|
|
imageView = m_device->createImageView(imageView->image(), info);
|
|
|
|
}
|
2018-04-12 23:25:40 +02:00
|
|
|
|
2022-04-25 17:34:45 +02:00
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cDstView = imageView
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearImageView(cDstView,
|
|
|
|
VkOffset3D { 0, 0, 0 },
|
|
|
|
cDstView->mipLevelExtent(0),
|
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
cClearValue);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
DxvkBufferCreateInfo bufferInfo;
|
|
|
|
bufferInfo.size = imageView->formatInfo()->elementSize
|
|
|
|
* imageView->info().numLayers
|
|
|
|
* util::flattenImageExtent(imageView->mipLevelExtent(0));
|
|
|
|
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
|
|
|
|
bufferInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT
|
|
|
|
| VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
|
|
|
bufferInfo.access = VK_ACCESS_TRANSFER_READ_BIT
|
|
|
|
| VK_ACCESS_SHADER_WRITE_BIT;
|
|
|
|
|
|
|
|
Rc<DxvkBuffer> buffer = m_device->createBuffer(bufferInfo,
|
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
DxvkBufferViewCreateInfo bufferViewInfo;
|
|
|
|
bufferViewInfo.format = rawFormat;
|
|
|
|
bufferViewInfo.rangeOffset = 0;
|
|
|
|
bufferViewInfo.rangeLength = bufferInfo.size;
|
|
|
|
|
|
|
|
Rc<DxvkBufferView> bufferView = m_device->createBufferView(buffer,
|
|
|
|
bufferViewInfo);
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cDstView = std::move(imageView),
|
|
|
|
cSrcView = std::move(bufferView),
|
|
|
|
cClearValue = clearValue.color
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(
|
|
|
|
cSrcView, 0,
|
|
|
|
cSrcView->elementCount(),
|
|
|
|
cClearValue);
|
|
|
|
|
|
|
|
ctx->copyBufferToImage(cDstView->image(),
|
|
|
|
vk::pickSubresourceLayers(cDstView->subresources(), 0),
|
|
|
|
VkOffset3D { 0, 0, 0 },
|
|
|
|
cDstView->mipLevelExtent(0),
|
|
|
|
cSrcView->buffer(), 0, 0, 0);
|
|
|
|
});
|
2018-04-12 23:25:40 +02:00
|
|
|
}
|
2018-02-04 23:57:43 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearUnorderedAccessViewFloat(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11UnorderedAccessView* pUnorderedAccessView,
|
|
|
|
const FLOAT Values[4]) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-04-11 23:39:12 +02:00
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);
|
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!uav)
|
2018-04-11 23:39:12 +02:00
|
|
|
return;
|
|
|
|
|
2019-07-17 11:45:39 +02:00
|
|
|
auto imgView = uav->GetImageView();
|
|
|
|
auto bufView = uav->GetBufferView();
|
|
|
|
|
|
|
|
const DxvkFormatInfo* info = nullptr;
|
|
|
|
if (imgView != nullptr) info = imgView->formatInfo();
|
|
|
|
if (bufView != nullptr) info = bufView->formatInfo();
|
|
|
|
|
|
|
|
if (!info || info->flags.any(DxvkFormatFlag::SampledSInt, DxvkFormatFlag::SampledUInt))
|
|
|
|
return;
|
|
|
|
|
2018-08-15 18:06:52 +02:00
|
|
|
VkClearValue clearValue;
|
|
|
|
clearValue.color.float32[0] = Values[0];
|
|
|
|
clearValue.color.float32[1] = Values[1];
|
|
|
|
clearValue.color.float32[2] = Values[2];
|
|
|
|
clearValue.color.float32[3] = Values[3];
|
2018-04-11 23:39:12 +02:00
|
|
|
|
|
|
|
if (uav->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
2019-07-17 11:45:39 +02:00
|
|
|
cDstView = std::move(bufView)
|
2018-04-11 23:39:12 +02:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(
|
|
|
|
cDstView, 0,
|
|
|
|
cDstView->elementCount(),
|
2018-08-15 18:06:52 +02:00
|
|
|
cClearValue.color);
|
2018-04-11 23:39:12 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
2019-07-17 11:45:39 +02:00
|
|
|
cDstView = std::move(imgView)
|
2018-04-11 23:39:12 +02:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearImageView(cDstView,
|
|
|
|
VkOffset3D { 0, 0, 0 },
|
|
|
|
cDstView->mipLevelExtent(0),
|
2019-05-09 09:08:29 +02:00
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
2018-04-11 23:39:12 +02:00
|
|
|
cClearValue);
|
|
|
|
});
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearDepthStencilView(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11DepthStencilView* pDepthStencilView,
|
|
|
|
UINT ClearFlags,
|
|
|
|
FLOAT Depth,
|
|
|
|
UINT8 Stencil) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2017-12-09 03:53:42 +01:00
|
|
|
auto dsv = static_cast<D3D11DepthStencilView*>(pDepthStencilView);
|
2018-02-24 23:39:22 +01:00
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!dsv)
|
2018-02-24 23:39:22 +01:00
|
|
|
return;
|
|
|
|
|
2019-06-02 16:34:33 +02:00
|
|
|
// Figure out which aspects to clear based on
|
|
|
|
// the image view properties and clear flags.
|
2018-01-23 19:01:07 +01:00
|
|
|
VkImageAspectFlags aspectMask = 0;
|
|
|
|
|
|
|
|
if (ClearFlags & D3D11_CLEAR_DEPTH)
|
|
|
|
aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
|
|
|
|
|
|
|
|
if (ClearFlags & D3D11_CLEAR_STENCIL)
|
|
|
|
aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
|
|
|
|
2019-06-02 16:34:33 +02:00
|
|
|
aspectMask &= dsv->GetWritableAspectMask();
|
|
|
|
|
|
|
|
if (!aspectMask)
|
|
|
|
return;
|
2018-03-17 17:59:43 +01:00
|
|
|
|
|
|
|
VkClearValue clearValue;
|
|
|
|
clearValue.depthStencil.depth = Depth;
|
|
|
|
clearValue.depthStencil.stencil = Stencil;
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cAspectMask = aspectMask,
|
2019-06-02 16:34:33 +02:00
|
|
|
cImageView = dsv->GetImageView()
|
2018-03-17 17:59:43 +01:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearRenderTarget(
|
2018-07-06 15:01:37 +02:00
|
|
|
cImageView,
|
|
|
|
cAspectMask,
|
|
|
|
cClearValue);
|
2018-03-17 17:59:43 +01:00
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 18:06:52 +02:00
|
|
|
|
2018-03-17 20:54:09 +03:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearView(
|
|
|
|
ID3D11View* pView,
|
|
|
|
const FLOAT Color[4],
|
|
|
|
const D3D11_RECT* pRect,
|
|
|
|
UINT NumRects) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2020-04-22 22:32:53 +02:00
|
|
|
if (NumRects && !pRect)
|
|
|
|
return;
|
|
|
|
|
2018-08-15 19:02:14 +02:00
|
|
|
// ID3D11View has no methods to query the exact type of
|
|
|
|
// the view, so we'll have to check each possible class
|
|
|
|
auto dsv = dynamic_cast<D3D11DepthStencilView*>(pView);
|
|
|
|
auto rtv = dynamic_cast<D3D11RenderTargetView*>(pView);
|
|
|
|
auto uav = dynamic_cast<D3D11UnorderedAccessView*>(pView);
|
2021-05-24 15:01:27 +02:00
|
|
|
auto vov = dynamic_cast<D3D11VideoProcessorOutputView*>(pView);
|
2018-08-15 19:02:14 +02:00
|
|
|
|
|
|
|
// Retrieve underlying resource view
|
|
|
|
Rc<DxvkBufferView> bufView;
|
|
|
|
Rc<DxvkImageView> imgView;
|
|
|
|
|
|
|
|
if (dsv != nullptr)
|
|
|
|
imgView = dsv->GetImageView();
|
|
|
|
|
|
|
|
if (rtv != nullptr)
|
|
|
|
imgView = rtv->GetImageView();
|
|
|
|
|
|
|
|
if (uav != nullptr) {
|
|
|
|
bufView = uav->GetBufferView();
|
|
|
|
imgView = uav->GetImageView();
|
|
|
|
}
|
|
|
|
|
2021-05-24 15:01:27 +02:00
|
|
|
if (vov != nullptr)
|
|
|
|
imgView = vov->GetView();
|
|
|
|
|
2018-08-15 19:02:14 +02:00
|
|
|
// 3D views are unsupported
|
|
|
|
if (imgView != nullptr
|
|
|
|
&& imgView->info().type == VK_IMAGE_VIEW_TYPE_3D)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Query the view format. We'll have to convert
|
|
|
|
// the clear color based on the format's data type.
|
|
|
|
VkFormat format = VK_FORMAT_UNDEFINED;
|
|
|
|
|
|
|
|
if (bufView != nullptr)
|
|
|
|
format = bufView->info().format;
|
|
|
|
|
|
|
|
if (imgView != nullptr)
|
|
|
|
format = imgView->info().format;
|
|
|
|
|
|
|
|
if (format == VK_FORMAT_UNDEFINED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We'll need the format info to determine the buffer
|
|
|
|
// element size, and we also need it for depth images.
|
2022-07-15 17:23:54 +02:00
|
|
|
const DxvkFormatInfo* formatInfo = lookupFormatInfo(format);
|
2018-08-15 19:02:14 +02:00
|
|
|
|
|
|
|
// Convert the clear color format. ClearView takes
|
|
|
|
// the clear value for integer formats as a set of
|
|
|
|
// integral floats, so we'll have to convert.
|
2019-07-17 11:34:21 +02:00
|
|
|
VkClearValue clearValue = ConvertColorValue(Color, formatInfo);
|
|
|
|
VkImageAspectFlags clearAspect = formatInfo->aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT);
|
2018-08-15 19:02:14 +02:00
|
|
|
|
|
|
|
// Clear all the rectangles that are specified
|
2020-04-22 22:32:53 +02:00
|
|
|
for (uint32_t i = 0; i < NumRects || i < 1; i++) {
|
|
|
|
if (pRect) {
|
|
|
|
if (pRect[i].left >= pRect[i].right
|
|
|
|
|| pRect[i].top >= pRect[i].bottom)
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-15 19:02:14 +02:00
|
|
|
|
|
|
|
if (bufView != nullptr) {
|
2020-04-22 22:32:53 +02:00
|
|
|
VkDeviceSize offset = 0;
|
|
|
|
VkDeviceSize length = bufView->info().rangeLength / formatInfo->elementSize;
|
|
|
|
|
|
|
|
if (pRect) {
|
|
|
|
offset = pRect[i].left;
|
|
|
|
length = pRect[i].right - pRect[i].left;
|
|
|
|
}
|
2018-08-15 19:02:14 +02:00
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cBufferView = bufView,
|
|
|
|
cRangeOffset = offset,
|
|
|
|
cRangeLength = length,
|
|
|
|
cClearValue = clearValue
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(
|
|
|
|
cBufferView,
|
|
|
|
cRangeOffset,
|
|
|
|
cRangeLength,
|
|
|
|
cClearValue.color);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imgView != nullptr) {
|
2020-04-22 22:32:53 +02:00
|
|
|
VkOffset3D offset = { 0, 0, 0 };
|
|
|
|
VkExtent3D extent = imgView->mipLevelExtent(0);
|
|
|
|
|
|
|
|
if (pRect) {
|
|
|
|
offset = { pRect[i].left, pRect[i].top, 0 };
|
|
|
|
extent = {
|
|
|
|
uint32_t(pRect[i].right - pRect[i].left),
|
|
|
|
uint32_t(pRect[i].bottom - pRect[i].top), 1 };
|
|
|
|
}
|
2018-08-15 19:02:14 +02:00
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cImageView = imgView,
|
|
|
|
cAreaOffset = offset,
|
|
|
|
cAreaExtent = extent,
|
2019-05-09 09:08:29 +02:00
|
|
|
cClearAspect = clearAspect,
|
2018-08-15 19:02:14 +02:00
|
|
|
cClearValue = clearValue
|
|
|
|
] (DxvkContext* ctx) {
|
2020-04-22 21:01:19 +02:00
|
|
|
const VkImageUsageFlags rtUsage =
|
|
|
|
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
|
|
|
|
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
|
|
|
2020-04-22 22:32:53 +02:00
|
|
|
bool isFullSize = cImageView->mipLevelExtent(0) == cAreaExtent;
|
2018-08-15 19:02:14 +02:00
|
|
|
|
2020-04-22 22:32:53 +02:00
|
|
|
if ((cImageView->info().usage & rtUsage) && isFullSize) {
|
2020-04-22 21:01:19 +02:00
|
|
|
ctx->clearRenderTarget(
|
|
|
|
cImageView,
|
|
|
|
cClearAspect,
|
|
|
|
cClearValue);
|
|
|
|
} else {
|
|
|
|
ctx->clearImageView(
|
|
|
|
cImageView,
|
2020-04-22 22:32:53 +02:00
|
|
|
cAreaOffset,
|
|
|
|
cAreaExtent,
|
2020-04-22 21:01:19 +02:00
|
|
|
cClearAspect,
|
|
|
|
cClearValue);
|
|
|
|
}
|
2018-08-15 19:02:14 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-03-17 20:54:09 +03:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2018-08-15 18:06:52 +02:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GenerateMips(ID3D11ShaderResourceView* pShaderResourceView) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-01-20 09:46:54 +01:00
|
|
|
auto view = static_cast<D3D11ShaderResourceView*>(pShaderResourceView);
|
2018-09-19 11:59:53 +02:00
|
|
|
|
|
|
|
if (!view || view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER)
|
2018-08-15 16:35:26 +02:00
|
|
|
return;
|
2019-06-13 03:15:59 +02:00
|
|
|
|
|
|
|
D3D11_COMMON_RESOURCE_DESC resourceDesc = view->GetResourceDesc();
|
|
|
|
|
|
|
|
if (!(resourceDesc.MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS))
|
|
|
|
return;
|
|
|
|
|
2018-08-15 16:35:26 +02:00
|
|
|
EmitCs([cDstImageView = view->GetImageView()]
|
|
|
|
(DxvkContext* ctx) {
|
2020-05-27 09:08:23 +01:00
|
|
|
ctx->generateMipmaps(cDstImageView, VK_FILTER_LINEAR);
|
2018-08-15 16:35:26 +02:00
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2019-09-15 18:40:08 +02:00
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11DeviceContext::UpdateTileMappings(
|
|
|
|
ID3D11Resource* pTiledResource,
|
|
|
|
UINT NumTiledResourceRegions,
|
|
|
|
const D3D11_TILED_RESOURCE_COORDINATE* pTiledResourceRegionStartCoordinates,
|
|
|
|
const D3D11_TILE_REGION_SIZE* pTiledResourceRegionSizes,
|
|
|
|
ID3D11Buffer* pTilePool,
|
|
|
|
UINT NumRanges,
|
|
|
|
const UINT* pRangeFlags,
|
|
|
|
const UINT* pTilePoolStartOffsets,
|
|
|
|
const UINT* pRangeTileCounts,
|
|
|
|
UINT Flags) {
|
|
|
|
bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::UpdateTileMappings: Not implemented");
|
|
|
|
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::UpdateTiles(
|
|
|
|
ID3D11Resource* pDestTiledResource,
|
|
|
|
const D3D11_TILED_RESOURCE_COORDINATE* pDestTileRegionStartCoordinate,
|
|
|
|
const D3D11_TILE_REGION_SIZE* pDestTileRegionSize,
|
|
|
|
const void* pSourceTileData,
|
|
|
|
UINT Flags) {
|
|
|
|
bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::UpdateTiles: Not implemented");
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SetResourceMinLOD(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pResource,
|
|
|
|
FLOAT MinLOD) {
|
2019-09-16 12:18:39 +02:00
|
|
|
bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::SetResourceMinLOD: Not implemented");
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
FLOAT STDMETHODCALLTYPE D3D11DeviceContext::GetResourceMinLOD(ID3D11Resource* pResource) {
|
2019-09-16 12:18:39 +02:00
|
|
|
bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::GetResourceMinLOD: Not implemented");
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ResolveSubresource(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pDstResource,
|
|
|
|
UINT DstSubresource,
|
|
|
|
ID3D11Resource* pSrcResource,
|
|
|
|
UINT SrcSubresource,
|
|
|
|
DXGI_FORMAT Format) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-09-28 19:39:52 +02:00
|
|
|
bool isSameSubresource = pDstResource == pSrcResource
|
|
|
|
&& DstSubresource == SrcSubresource;
|
|
|
|
|
|
|
|
if (!pDstResource || !pSrcResource || isSameSubresource)
|
2018-09-19 11:59:53 +02:00
|
|
|
return;
|
|
|
|
|
2018-01-28 18:06:41 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION dstResourceType;
|
|
|
|
D3D11_RESOURCE_DIMENSION srcResourceType;
|
|
|
|
|
|
|
|
pDstResource->GetType(&dstResourceType);
|
|
|
|
pSrcResource->GetType(&srcResourceType);
|
|
|
|
|
|
|
|
if (dstResourceType != D3D11_RESOURCE_DIMENSION_TEXTURE2D
|
|
|
|
|| srcResourceType != D3D11_RESOURCE_DIMENSION_TEXTURE2D) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: ResolveSubresource: Incompatible resources",
|
|
|
|
"\n Dst resource type: ", dstResourceType,
|
|
|
|
"\n Src resource type: ", srcResourceType));
|
2018-01-28 18:06:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dstTexture = static_cast<D3D11Texture2D*>(pDstResource);
|
|
|
|
auto srcTexture = static_cast<D3D11Texture2D*>(pSrcResource);
|
|
|
|
|
|
|
|
D3D11_TEXTURE2D_DESC dstDesc;
|
|
|
|
D3D11_TEXTURE2D_DESC srcDesc;
|
|
|
|
|
|
|
|
dstTexture->GetDesc(&dstDesc);
|
|
|
|
srcTexture->GetDesc(&srcDesc);
|
|
|
|
|
2018-01-30 01:18:43 +01:00
|
|
|
if (dstDesc.SampleDesc.Count != 1) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: ResolveSubresource: Invalid sample counts",
|
|
|
|
"\n Dst sample count: ", dstDesc.SampleDesc.Count,
|
|
|
|
"\n Src sample count: ", srcDesc.SampleDesc.Count));
|
2018-01-28 18:06:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-09 02:54:32 +01:00
|
|
|
D3D11CommonTexture* dstTextureInfo = GetCommonTexture(pDstResource);
|
|
|
|
D3D11CommonTexture* srcTextureInfo = GetCommonTexture(pSrcResource);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
2018-04-12 17:49:14 +02:00
|
|
|
const DXGI_VK_FORMAT_INFO dstFormatInfo = m_parent->LookupFormat(dstDesc.Format, DXGI_VK_FORMAT_MODE_ANY);
|
|
|
|
const DXGI_VK_FORMAT_INFO srcFormatInfo = m_parent->LookupFormat(srcDesc.Format, DXGI_VK_FORMAT_MODE_ANY);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
2022-07-15 17:23:54 +02:00
|
|
|
auto dstVulkanFormatInfo = lookupFormatInfo(dstFormatInfo.Format);
|
|
|
|
auto srcVulkanFormatInfo = lookupFormatInfo(srcFormatInfo.Format);
|
2018-06-21 10:17:59 +02:00
|
|
|
|
2020-02-13 00:39:55 +01:00
|
|
|
if (DstSubresource >= dstTextureInfo->CountSubresources()
|
|
|
|
|| SrcSubresource >= srcTextureInfo->CountSubresources())
|
|
|
|
return;
|
|
|
|
|
2018-01-28 18:06:41 +01:00
|
|
|
const VkImageSubresource dstSubresource =
|
2018-03-14 00:45:07 +01:00
|
|
|
dstTextureInfo->GetSubresourceFromIndex(
|
2018-06-21 10:17:59 +02:00
|
|
|
dstVulkanFormatInfo->aspectMask, DstSubresource);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
|
|
|
const VkImageSubresource srcSubresource =
|
2018-03-14 00:45:07 +01:00
|
|
|
srcTextureInfo->GetSubresourceFromIndex(
|
2018-06-21 10:17:59 +02:00
|
|
|
srcVulkanFormatInfo->aspectMask, SrcSubresource);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
2018-01-30 02:20:28 +01:00
|
|
|
const VkImageSubresourceLayers dstSubresourceLayers = {
|
|
|
|
dstSubresource.aspectMask,
|
|
|
|
dstSubresource.mipLevel,
|
|
|
|
dstSubresource.arrayLayer, 1 };
|
|
|
|
|
|
|
|
const VkImageSubresourceLayers srcSubresourceLayers = {
|
|
|
|
srcSubresource.aspectMask,
|
|
|
|
srcSubresource.mipLevel,
|
|
|
|
srcSubresource.arrayLayer, 1 };
|
|
|
|
|
2021-07-02 04:39:26 +02:00
|
|
|
if (srcDesc.SampleDesc.Count == 1 || m_parent->GetOptions()->disableMsaa) {
|
2018-01-30 01:18:43 +01:00
|
|
|
EmitCs([
|
2018-03-14 00:45:07 +01:00
|
|
|
cDstImage = dstTextureInfo->GetImage(),
|
|
|
|
cSrcImage = srcTextureInfo->GetImage(),
|
2018-01-30 01:18:43 +01:00
|
|
|
cDstLayers = dstSubresourceLayers,
|
|
|
|
cSrcLayers = srcSubresourceLayers
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->copyImage(
|
|
|
|
cDstImage, cDstLayers, VkOffset3D { 0, 0, 0 },
|
|
|
|
cSrcImage, cSrcLayers, VkOffset3D { 0, 0, 0 },
|
|
|
|
cDstImage->mipLevelExtent(cDstLayers.mipLevel));
|
|
|
|
});
|
2018-02-20 22:26:23 +01:00
|
|
|
} else {
|
|
|
|
const VkFormat format = m_parent->LookupFormat(
|
2018-04-12 17:49:14 +02:00
|
|
|
Format, DXGI_VK_FORMAT_MODE_ANY).Format;
|
2018-01-28 18:06:41 +01:00
|
|
|
|
|
|
|
EmitCs([
|
2018-03-14 00:45:07 +01:00
|
|
|
cDstImage = dstTextureInfo->GetImage(),
|
|
|
|
cSrcImage = srcTextureInfo->GetImage(),
|
2018-01-28 18:06:41 +01:00
|
|
|
cDstSubres = dstSubresourceLayers,
|
2018-02-20 22:26:23 +01:00
|
|
|
cSrcSubres = srcSubresourceLayers,
|
|
|
|
cFormat = format
|
2018-01-28 18:06:41 +01:00
|
|
|
] (DxvkContext* ctx) {
|
2019-04-19 11:19:14 +02:00
|
|
|
VkImageResolve region;
|
|
|
|
region.srcSubresource = cSrcSubres;
|
|
|
|
region.srcOffset = VkOffset3D { 0, 0, 0 };
|
|
|
|
region.dstSubresource = cDstSubres;
|
|
|
|
region.dstOffset = VkOffset3D { 0, 0, 0 };
|
|
|
|
region.extent = cDstImage->mipLevelExtent(cDstSubres.mipLevel);
|
|
|
|
|
|
|
|
ctx->resolveImage(cDstImage, cSrcImage, region, cFormat);
|
2018-01-28 18:06:41 +01:00
|
|
|
});
|
|
|
|
}
|
2022-02-09 02:54:32 +01:00
|
|
|
|
|
|
|
if (dstTextureInfo->HasSequenceNumber())
|
|
|
|
TrackTextureSequenceNumber(dstTextureInfo, DstSubresource);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawAuto() {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-09-04 02:17:21 +02:00
|
|
|
D3D11Buffer* buffer = m_state.ia.vertexBuffers[0].buffer.ptr();
|
|
|
|
|
|
|
|
if (buffer == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DxvkBufferSlice vtxBuf = buffer->GetBufferSlice();
|
|
|
|
DxvkBufferSlice ctrBuf = buffer->GetSOCounter();
|
|
|
|
|
|
|
|
if (!ctrBuf.defined())
|
|
|
|
return;
|
|
|
|
|
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->drawIndirectXfb(ctrBuf,
|
|
|
|
vtxBuf.buffer()->getXfbVertexStride(),
|
2019-05-02 16:02:15 +02:00
|
|
|
vtxBuf.offset());
|
2018-09-04 02:17:21 +02:00
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::Draw(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT VertexCount,
|
|
|
|
UINT StartVertexLocation) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->draw(
|
|
|
|
VertexCount, 1,
|
|
|
|
StartVertexLocation, 0);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawIndexed(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT IndexCount,
|
|
|
|
UINT StartIndexLocation,
|
|
|
|
INT BaseVertexLocation) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->drawIndexed(
|
|
|
|
IndexCount, 1,
|
|
|
|
StartIndexLocation,
|
|
|
|
BaseVertexLocation, 0);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawInstanced(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT VertexCountPerInstance,
|
|
|
|
UINT InstanceCount,
|
|
|
|
UINT StartVertexLocation,
|
|
|
|
UINT StartInstanceLocation) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->draw(
|
|
|
|
VertexCountPerInstance,
|
|
|
|
InstanceCount,
|
|
|
|
StartVertexLocation,
|
|
|
|
StartInstanceLocation);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawIndexedInstanced(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT IndexCountPerInstance,
|
|
|
|
UINT InstanceCount,
|
|
|
|
UINT StartIndexLocation,
|
|
|
|
INT BaseVertexLocation,
|
|
|
|
UINT StartInstanceLocation) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->drawIndexed(
|
|
|
|
IndexCountPerInstance,
|
|
|
|
InstanceCount,
|
|
|
|
StartIndexLocation,
|
|
|
|
BaseVertexLocation,
|
|
|
|
StartInstanceLocation);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawIndexedInstancedIndirect(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pBufferForArgs,
|
|
|
|
UINT AlignedByteOffsetForArgs) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
2019-04-24 21:58:20 +02:00
|
|
|
SetDrawBuffers(pBufferForArgs, nullptr);
|
2021-09-11 19:38:24 +02:00
|
|
|
|
|
|
|
if (!ValidateDrawBufferSize(pBufferForArgs, AlignedByteOffsetForArgs, sizeof(VkDrawIndexedIndirectCommand)))
|
|
|
|
return;
|
2017-12-31 00:25:19 +01:00
|
|
|
|
2019-01-10 16:58:01 +01:00
|
|
|
// If possible, batch up multiple indirect draw calls of
|
|
|
|
// the same type into one single multiDrawIndirect call
|
|
|
|
auto cmdData = static_cast<D3D11CmdDrawIndirectData*>(m_cmdData);
|
2020-11-21 05:39:05 +01:00
|
|
|
auto stride = 0u;
|
|
|
|
|
|
|
|
if (cmdData && cmdData->type == D3D11CmdType::DrawIndirectIndexed)
|
|
|
|
stride = GetIndirectCommandStride(cmdData, AlignedByteOffsetForArgs, sizeof(VkDrawIndexedIndirectCommand));
|
2019-01-10 16:58:01 +01:00
|
|
|
|
2020-11-21 05:39:05 +01:00
|
|
|
if (stride) {
|
2019-01-10 16:58:01 +01:00
|
|
|
cmdData->count += 1;
|
2020-11-21 05:39:05 +01:00
|
|
|
cmdData->stride = stride;
|
2019-01-10 16:58:01 +01:00
|
|
|
} else {
|
|
|
|
cmdData = EmitCsCmd<D3D11CmdDrawIndirectData>(
|
|
|
|
[] (DxvkContext* ctx, const D3D11CmdDrawIndirectData* data) {
|
2020-11-21 05:39:05 +01:00
|
|
|
ctx->drawIndexedIndirect(data->offset, data->count, data->stride);
|
2019-01-10 16:58:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
cmdData->type = D3D11CmdType::DrawIndirectIndexed;
|
|
|
|
cmdData->offset = AlignedByteOffsetForArgs;
|
|
|
|
cmdData->count = 1;
|
2020-11-21 05:39:05 +01:00
|
|
|
cmdData->stride = 0;
|
2019-01-10 16:58:01 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawInstancedIndirect(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pBufferForArgs,
|
|
|
|
UINT AlignedByteOffsetForArgs) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
2019-04-24 21:58:20 +02:00
|
|
|
SetDrawBuffers(pBufferForArgs, nullptr);
|
2019-01-10 16:58:01 +01:00
|
|
|
|
2021-09-11 19:38:24 +02:00
|
|
|
if (!ValidateDrawBufferSize(pBufferForArgs, AlignedByteOffsetForArgs, sizeof(VkDrawIndirectCommand)))
|
|
|
|
return;
|
|
|
|
|
2019-01-10 16:58:01 +01:00
|
|
|
// If possible, batch up multiple indirect draw calls of
|
|
|
|
// the same type into one single multiDrawIndirect call
|
|
|
|
auto cmdData = static_cast<D3D11CmdDrawIndirectData*>(m_cmdData);
|
2020-11-21 05:39:05 +01:00
|
|
|
auto stride = 0u;
|
|
|
|
|
|
|
|
if (cmdData && cmdData->type == D3D11CmdType::DrawIndirect)
|
|
|
|
stride = GetIndirectCommandStride(cmdData, AlignedByteOffsetForArgs, sizeof(VkDrawIndirectCommand));
|
2017-12-31 00:25:19 +01:00
|
|
|
|
2020-11-21 05:39:05 +01:00
|
|
|
if (stride) {
|
2019-01-10 16:58:01 +01:00
|
|
|
cmdData->count += 1;
|
2020-11-21 05:39:05 +01:00
|
|
|
cmdData->stride = stride;
|
2019-01-10 16:58:01 +01:00
|
|
|
} else {
|
|
|
|
cmdData = EmitCsCmd<D3D11CmdDrawIndirectData>(
|
|
|
|
[] (DxvkContext* ctx, const D3D11CmdDrawIndirectData* data) {
|
2020-11-21 05:39:05 +01:00
|
|
|
ctx->drawIndirect(data->offset, data->count, data->stride);
|
2019-01-10 16:58:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
cmdData->type = D3D11CmdType::DrawIndirect;
|
|
|
|
cmdData->offset = AlignedByteOffsetForArgs;
|
|
|
|
cmdData->count = 1;
|
2020-11-21 05:39:05 +01:00
|
|
|
cmdData->stride = 0;
|
2019-01-10 16:58:01 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::Dispatch(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT ThreadGroupCountX,
|
|
|
|
UINT ThreadGroupCountY,
|
|
|
|
UINT ThreadGroupCountZ) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->dispatch(
|
|
|
|
ThreadGroupCountX,
|
|
|
|
ThreadGroupCountY,
|
|
|
|
ThreadGroupCountZ);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DispatchIndirect(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pBufferForArgs,
|
|
|
|
UINT AlignedByteOffsetForArgs) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
2019-04-24 21:58:20 +02:00
|
|
|
SetDrawBuffers(pBufferForArgs, nullptr);
|
2017-12-31 00:25:19 +01:00
|
|
|
|
2021-09-12 16:18:25 +02:00
|
|
|
if (!ValidateDrawBufferSize(pBufferForArgs, AlignedByteOffsetForArgs, sizeof(VkDispatchIndirectCommand)))
|
|
|
|
return;
|
|
|
|
|
2018-10-08 09:23:11 +02:00
|
|
|
EmitCs([cOffset = AlignedByteOffsetForArgs]
|
2018-01-20 18:26:17 +01:00
|
|
|
(DxvkContext* ctx) {
|
2018-10-08 09:23:11 +02:00
|
|
|
ctx->dispatchIndirect(cOffset);
|
2018-01-20 18:26:17 +01:00
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-15 18:40:08 +02:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SetMarkerInt(
|
|
|
|
LPCWSTR pLabel,
|
|
|
|
INT Data) {
|
|
|
|
// Not implemented in the backend, ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::BeginEventInt(
|
|
|
|
LPCWSTR pLabel,
|
|
|
|
INT Data) {
|
|
|
|
// Not implemented in the backend, ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::EndEvent() {
|
|
|
|
// Not implemented in the backend, ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-16 13:12:13 +02:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GetHardwareProtectionState(
|
|
|
|
BOOL* pHwProtectionEnable) {
|
|
|
|
static bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (!std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::GetHardwareProtectionState: Not implemented");
|
|
|
|
|
|
|
|
if (pHwProtectionEnable)
|
|
|
|
*pHwProtectionEnable = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SetHardwareProtectionState(
|
|
|
|
BOOL HwProtectionEnable) {
|
|
|
|
static bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (!std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::SetHardwareProtectionState: Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-20 00:19:03 +02:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::TransitionSurfaceLayout(
|
|
|
|
IDXGIVkInteropSurface* pSurface,
|
|
|
|
const VkImageSubresourceRange* pSubresources,
|
|
|
|
VkImageLayout OldLayout,
|
|
|
|
VkImageLayout NewLayout) {
|
2018-11-29 20:59:40 +01:00
|
|
|
D3D10DeviceLock lock = LockContext();
|
|
|
|
|
2018-04-20 00:19:03 +02:00
|
|
|
// Get the underlying D3D11 resource
|
|
|
|
Com<ID3D11Resource> resource;
|
|
|
|
|
|
|
|
pSurface->QueryInterface(__uuidof(ID3D11Resource),
|
|
|
|
reinterpret_cast<void**>(&resource));
|
|
|
|
|
|
|
|
// Get the texture from that resource
|
|
|
|
D3D11CommonTexture* texture = GetCommonTexture(resource.ptr());
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cImage = texture->GetImage(),
|
|
|
|
cSubresources = *pSubresources,
|
|
|
|
cOldLayout = OldLayout,
|
|
|
|
cNewLayout = NewLayout
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->transformImage(
|
|
|
|
cImage, cSubresources,
|
|
|
|
cOldLayout, cNewLayout);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:44:27 +01:00
|
|
|
void D3D11DeviceContext::ApplyInputLayout() {
|
2019-07-17 20:01:57 +02:00
|
|
|
auto inputLayout = m_state.ia.inputLayout.prvRef();
|
|
|
|
|
|
|
|
if (likely(inputLayout != nullptr)) {
|
|
|
|
EmitCs([
|
|
|
|
cInputLayout = std::move(inputLayout)
|
|
|
|
] (DxvkContext* ctx) {
|
2018-03-10 11:44:27 +01:00
|
|
|
cInputLayout->BindToContext(ctx);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([] (DxvkContext* ctx) {
|
|
|
|
ctx->setInputLayout(0, nullptr, 0, nullptr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyPrimitiveTopology() {
|
2019-07-17 15:52:42 +02:00
|
|
|
D3D11_PRIMITIVE_TOPOLOGY topology = m_state.ia.primitiveTopology;
|
|
|
|
DxvkInputAssemblyState iaState = { };
|
|
|
|
|
|
|
|
if (topology <= D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ) {
|
|
|
|
static const std::array<DxvkInputAssemblyState, 14> s_iaStates = {{
|
2019-09-23 15:20:53 +02:00
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_MAX_ENUM, VK_FALSE, 0 },
|
2019-07-17 15:52:42 +02:00
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_POINT_LIST, VK_FALSE, 0 },
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_LINE_LIST, VK_FALSE, 0 },
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, VK_TRUE, 0 },
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VK_FALSE, 0 },
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, VK_TRUE, 0 },
|
|
|
|
{ }, { }, { }, { }, // Random gap that exists for no reason
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, VK_FALSE, 0 },
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY, VK_TRUE, 0 },
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, VK_FALSE, 0 },
|
|
|
|
{ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY, VK_TRUE, 0 },
|
|
|
|
}};
|
|
|
|
|
|
|
|
iaState = s_iaStates[uint32_t(topology)];
|
|
|
|
} else if (topology >= D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST
|
|
|
|
&& topology <= D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST) {
|
|
|
|
// The number of control points per patch can be inferred from the enum value in D3D11
|
|
|
|
uint32_t vertexCount = uint32_t(topology - D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + 1);
|
|
|
|
iaState = { VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE, vertexCount };
|
|
|
|
}
|
2018-03-10 11:44:27 +01:00
|
|
|
|
|
|
|
EmitCs([iaState] (DxvkContext* ctx) {
|
|
|
|
ctx->setInputAssemblyState(iaState);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:56:58 +01:00
|
|
|
void D3D11DeviceContext::ApplyBlendState() {
|
2019-10-13 23:04:15 +02:00
|
|
|
if (m_state.om.cbState != nullptr) {
|
|
|
|
EmitCs([
|
2019-10-14 02:05:39 +02:00
|
|
|
cBlendState = m_state.om.cbState,
|
2019-10-13 23:04:15 +02:00
|
|
|
cSampleMask = m_state.om.sampleMask
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
cBlendState->BindToContext(ctx, cSampleMask);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([
|
|
|
|
cSampleMask = m_state.om.sampleMask
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
DxvkBlendMode cbState;
|
|
|
|
DxvkLogicOpState loState;
|
|
|
|
DxvkMultisampleState msState;
|
|
|
|
InitDefaultBlendState(&cbState, &loState, &msState, cSampleMask);
|
2019-07-17 20:01:57 +02:00
|
|
|
|
2019-10-13 23:04:15 +02:00
|
|
|
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
|
|
|
|
ctx->setBlendMode(i, cbState);
|
2019-07-17 20:01:57 +02:00
|
|
|
|
2019-10-13 23:04:15 +02:00
|
|
|
ctx->setLogicOpState(loState);
|
|
|
|
ctx->setMultisampleState(msState);
|
|
|
|
});
|
|
|
|
}
|
2018-03-10 11:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyBlendFactor() {
|
|
|
|
EmitCs([
|
|
|
|
cBlendConstants = DxvkBlendConstants {
|
|
|
|
m_state.om.blendFactor[0], m_state.om.blendFactor[1],
|
|
|
|
m_state.om.blendFactor[2], m_state.om.blendFactor[3] }
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->setBlendConstants(cBlendConstants);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyDepthStencilState() {
|
2019-10-13 22:48:06 +02:00
|
|
|
if (m_state.om.dsState != nullptr) {
|
|
|
|
EmitCs([
|
2019-10-14 02:05:39 +02:00
|
|
|
cDepthStencilState = m_state.om.dsState
|
2019-10-13 22:48:06 +02:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
cDepthStencilState->BindToContext(ctx);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([] (DxvkContext* ctx) {
|
|
|
|
DxvkDepthStencilState dsState;
|
|
|
|
InitDefaultDepthStencilState(&dsState);
|
2019-07-17 20:01:57 +02:00
|
|
|
|
2019-10-13 22:48:06 +02:00
|
|
|
ctx->setDepthStencilState(dsState);
|
|
|
|
});
|
|
|
|
}
|
2018-03-10 11:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyStencilRef() {
|
|
|
|
EmitCs([
|
|
|
|
cStencilRef = m_state.om.stencilRef
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->setStencilReference(cStencilRef);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyRasterizerState() {
|
2019-10-13 22:40:41 +02:00
|
|
|
if (m_state.rs.state != nullptr) {
|
|
|
|
EmitCs([
|
2019-10-14 02:05:39 +02:00
|
|
|
cRasterizerState = m_state.rs.state
|
2019-10-13 22:40:41 +02:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
cRasterizerState->BindToContext(ctx);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([] (DxvkContext* ctx) {
|
|
|
|
DxvkRasterizerState rsState;
|
|
|
|
InitDefaultRasterizerState(&rsState);
|
2019-07-17 20:01:57 +02:00
|
|
|
|
2019-10-13 22:40:41 +02:00
|
|
|
ctx->setRasterizerState(rsState);
|
|
|
|
});
|
|
|
|
}
|
2018-03-10 11:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-30 19:26:26 +02:00
|
|
|
void D3D11DeviceContext::ApplyRasterizerSampleCount() {
|
|
|
|
DxbcPushConstants pc;
|
|
|
|
pc.rasterizerSampleCount = m_state.om.sampleCount;
|
|
|
|
|
|
|
|
if (unlikely(!m_state.om.sampleCount)) {
|
|
|
|
pc.rasterizerSampleCount = m_state.rs.state->Desc()->ForcedSampleCount;
|
|
|
|
|
|
|
|
if (!m_state.om.sampleCount)
|
|
|
|
pc.rasterizerSampleCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cPushConstants = pc
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->pushConstants(0, sizeof(cPushConstants), &cPushConstants);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:44:27 +01:00
|
|
|
void D3D11DeviceContext::ApplyViewportState() {
|
|
|
|
std::array<VkViewport, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE> viewports;
|
|
|
|
std::array<VkRect2D, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE> scissors;
|
2019-06-13 02:21:10 +02:00
|
|
|
|
|
|
|
// The backend can't handle a viewport count of zero,
|
|
|
|
// so we should at least specify one empty viewport
|
|
|
|
uint32_t viewportCount = m_state.rs.numViewports;
|
|
|
|
|
|
|
|
if (unlikely(!viewportCount)) {
|
|
|
|
viewportCount = 1;
|
|
|
|
viewports[0] = VkViewport();
|
|
|
|
scissors [0] = VkRect2D();
|
|
|
|
}
|
|
|
|
|
2018-03-10 11:44:27 +01:00
|
|
|
// D3D11's coordinate system has its origin in the bottom left,
|
|
|
|
// but the viewport coordinates are aligned to the top-left
|
|
|
|
// corner so we can get away with flipping the viewport.
|
|
|
|
for (uint32_t i = 0; i < m_state.rs.numViewports; i++) {
|
2019-05-01 03:00:23 +02:00
|
|
|
const D3D11_VIEWPORT& vp = m_state.rs.viewports[i];
|
2018-03-10 11:44:27 +01:00
|
|
|
|
2019-05-01 03:00:23 +02:00
|
|
|
viewports[i] = VkViewport {
|
2018-03-10 11:44:27 +01:00
|
|
|
vp.TopLeftX, vp.Height + vp.TopLeftY,
|
|
|
|
vp.Width, -vp.Height,
|
|
|
|
vp.MinDepth, vp.MaxDepth,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scissor rectangles. Vulkan does not provide an easy way
|
|
|
|
// to disable the scissor test, so we'll have to set scissor
|
|
|
|
// rects that are at least as large as the framebuffer.
|
|
|
|
bool enableScissorTest = false;
|
|
|
|
|
|
|
|
if (m_state.rs.state != nullptr) {
|
|
|
|
D3D11_RASTERIZER_DESC rsDesc;
|
|
|
|
m_state.rs.state->GetDesc(&rsDesc);
|
|
|
|
enableScissorTest = rsDesc.ScissorEnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < m_state.rs.numViewports; i++) {
|
2019-06-13 02:16:12 +02:00
|
|
|
if (!enableScissorTest) {
|
|
|
|
scissors[i] = VkRect2D {
|
|
|
|
VkOffset2D { 0, 0 },
|
|
|
|
VkExtent2D {
|
|
|
|
D3D11_VIEWPORT_BOUNDS_MAX,
|
|
|
|
D3D11_VIEWPORT_BOUNDS_MAX } };
|
|
|
|
} else if (i >= m_state.rs.numScissors) {
|
|
|
|
scissors[i] = VkRect2D {
|
|
|
|
VkOffset2D { 0, 0 },
|
|
|
|
VkExtent2D { 0, 0 } };
|
|
|
|
} else {
|
2019-05-01 03:00:23 +02:00
|
|
|
D3D11_RECT sr = m_state.rs.scissors[i];
|
2018-03-10 11:44:27 +01:00
|
|
|
|
2018-05-25 00:08:28 +02:00
|
|
|
VkOffset2D srPosA;
|
|
|
|
srPosA.x = std::max<int32_t>(0, sr.left);
|
|
|
|
srPosA.y = std::max<int32_t>(0, sr.top);
|
|
|
|
|
|
|
|
VkOffset2D srPosB;
|
|
|
|
srPosB.x = std::max<int32_t>(srPosA.x, sr.right);
|
|
|
|
srPosB.y = std::max<int32_t>(srPosA.y, sr.bottom);
|
|
|
|
|
|
|
|
VkExtent2D srSize;
|
|
|
|
srSize.width = uint32_t(srPosB.x - srPosA.x);
|
|
|
|
srSize.height = uint32_t(srPosB.y - srPosA.y);
|
|
|
|
|
2019-05-01 03:00:23 +02:00
|
|
|
scissors[i] = VkRect2D { srPosA, srSize };
|
2018-03-10 11:44:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-13 14:38:51 +02:00
|
|
|
if (likely(viewportCount == 1)) {
|
|
|
|
EmitCs([
|
|
|
|
cViewport = viewports[0],
|
|
|
|
cScissor = scissors[0]
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->setViewports(1,
|
|
|
|
&cViewport,
|
|
|
|
&cScissor);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([
|
|
|
|
cViewportCount = viewportCount,
|
|
|
|
cViewports = viewports,
|
|
|
|
cScissors = scissors
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->setViewports(
|
|
|
|
cViewportCount,
|
|
|
|
cViewports.data(),
|
|
|
|
cScissors.data());
|
|
|
|
});
|
|
|
|
}
|
2018-03-10 11:44:27 +01:00
|
|
|
}
|
2019-05-01 00:32:03 +02:00
|
|
|
|
2018-03-10 11:44:27 +01:00
|
|
|
|
2019-06-20 22:09:02 +02:00
|
|
|
template<DxbcProgramType ShaderStage>
|
2018-07-30 19:34:48 +02:00
|
|
|
void D3D11DeviceContext::BindShader(
|
|
|
|
const D3D11CommonShader* pShaderModule) {
|
2018-07-30 20:15:19 +02:00
|
|
|
// Bind the shader and the ICB at once
|
2018-07-30 19:34:48 +02:00
|
|
|
EmitCs([
|
2018-07-30 20:15:19 +02:00
|
|
|
cSlice = pShaderModule != nullptr
|
|
|
|
&& pShaderModule->GetIcb() != nullptr
|
|
|
|
? DxvkBufferSlice(pShaderModule->GetIcb())
|
|
|
|
: DxvkBufferSlice(),
|
|
|
|
cShader = pShaderModule != nullptr
|
|
|
|
? pShaderModule->GetShader()
|
|
|
|
: nullptr
|
2018-07-30 19:34:48 +02:00
|
|
|
] (DxvkContext* ctx) {
|
2020-01-08 21:59:00 +00:00
|
|
|
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
|
|
|
|
|
|
|
|
uint32_t slotId = computeConstantBufferBinding(ShaderStage,
|
|
|
|
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
|
|
|
|
|
2022-06-02 19:37:16 +02:00
|
|
|
ctx->bindShader (stage, cShader);
|
|
|
|
ctx->bindResourceBuffer(stage, slotId, cSlice);
|
2018-07-30 19:34:48 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-13 00:59:02 +02:00
|
|
|
void D3D11DeviceContext::BindFramebuffer() {
|
2018-03-03 22:15:41 +01:00
|
|
|
DxvkRenderTargets attachments;
|
2022-06-30 19:26:26 +02:00
|
|
|
uint32_t sampleCount = 0;
|
|
|
|
|
2018-03-03 22:15:41 +01:00
|
|
|
// D3D11 doesn't have the concept of a framebuffer object,
|
|
|
|
// so we'll just create a new one every time the render
|
|
|
|
// target bindings are updated. Set up the attachments.
|
|
|
|
for (UINT i = 0; i < m_state.om.renderTargetViews.size(); i++) {
|
2019-05-01 03:00:23 +02:00
|
|
|
if (m_state.om.renderTargetViews[i] != nullptr) {
|
2018-04-30 13:12:28 +02:00
|
|
|
attachments.color[i] = {
|
2019-05-01 03:00:23 +02:00
|
|
|
m_state.om.renderTargetViews[i]->GetImageView(),
|
|
|
|
m_state.om.renderTargetViews[i]->GetRenderLayout() };
|
2022-06-30 19:26:26 +02:00
|
|
|
sampleCount = m_state.om.renderTargetViews[i]->GetSampleCount();
|
2018-03-03 22:15:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_state.om.depthStencilView != nullptr) {
|
2018-04-30 13:12:28 +02:00
|
|
|
attachments.depth = {
|
2018-03-03 22:15:41 +01:00
|
|
|
m_state.om.depthStencilView->GetImageView(),
|
2018-04-30 13:12:28 +02:00
|
|
|
m_state.om.depthStencilView->GetRenderLayout() };
|
2022-06-30 19:26:26 +02:00
|
|
|
sampleCount = m_state.om.depthStencilView->GetSampleCount();
|
2018-03-03 22:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create and bind the framebuffer object to the context
|
2018-06-15 20:49:24 +02:00
|
|
|
EmitCs([
|
2019-10-13 00:59:02 +02:00
|
|
|
cAttachments = std::move(attachments)
|
2018-06-15 20:49:24 +02:00
|
|
|
] (DxvkContext* ctx) {
|
2019-10-13 01:35:06 +02:00
|
|
|
ctx->bindRenderTargets(cAttachments);
|
2018-03-03 22:15:41 +01:00
|
|
|
});
|
2022-06-30 19:26:26 +02:00
|
|
|
|
|
|
|
// If necessary, update push constant for the sample count
|
|
|
|
if (m_state.om.sampleCount != sampleCount) {
|
|
|
|
m_state.om.sampleCount = sampleCount;
|
|
|
|
ApplyRasterizerSampleCount();
|
|
|
|
}
|
2018-03-03 22:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-24 21:58:20 +02:00
|
|
|
void D3D11DeviceContext::BindDrawBuffers(
|
|
|
|
D3D11Buffer* pBufferForArgs,
|
|
|
|
D3D11Buffer* pBufferForCount) {
|
2018-10-08 09:23:11 +02:00
|
|
|
EmitCs([
|
2019-04-24 21:58:20 +02:00
|
|
|
cArgBuffer = pBufferForArgs ? pBufferForArgs->GetBufferSlice() : DxvkBufferSlice(),
|
|
|
|
cCntBuffer = pBufferForCount ? pBufferForCount->GetBufferSlice() : DxvkBufferSlice()
|
2018-10-08 09:23:11 +02:00
|
|
|
] (DxvkContext* ctx) {
|
2019-04-24 21:58:20 +02:00
|
|
|
ctx->bindDrawBuffers(cArgBuffer, cCntBuffer);
|
2018-10-08 09:23:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 10:39:07 +01:00
|
|
|
void D3D11DeviceContext::BindVertexBuffer(
|
|
|
|
UINT Slot,
|
|
|
|
D3D11Buffer* pBuffer,
|
|
|
|
UINT Offset,
|
|
|
|
UINT Stride) {
|
2022-02-19 13:20:36 +01:00
|
|
|
if (likely(pBuffer != nullptr)) {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cBufferSlice = pBuffer->GetBufferSlice(Offset),
|
|
|
|
cStride = Stride
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindVertexBuffer(cSlotId, cBufferSlice, cStride);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindVertexBuffer(cSlotId, DxvkBufferSlice(), 0);
|
|
|
|
});
|
|
|
|
}
|
2018-03-10 10:39:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::BindIndexBuffer(
|
|
|
|
D3D11Buffer* pBuffer,
|
|
|
|
UINT Offset,
|
|
|
|
DXGI_FORMAT Format) {
|
2019-07-17 14:41:00 +02:00
|
|
|
VkIndexType indexType = Format == DXGI_FORMAT_R16_UINT
|
|
|
|
? VK_INDEX_TYPE_UINT16
|
|
|
|
: VK_INDEX_TYPE_UINT32;
|
2018-03-10 10:39:07 +01:00
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cBufferSlice = pBuffer != nullptr ? pBuffer->GetBufferSlice(Offset) : DxvkBufferSlice(),
|
|
|
|
cIndexType = indexType
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindIndexBuffer(cBufferSlice, cIndexType);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-24 17:09:11 +02:00
|
|
|
|
|
|
|
void D3D11DeviceContext::BindXfbBuffer(
|
|
|
|
UINT Slot,
|
|
|
|
D3D11Buffer* pBuffer,
|
|
|
|
UINT Offset) {
|
|
|
|
DxvkBufferSlice bufferSlice;
|
|
|
|
DxvkBufferSlice counterSlice;
|
|
|
|
|
|
|
|
if (pBuffer != nullptr) {
|
|
|
|
bufferSlice = pBuffer->GetBufferSlice();
|
|
|
|
counterSlice = pBuffer->GetSOCounter();
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cOffset = Offset,
|
|
|
|
cBufferSlice = bufferSlice,
|
|
|
|
cCounterSlice = counterSlice
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
if (cCounterSlice.defined() && cOffset != ~0u) {
|
|
|
|
ctx->updateBuffer(
|
|
|
|
cCounterSlice.buffer(),
|
|
|
|
cCounterSlice.offset(),
|
|
|
|
sizeof(cOffset),
|
|
|
|
&cOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->bindXfbBuffer(cSlotId, cBufferSlice, cCounterSlice);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-02 19:37:16 +02:00
|
|
|
template<DxbcProgramType ShaderStage>
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::BindConstantBuffer(
|
2019-06-20 22:49:19 +02:00
|
|
|
UINT Slot,
|
|
|
|
D3D11Buffer* pBuffer,
|
|
|
|
UINT Offset,
|
|
|
|
UINT Length) {
|
2018-03-10 11:16:52 +01:00
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
2022-07-14 15:10:48 +02:00
|
|
|
cBufferSlice = pBuffer ? pBuffer->GetBufferSlice(16 * Offset, 16 * Length) : DxvkBufferSlice()
|
2018-03-10 11:16:52 +01:00
|
|
|
] (DxvkContext* ctx) {
|
2022-06-02 19:37:16 +02:00
|
|
|
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
|
|
|
|
ctx->bindResourceBuffer(stage, cSlotId, cBufferSlice);
|
2018-03-10 11:16:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-14 15:10:48 +02:00
|
|
|
template<DxbcProgramType ShaderStage>
|
|
|
|
void D3D11DeviceContext::BindConstantBufferRange(
|
|
|
|
UINT Slot,
|
|
|
|
UINT Offset,
|
|
|
|
UINT Length) {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cOffset = 16 * Offset,
|
|
|
|
cLength = 16 * Length
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
|
|
|
|
ctx->bindResourceBufferRange(stage, cSlotId, cOffset, cLength);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-02 19:37:16 +02:00
|
|
|
template<DxbcProgramType ShaderStage>
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::BindSampler(
|
|
|
|
UINT Slot,
|
|
|
|
D3D11SamplerState* pSampler) {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cSampler = pSampler != nullptr ? pSampler->GetDXVKSampler() : nullptr
|
|
|
|
] (DxvkContext* ctx) {
|
2022-06-02 19:37:16 +02:00
|
|
|
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
|
|
|
|
ctx->bindResourceSampler(stage, cSlotId, cSampler);
|
2018-03-10 11:16:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-02 19:37:16 +02:00
|
|
|
template<DxbcProgramType ShaderStage>
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::BindShaderResource(
|
|
|
|
UINT Slot,
|
|
|
|
D3D11ShaderResourceView* pResource) {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cImageView = pResource != nullptr ? pResource->GetImageView() : nullptr,
|
|
|
|
cBufferView = pResource != nullptr ? pResource->GetBufferView() : nullptr
|
|
|
|
] (DxvkContext* ctx) {
|
2022-06-02 19:37:16 +02:00
|
|
|
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
|
|
|
|
ctx->bindResourceView(stage, cSlotId, cImageView, cBufferView);
|
2018-03-10 11:16:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-02 19:37:16 +02:00
|
|
|
template<DxbcProgramType ShaderStage>
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::BindUnorderedAccessView(
|
|
|
|
UINT UavSlot,
|
2018-09-27 16:50:34 +02:00
|
|
|
D3D11UnorderedAccessView* pUav,
|
2018-11-26 17:16:29 +01:00
|
|
|
UINT CtrSlot,
|
2018-09-27 16:50:34 +02:00
|
|
|
UINT Counter) {
|
2018-03-10 11:16:52 +01:00
|
|
|
EmitCs([
|
|
|
|
cUavSlotId = UavSlot,
|
|
|
|
cCtrSlotId = CtrSlot,
|
|
|
|
cImageView = pUav != nullptr ? pUav->GetImageView() : nullptr,
|
|
|
|
cBufferView = pUav != nullptr ? pUav->GetBufferView() : nullptr,
|
2018-09-27 16:50:34 +02:00
|
|
|
cCounterSlice = pUav != nullptr ? pUav->GetCounterSlice() : DxvkBufferSlice(),
|
|
|
|
cCounterValue = Counter
|
2018-03-10 11:16:52 +01:00
|
|
|
] (DxvkContext* ctx) {
|
2022-06-02 19:37:16 +02:00
|
|
|
VkShaderStageFlags stages = ShaderStage == DxbcProgramType::PixelShader
|
|
|
|
? VK_SHADER_STAGE_ALL_GRAPHICS
|
|
|
|
: VK_SHADER_STAGE_COMPUTE_BIT;
|
|
|
|
|
2018-09-27 16:50:34 +02:00
|
|
|
if (cCounterSlice.defined() && cCounterValue != ~0u) {
|
|
|
|
ctx->updateBuffer(
|
|
|
|
cCounterSlice.buffer(),
|
|
|
|
cCounterSlice.offset(),
|
|
|
|
sizeof(uint32_t),
|
|
|
|
&cCounterValue);
|
|
|
|
}
|
|
|
|
|
2022-06-02 19:37:16 +02:00
|
|
|
ctx->bindResourceView (stages, cUavSlotId, cImageView, cBufferView);
|
|
|
|
ctx->bindResourceBuffer (stages, cCtrSlotId, cCounterSlice);
|
2018-03-10 11:16:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-06 18:20:31 +01:00
|
|
|
void D3D11DeviceContext::UpdateBuffer(
|
|
|
|
D3D11Buffer* pDstBuffer,
|
|
|
|
UINT Offset,
|
|
|
|
UINT Length,
|
|
|
|
const void* pSrcData) {
|
|
|
|
DxvkBufferSlice bufferSlice = pDstBuffer->GetBufferSlice(Offset, Length);
|
|
|
|
|
2022-02-12 14:34:54 +01:00
|
|
|
if (Length <= 1024 && !(Offset & 0x3) && !(Length & 0x3)) {
|
|
|
|
// The backend has special code paths for small buffer updates,
|
|
|
|
// however both offset and size must be aligned to four bytes.
|
2022-02-06 18:20:31 +01:00
|
|
|
DxvkDataSlice dataSlice = AllocUpdateBufferSlice(Length);
|
|
|
|
std::memcpy(dataSlice.ptr(), pSrcData, Length);
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cDataBuffer = std::move(dataSlice),
|
|
|
|
cBufferSlice = std::move(bufferSlice)
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->updateBuffer(
|
|
|
|
cBufferSlice.buffer(),
|
|
|
|
cBufferSlice.offset(),
|
|
|
|
cBufferSlice.length(),
|
|
|
|
cDataBuffer.ptr());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Otherwise, to avoid large data copies on the CS thread,
|
|
|
|
// write directly to a staging buffer and dispatch a copy
|
|
|
|
DxvkBufferSlice stagingSlice = AllocStagingBuffer(Length);
|
|
|
|
std::memcpy(stagingSlice.mapPtr(0), pSrcData, Length);
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cStagingSlice = std::move(stagingSlice),
|
|
|
|
cBufferSlice = std::move(bufferSlice)
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->copyBuffer(
|
|
|
|
cBufferSlice.buffer(),
|
|
|
|
cBufferSlice.offset(),
|
|
|
|
cStagingSlice.buffer(),
|
|
|
|
cStagingSlice.offset(),
|
|
|
|
cBufferSlice.length());
|
|
|
|
});
|
|
|
|
}
|
2022-02-09 02:54:32 +01:00
|
|
|
|
|
|
|
if (pDstBuffer->HasSequenceNumber())
|
|
|
|
TrackBufferSequenceNumber(pDstBuffer);
|
2022-02-06 18:20:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::UpdateTexture(
|
|
|
|
D3D11CommonTexture* pDstTexture,
|
|
|
|
UINT DstSubresource,
|
|
|
|
const D3D11_BOX* pDstBox,
|
|
|
|
const void* pSrcData,
|
|
|
|
UINT SrcRowPitch,
|
|
|
|
UINT SrcDepthPitch) {
|
|
|
|
if (DstSubresource >= pDstTexture->CountSubresources())
|
|
|
|
return;
|
|
|
|
|
|
|
|
VkFormat packedFormat = pDstTexture->GetPackedFormat();
|
|
|
|
|
2022-07-15 17:23:54 +02:00
|
|
|
auto formatInfo = lookupFormatInfo(packedFormat);
|
2022-02-06 18:20:31 +01:00
|
|
|
auto subresource = pDstTexture->GetSubresourceFromIndex(
|
|
|
|
formatInfo->aspectMask, DstSubresource);
|
|
|
|
|
|
|
|
VkExtent3D mipExtent = pDstTexture->MipLevelExtent(subresource.mipLevel);
|
|
|
|
|
|
|
|
VkOffset3D offset = { 0, 0, 0 };
|
|
|
|
VkExtent3D extent = mipExtent;
|
|
|
|
|
|
|
|
if (pDstBox != nullptr) {
|
|
|
|
if (pDstBox->left >= pDstBox->right
|
|
|
|
|| pDstBox->top >= pDstBox->bottom
|
|
|
|
|| pDstBox->front >= pDstBox->back)
|
|
|
|
return; // no-op, but legal
|
|
|
|
|
|
|
|
offset.x = pDstBox->left;
|
|
|
|
offset.y = pDstBox->top;
|
|
|
|
offset.z = pDstBox->front;
|
|
|
|
|
|
|
|
extent.width = pDstBox->right - pDstBox->left;
|
|
|
|
extent.height = pDstBox->bottom - pDstBox->top;
|
|
|
|
extent.depth = pDstBox->back - pDstBox->front;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!util::isBlockAligned(offset, extent, formatInfo->blockSize, mipExtent)) {
|
|
|
|
Logger::err("D3D11: UpdateSubresource1: Unaligned region");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto stagingSlice = AllocStagingBuffer(util::computeImageDataSize(packedFormat, extent));
|
|
|
|
|
|
|
|
util::packImageData(stagingSlice.mapPtr(0),
|
|
|
|
pSrcData, SrcRowPitch, SrcDepthPitch, 0, 0,
|
|
|
|
pDstTexture->GetVkImageType(), extent, 1,
|
|
|
|
formatInfo, formatInfo->aspectMask);
|
|
|
|
|
|
|
|
UpdateImage(pDstTexture, &subresource,
|
|
|
|
offset, extent, std::move(stagingSlice));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-24 01:41:48 +02:00
|
|
|
void D3D11DeviceContext::UpdateImage(
|
|
|
|
D3D11CommonTexture* pDstTexture,
|
|
|
|
const VkImageSubresource* pDstSubresource,
|
|
|
|
VkOffset3D DstOffset,
|
|
|
|
VkExtent3D DstExtent,
|
|
|
|
DxvkBufferSlice StagingBuffer) {
|
|
|
|
bool dstIsImage = pDstTexture->GetMapMode() != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING;
|
|
|
|
|
2022-02-09 02:54:32 +01:00
|
|
|
uint32_t dstSubresource = D3D11CalcSubresource(pDstSubresource->mipLevel,
|
|
|
|
pDstSubresource->arrayLayer, pDstTexture->Desc()->MipLevels);
|
|
|
|
|
2021-06-24 01:41:48 +02:00
|
|
|
if (dstIsImage) {
|
|
|
|
EmitCs([
|
|
|
|
cDstImage = pDstTexture->GetImage(),
|
|
|
|
cDstLayers = vk::makeSubresourceLayers(*pDstSubresource),
|
|
|
|
cDstOffset = DstOffset,
|
|
|
|
cDstExtent = DstExtent,
|
|
|
|
cStagingSlice = std::move(StagingBuffer),
|
|
|
|
cPackedFormat = pDstTexture->GetPackedFormat()
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
if (cDstLayers.aspectMask != (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
|
|
|
|
ctx->copyBufferToImage(cDstImage,
|
|
|
|
cDstLayers, cDstOffset, cDstExtent,
|
|
|
|
cStagingSlice.buffer(),
|
|
|
|
cStagingSlice.offset(), 0, 0);
|
|
|
|
} else {
|
|
|
|
ctx->copyPackedBufferToDepthStencilImage(cDstImage, cDstLayers,
|
|
|
|
VkOffset2D { cDstOffset.x, cDstOffset.y },
|
|
|
|
VkExtent2D { cDstExtent.width, cDstExtent.height },
|
|
|
|
cStagingSlice.buffer(),
|
|
|
|
cStagingSlice.offset(),
|
|
|
|
VkOffset2D { 0, 0 },
|
|
|
|
VkExtent2D { cDstExtent.width, cDstExtent.height },
|
|
|
|
cPackedFormat);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// If the destination image is backed only by a buffer, we need to use
|
|
|
|
// the packed buffer copy function which does not know about planes and
|
|
|
|
// format metadata, so deal with it manually here.
|
|
|
|
VkExtent3D dstMipExtent = pDstTexture->MipLevelExtent(pDstSubresource->mipLevel);
|
|
|
|
|
|
|
|
auto dstFormat = pDstTexture->GetPackedFormat();
|
2022-07-15 17:23:54 +02:00
|
|
|
auto dstFormatInfo = lookupFormatInfo(dstFormat);
|
2021-06-24 01:41:48 +02:00
|
|
|
|
|
|
|
uint32_t planeCount = 1;
|
|
|
|
|
|
|
|
if (dstFormatInfo->flags.test(DxvkFormatFlag::MultiPlane))
|
|
|
|
planeCount = vk::getPlaneCount(dstFormatInfo->aspectMask);
|
|
|
|
|
|
|
|
// The source data isn't stored in an image so we'll also need to
|
|
|
|
// track the offset for that while iterating over the planes.
|
|
|
|
VkDeviceSize srcPlaneOffset = 0;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < planeCount; i++) {
|
|
|
|
VkImageAspectFlags dstAspectMask = dstFormatInfo->aspectMask;
|
|
|
|
VkDeviceSize elementSize = dstFormatInfo->elementSize;
|
|
|
|
VkExtent3D blockSize = dstFormatInfo->blockSize;
|
|
|
|
|
|
|
|
if (dstFormatInfo->flags.test(DxvkFormatFlag::MultiPlane)) {
|
|
|
|
dstAspectMask = vk::getPlaneAspect(i);
|
|
|
|
|
|
|
|
auto plane = &dstFormatInfo->planes[i];
|
|
|
|
blockSize.width *= plane->blockSize.width;
|
|
|
|
blockSize.height *= plane->blockSize.height;
|
|
|
|
elementSize = plane->elementSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkExtent3D blockCount = util::computeBlockCount(DstExtent, blockSize);
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cDstBuffer = pDstTexture->GetMappedBuffer(dstSubresource),
|
|
|
|
cDstStart = pDstTexture->GetSubresourceLayout(dstAspectMask, dstSubresource).Offset,
|
|
|
|
cDstOffset = util::computeBlockOffset(DstOffset, blockSize),
|
|
|
|
cDstSize = util::computeBlockCount(dstMipExtent, blockSize),
|
|
|
|
cDstExtent = blockCount,
|
|
|
|
cSrcBuffer = StagingBuffer.buffer(),
|
|
|
|
cSrcStart = StagingBuffer.offset() + srcPlaneOffset,
|
|
|
|
cPixelSize = elementSize
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->copyPackedBufferImage(
|
|
|
|
cDstBuffer, cDstStart, cDstOffset, cDstSize,
|
|
|
|
cSrcBuffer, cSrcStart, VkOffset3D(), cDstExtent,
|
|
|
|
cDstExtent, cPixelSize);
|
|
|
|
});
|
|
|
|
|
|
|
|
srcPlaneOffset += util::flattenImageExtent(blockCount) * elementSize;
|
|
|
|
}
|
|
|
|
}
|
2022-02-09 02:54:32 +01:00
|
|
|
|
|
|
|
if (pDstTexture->HasSequenceNumber())
|
|
|
|
TrackTextureSequenceNumber(pDstTexture, dstSubresource);
|
2021-06-24 01:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-24 21:58:20 +02:00
|
|
|
void D3D11DeviceContext::SetDrawBuffers(
|
|
|
|
ID3D11Buffer* pBufferForArgs,
|
|
|
|
ID3D11Buffer* pBufferForCount) {
|
|
|
|
auto argBuffer = static_cast<D3D11Buffer*>(pBufferForArgs);
|
|
|
|
auto cntBuffer = static_cast<D3D11Buffer*>(pBufferForCount);
|
|
|
|
|
|
|
|
if (m_state.id.argBuffer != argBuffer
|
|
|
|
|| m_state.id.cntBuffer != cntBuffer) {
|
|
|
|
m_state.id.argBuffer = argBuffer;
|
|
|
|
m_state.id.cntBuffer = cntBuffer;
|
2018-10-08 09:23:11 +02:00
|
|
|
|
2019-04-24 21:58:20 +02:00
|
|
|
BindDrawBuffers(argBuffer, cntBuffer);
|
2018-10-08 09:23:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-29 18:40:56 +02:00
|
|
|
bool D3D11DeviceContext::TestRtvUavHazards(
|
|
|
|
UINT NumRTVs,
|
|
|
|
ID3D11RenderTargetView* const* ppRTVs,
|
|
|
|
UINT NumUAVs,
|
|
|
|
ID3D11UnorderedAccessView* const* ppUAVs) {
|
|
|
|
if (NumRTVs == D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL) NumRTVs = 0;
|
|
|
|
if (NumUAVs == D3D11_KEEP_UNORDERED_ACCESS_VIEWS) NumUAVs = 0;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < NumRTVs; i++) {
|
|
|
|
auto rtv = static_cast<D3D11RenderTargetView*>(ppRTVs[i]);
|
|
|
|
|
|
|
|
if (!rtv)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (uint32_t j = 0; j < i; j++) {
|
|
|
|
if (CheckViewOverlap(rtv, static_cast<D3D11RenderTargetView*>(ppRTVs[j])))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtv->HasBindFlag(D3D11_BIND_UNORDERED_ACCESS)) {
|
|
|
|
for (uint32_t j = 0; j < NumUAVs; j++) {
|
|
|
|
if (CheckViewOverlap(rtv, static_cast<D3D11UnorderedAccessView*>(ppUAVs[j])))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < NumUAVs; i++) {
|
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(ppUAVs[i]);
|
|
|
|
|
|
|
|
if (!uav)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (uint32_t j = 0; j < i; j++) {
|
|
|
|
if (CheckViewOverlap(uav, static_cast<D3D11UnorderedAccessView*>(ppUAVs[j])))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-26 18:08:05 +02:00
|
|
|
template<DxbcProgramType ShaderStage>
|
|
|
|
bool D3D11DeviceContext::TestSrvHazards(
|
|
|
|
D3D11ShaderResourceView* pView) {
|
|
|
|
bool hazard = false;
|
|
|
|
|
|
|
|
if (ShaderStage == DxbcProgramType::ComputeShader) {
|
|
|
|
int32_t uav = m_state.cs.uavMask.findNext(0);
|
|
|
|
|
|
|
|
while (uav >= 0 && !hazard) {
|
|
|
|
hazard = CheckViewOverlap(pView, m_state.cs.unorderedAccessViews[uav].ptr());
|
|
|
|
uav = m_state.cs.uavMask.findNext(uav + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hazard = CheckViewOverlap(pView, m_state.om.depthStencilView.ptr());
|
|
|
|
|
|
|
|
for (uint32_t i = 0; !hazard && i < m_state.om.maxRtv; i++)
|
|
|
|
hazard = CheckViewOverlap(pView, m_state.om.renderTargetViews[i].ptr());
|
|
|
|
|
|
|
|
for (uint32_t i = 0; !hazard && i < m_state.om.maxUav; i++)
|
|
|
|
hazard = CheckViewOverlap(pView, m_state.ps.unorderedAccessViews[i].ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
return hazard;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<DxbcProgramType ShaderStage, typename T>
|
2019-08-29 18:49:04 +02:00
|
|
|
void D3D11DeviceContext::ResolveSrvHazards(
|
2019-08-26 18:08:05 +02:00
|
|
|
T* pView,
|
|
|
|
D3D11ShaderResourceBindings& Bindings) {
|
|
|
|
uint32_t slotId = computeSrvBinding(ShaderStage, 0);
|
|
|
|
int32_t srvId = Bindings.hazardous.findNext(0);
|
|
|
|
|
|
|
|
while (srvId >= 0) {
|
|
|
|
auto srv = Bindings.views[srvId].ptr();
|
|
|
|
|
|
|
|
if (likely(srv && srv->TestHazards())) {
|
|
|
|
bool hazard = CheckViewOverlap(pView, srv);
|
|
|
|
|
|
|
|
if (unlikely(hazard)) {
|
|
|
|
Bindings.views[srvId] = nullptr;
|
|
|
|
Bindings.hazardous.clr(srvId);
|
|
|
|
|
2022-06-02 19:37:16 +02:00
|
|
|
BindShaderResource<ShaderStage>(slotId + srvId, nullptr);
|
2019-08-26 18:08:05 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Avoid further redundant iterations
|
|
|
|
Bindings.hazardous.clr(srvId);
|
|
|
|
}
|
|
|
|
|
|
|
|
srvId = Bindings.hazardous.findNext(srvId + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
2019-08-29 18:49:04 +02:00
|
|
|
void D3D11DeviceContext::ResolveCsSrvHazards(
|
2019-08-26 18:08:05 +02:00
|
|
|
T* pView) {
|
|
|
|
if (!pView) return;
|
2019-08-29 18:49:04 +02:00
|
|
|
ResolveSrvHazards<DxbcProgramType::ComputeShader> (pView, m_state.cs.shaderResources);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-17 11:34:21 +02:00
|
|
|
VkClearValue D3D11DeviceContext::ConvertColorValue(
|
|
|
|
const FLOAT Color[4],
|
|
|
|
const DxvkFormatInfo* pFormatInfo) {
|
|
|
|
VkClearValue result;
|
|
|
|
|
|
|
|
if (pFormatInfo->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
|
|
|
|
for (uint32_t i = 0; i < 4; i++) {
|
|
|
|
if (pFormatInfo->flags.test(DxvkFormatFlag::SampledUInt))
|
|
|
|
result.color.uint32[i] = uint32_t(std::max(0.0f, Color[i]));
|
|
|
|
else if (pFormatInfo->flags.test(DxvkFormatFlag::SampledSInt))
|
|
|
|
result.color.int32[i] = int32_t(Color[i]);
|
|
|
|
else
|
|
|
|
result.color.float32[i] = Color[i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result.depthStencil.depth = Color[0];
|
|
|
|
result.depthStencil.stencil = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) {
|
2022-02-06 18:19:37 +01:00
|
|
|
constexpr size_t UpdateBufferSize = 1 * 1024 * 1024;
|
2018-01-23 16:43:55 +01:00
|
|
|
|
|
|
|
if (Size >= UpdateBufferSize) {
|
|
|
|
Rc<DxvkDataBuffer> buffer = new DxvkDataBuffer(Size);
|
|
|
|
return buffer->alloc(Size);
|
|
|
|
} else {
|
|
|
|
if (m_updateBuffer == nullptr)
|
2018-05-13 11:12:54 +02:00
|
|
|
m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize);
|
2018-01-23 16:43:55 +01:00
|
|
|
|
|
|
|
DxvkDataSlice slice = m_updateBuffer->alloc(Size);
|
|
|
|
|
|
|
|
if (slice.ptr() == nullptr) {
|
2018-05-13 11:12:54 +02:00
|
|
|
m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize);
|
2018-01-23 16:43:55 +01:00
|
|
|
slice = m_updateBuffer->alloc(Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return slice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-27 16:07:38 +02:00
|
|
|
|
2021-05-27 17:56:55 +02:00
|
|
|
DxvkBufferSlice D3D11DeviceContext::AllocStagingBuffer(
|
|
|
|
VkDeviceSize Size) {
|
2022-02-12 16:47:40 +01:00
|
|
|
return m_staging.alloc(256, Size);
|
2022-02-06 18:19:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ResetStagingBuffer() {
|
2022-02-12 16:47:40 +01:00
|
|
|
m_staging.reset();
|
2021-05-27 17:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-27 16:07:38 +02:00
|
|
|
DxvkCsChunkRef D3D11DeviceContext::AllocCsChunk() {
|
2018-11-20 10:44:04 +01:00
|
|
|
return m_parent->AllocCsChunk(m_csFlags);
|
2018-08-27 16:07:38 +02:00
|
|
|
}
|
|
|
|
|
2019-10-13 22:09:55 +02:00
|
|
|
|
|
|
|
void D3D11DeviceContext::InitDefaultPrimitiveTopology(
|
|
|
|
DxvkInputAssemblyState* pIaState) {
|
|
|
|
pIaState->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
|
|
|
|
pIaState->primitiveRestart = VK_FALSE;
|
|
|
|
pIaState->patchVertexCount = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-13 22:40:41 +02:00
|
|
|
|
|
|
|
void D3D11DeviceContext::InitDefaultRasterizerState(
|
|
|
|
DxvkRasterizerState* pRsState) {
|
|
|
|
pRsState->polygonMode = VK_POLYGON_MODE_FILL;
|
|
|
|
pRsState->cullMode = VK_CULL_MODE_BACK_BIT;
|
|
|
|
pRsState->frontFace = VK_FRONT_FACE_CLOCKWISE;
|
|
|
|
pRsState->depthClipEnable = VK_TRUE;
|
|
|
|
pRsState->depthBiasEnable = VK_FALSE;
|
2021-03-13 19:45:00 +01:00
|
|
|
pRsState->conservativeMode = VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT;
|
2019-10-13 22:40:41 +02:00
|
|
|
pRsState->sampleCount = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-13 22:48:06 +02:00
|
|
|
|
|
|
|
void D3D11DeviceContext::InitDefaultDepthStencilState(
|
|
|
|
DxvkDepthStencilState* pDsState) {
|
|
|
|
VkStencilOpState stencilOp;
|
|
|
|
stencilOp.failOp = VK_STENCIL_OP_KEEP;
|
|
|
|
stencilOp.passOp = VK_STENCIL_OP_KEEP;
|
|
|
|
stencilOp.depthFailOp = VK_STENCIL_OP_KEEP;
|
|
|
|
stencilOp.compareOp = VK_COMPARE_OP_ALWAYS;
|
|
|
|
stencilOp.compareMask = D3D11_DEFAULT_STENCIL_READ_MASK;
|
|
|
|
stencilOp.writeMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
|
|
|
|
stencilOp.reference = 0;
|
|
|
|
|
|
|
|
pDsState->enableDepthTest = VK_TRUE;
|
|
|
|
pDsState->enableDepthWrite = VK_TRUE;
|
|
|
|
pDsState->enableStencilTest = VK_FALSE;
|
|
|
|
pDsState->depthCompareOp = VK_COMPARE_OP_LESS;
|
|
|
|
pDsState->stencilOpFront = stencilOp;
|
|
|
|
pDsState->stencilOpBack = stencilOp;
|
|
|
|
}
|
|
|
|
|
2019-10-13 23:04:15 +02:00
|
|
|
|
|
|
|
void D3D11DeviceContext::InitDefaultBlendState(
|
|
|
|
DxvkBlendMode* pCbState,
|
|
|
|
DxvkLogicOpState* pLoState,
|
|
|
|
DxvkMultisampleState* pMsState,
|
|
|
|
UINT SampleMask) {
|
|
|
|
pCbState->enableBlending = VK_FALSE;
|
|
|
|
pCbState->colorSrcFactor = VK_BLEND_FACTOR_ONE;
|
|
|
|
pCbState->colorDstFactor = VK_BLEND_FACTOR_ZERO;
|
|
|
|
pCbState->colorBlendOp = VK_BLEND_OP_ADD;
|
|
|
|
pCbState->alphaSrcFactor = VK_BLEND_FACTOR_ONE;
|
|
|
|
pCbState->alphaDstFactor = VK_BLEND_FACTOR_ZERO;
|
|
|
|
pCbState->alphaBlendOp = VK_BLEND_OP_ADD;
|
|
|
|
pCbState->writeMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT
|
|
|
|
| VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
|
|
|
|
|
|
|
pLoState->enableLogicOp = VK_FALSE;
|
|
|
|
pLoState->logicOp = VK_LOGIC_OP_NO_OP;
|
|
|
|
|
|
|
|
pMsState->sampleMask = SampleMask;
|
|
|
|
pMsState->enableAlphaToCoverage = VK_FALSE;
|
|
|
|
}
|
|
|
|
|
2022-02-09 13:14:10 +01:00
|
|
|
|
|
|
|
void D3D11DeviceContext::TrackResourceSequenceNumber(
|
|
|
|
ID3D11Resource* pResource) {
|
|
|
|
if (!pResource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
D3D11CommonTexture* texture = GetCommonTexture(pResource);
|
|
|
|
|
|
|
|
if (texture) {
|
|
|
|
if (texture->HasSequenceNumber()) {
|
|
|
|
for (uint32_t i = 0; i < texture->CountSubresources(); i++)
|
|
|
|
TrackTextureSequenceNumber(texture, i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
D3D11Buffer* buffer = static_cast<D3D11Buffer*>(pResource);
|
|
|
|
|
|
|
|
if (buffer->HasSequenceNumber())
|
|
|
|
TrackBufferSequenceNumber(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|