From f8dc5612f75e42f027dac792f979713d3e666a8c Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 9 Sep 2018 23:14:00 +0200 Subject: [PATCH] [d3d11] Added option to limit tessellation factors d3d11.maxTessFactor accepts values ranging from 8 to 64, and limits the maximum tessellation factor accordingly. --- src/d3d11/d3d11_device.cpp | 12 ++++++++++++ src/d3d11/d3d11_options.cpp | 1 + src/d3d11/d3d11_options.h | 7 +++++++ src/dxbc/dxbc_compiler.cpp | 9 ++++++++- src/dxbc/dxbc_modinfo.h | 14 +++++++++++++- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 48610eeb4..f07043a0c 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -612,6 +612,7 @@ namespace dxvk { DxbcModuleInfo moduleInfo; moduleInfo.options = m_dxbcOptions; + moduleInfo.tess = nullptr; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, @@ -636,6 +637,7 @@ namespace dxvk { DxbcModuleInfo moduleInfo; moduleInfo.options = m_dxbcOptions; + moduleInfo.tess = nullptr; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, @@ -679,6 +681,7 @@ namespace dxvk { DxbcModuleInfo moduleInfo; moduleInfo.options = m_dxbcOptions; + moduleInfo.tess = nullptr; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, @@ -701,8 +704,15 @@ namespace dxvk { InitReturnPtr(ppHullShader); D3D11CommonShader module; + DxbcTessInfo tessInfo; + tessInfo.maxTessFactor = float(m_d3d11Options.maxTessFactor); + DxbcModuleInfo moduleInfo; moduleInfo.options = m_dxbcOptions; + moduleInfo.tess = nullptr; + + if (tessInfo.maxTessFactor >= 8.0f) + moduleInfo.tess = &tessInfo; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, @@ -727,6 +737,7 @@ namespace dxvk { DxbcModuleInfo moduleInfo; moduleInfo.options = m_dxbcOptions; + moduleInfo.tess = nullptr; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, @@ -751,6 +762,7 @@ namespace dxvk { DxbcModuleInfo moduleInfo; moduleInfo.options = m_dxbcOptions; + moduleInfo.tess = nullptr; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage, diff --git a/src/d3d11/d3d11_options.cpp b/src/d3d11/d3d11_options.cpp index 88c385ad4..38274b7f9 100644 --- a/src/d3d11/d3d11_options.cpp +++ b/src/d3d11/d3d11_options.cpp @@ -7,6 +7,7 @@ namespace dxvk { D3D11Options::D3D11Options(const Config& config) { this->allowMapFlagNoWait = config.getOption("d3d11.allowMapFlagNoWait", false); this->fakeStreamOutSupport = config.getOption("d3d11.fakeStreamOutSupport", false); + this->maxTessFactor = config.getOption("d3d11.maxTessFactor", 0); } } \ No newline at end of file diff --git a/src/d3d11/d3d11_options.h b/src/d3d11/d3d11_options.h index 459185660..4acee2d8d 100644 --- a/src/d3d11/d3d11_options.h +++ b/src/d3d11/d3d11_options.h @@ -23,6 +23,13 @@ namespace dxvk { /// well enough without it. Will be removed once /// Stream Output is properly supported in DXVK. bool fakeStreamOutSupport; + + /// Maximum tessellation factor. + /// + /// Limits tessellation factors in tessellation + /// control shaders. Values from 8 to 64 are + /// supported, other values will be ignored. + int32_t maxTessFactor; }; } \ No newline at end of file diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index 236ade58b..14ba2a0d7 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -5631,10 +5631,17 @@ namespace dxvk { = m_module.constu32(tessFactor.index); // Apply global tess factor limit + float maxTessFactor = m_hs.maxTessFactor; + + if (m_moduleInfo.tess != nullptr) { + if (m_moduleInfo.tess->maxTessFactor < maxTessFactor) + maxTessFactor = m_moduleInfo.tess->maxTessFactor; + } + DxbcRegisterValue tessValue = emitRegisterExtract(value, mask); tessValue.id = m_module.opFClamp(getVectorTypeId(tessValue.type), tessValue.id, m_module.constf32(0.0f), - m_module.constf32(m_hs.maxTessFactor)); + m_module.constf32(maxTessFactor)); DxbcRegisterPointer ptr; ptr.type.ctype = DxbcScalarType::Float32; diff --git a/src/dxbc/dxbc_modinfo.h b/src/dxbc/dxbc_modinfo.h index a82fe50bb..565885465 100644 --- a/src/dxbc/dxbc_modinfo.h +++ b/src/dxbc/dxbc_modinfo.h @@ -4,6 +4,17 @@ namespace dxvk { + /** + * \brief Tessellation info + * + * Stores the maximum tessellation factor + * to export from tessellation shaders. + */ + struct DxbcTessInfo { + float maxTessFactor; + }; + + /** * \brief Shader module info * @@ -11,7 +22,8 @@ namespace dxvk { * This data can be supplied by the client API implementation. */ struct DxbcModuleInfo { - DxbcOptions options; + DxbcOptions options; + DxbcTessInfo* tess; }; } \ No newline at end of file