mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-18 22:54:15 +01:00
[d3d11] Validate texture sample count
Fixes incorrect return values in case a game tries to create a texture with an unsupported number of samples.
This commit is contained in:
parent
ebf474ae9e
commit
4a0c9dbaba
@ -1417,7 +1417,7 @@ namespace dxvk {
|
||||
// D3D may legally query non-power-of-two sample counts as well
|
||||
VkSampleCountFlagBits sampleCountFlag = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
if (FAILED(GetSampleCount(SampleCount, &sampleCountFlag)))
|
||||
if (FAILED(DecodeSampleCount(SampleCount, &sampleCountFlag)))
|
||||
return E_INVALIDARG;
|
||||
|
||||
// Check if the device supports the given combination of format
|
||||
|
@ -28,8 +28,7 @@ namespace dxvk {
|
||||
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
|
||||
if (FAILED(GetSampleCount(m_desc.SampleDesc.Count, &imageInfo.sampleCount)))
|
||||
throw DxvkError(str::format("D3D11: Invalid sample count: ", m_desc.SampleDesc.Count));
|
||||
DecodeSampleCount(m_desc.SampleDesc.Count, &imageInfo.sampleCount);
|
||||
|
||||
// Adjust image flags based on the corresponding D3D flags
|
||||
if (m_desc.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
|
||||
@ -154,7 +153,12 @@ namespace dxvk {
|
||||
|
||||
|
||||
HRESULT D3D11CommonTexture::NormalizeTextureProperties(D3D11_COMMON_TEXTURE_DESC* pDesc) {
|
||||
uint32_t maxMipLevelCount = pDesc->SampleDesc.Count <= 1
|
||||
if (FAILED(DecodeSampleCount(pDesc->SampleDesc.Count, nullptr)))
|
||||
return E_INVALIDARG;
|
||||
|
||||
// Use the maximum possible mip level count if the supplied
|
||||
// mip level count is either unspecified (0) or invalid
|
||||
const uint32_t maxMipLevelCount = pDesc->SampleDesc.Count <= 1
|
||||
? util::computeMipLevelCount({ pDesc->Width, pDesc->Height, pDesc->Depth })
|
||||
: 1u;
|
||||
|
||||
|
@ -2,16 +2,22 @@
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
HRESULT GetSampleCount(UINT Count, VkSampleCountFlagBits* pCount) {
|
||||
HRESULT DecodeSampleCount(UINT Count, VkSampleCountFlagBits* pCount) {
|
||||
VkSampleCountFlagBits flag;
|
||||
|
||||
switch (Count) {
|
||||
case 1: *pCount = VK_SAMPLE_COUNT_1_BIT; return S_OK;
|
||||
case 2: *pCount = VK_SAMPLE_COUNT_2_BIT; return S_OK;
|
||||
case 4: *pCount = VK_SAMPLE_COUNT_4_BIT; return S_OK;
|
||||
case 8: *pCount = VK_SAMPLE_COUNT_8_BIT; return S_OK;
|
||||
case 16: *pCount = VK_SAMPLE_COUNT_16_BIT; return S_OK;
|
||||
case 1: flag = VK_SAMPLE_COUNT_1_BIT; break;
|
||||
case 2: flag = VK_SAMPLE_COUNT_2_BIT; break;
|
||||
case 4: flag = VK_SAMPLE_COUNT_4_BIT; break;
|
||||
case 8: flag = VK_SAMPLE_COUNT_8_BIT; break;
|
||||
case 16: flag = VK_SAMPLE_COUNT_16_BIT; break;
|
||||
default: return E_INVALIDARG;
|
||||
}
|
||||
|
||||
return E_INVALIDARG;
|
||||
if (pCount != nullptr) {
|
||||
*pCount = flag;
|
||||
return S_OK;
|
||||
} return S_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
HRESULT GetSampleCount(
|
||||
HRESULT DecodeSampleCount(
|
||||
UINT Count,
|
||||
VkSampleCountFlagBits* pCount);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user