D3D12: Only set root parameters for dynamic storage buffers when needed

This patch skips setting the items for dynamic storage buffer lengths
in root signatures when there is no dynamic storage buffer in the
pipeline layout so that we can avoid adding a root constant with
Num32BitValues == 0 in the root signature.

BUG=dawn:1262

Change-Id: I7d698425c94092299aefaf8cb6ef465745c8d194
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/79742
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2022-02-10 00:05:01 +00:00 committed by Dawn LUCI CQ
parent 311e20e5de
commit 47f051984b
1 changed files with 22 additions and 12 deletions

View File

@ -37,6 +37,9 @@ namespace dawn::native::d3d12 {
static constexpr uint32_t kDynamicStorageBufferLengthsRegisterSpace = kMaxBindGroups + 2;
static constexpr uint32_t kDynamicStorageBufferLengthsBaseRegister = 0;
static constexpr uint32_t kInvalidDynamicStorageBufferLengthsParameterIndex =
std::numeric_limits<uint32_t>::max();
D3D12_SHADER_VISIBILITY ShaderVisibilityType(wgpu::ShaderStage visibility) {
ASSERT(visibility != wgpu::ShaderStage::None);
@ -224,18 +227,23 @@ namespace dawn::native::d3d12 {
ASSERT(dynamicStorageBufferLengthsShaderRegisterOffset <=
kMaxDynamicStorageBuffersPerPipelineLayout);
D3D12_ROOT_PARAMETER dynamicStorageBufferLengthConstants{};
dynamicStorageBufferLengthConstants.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
dynamicStorageBufferLengthConstants.ParameterType =
D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
dynamicStorageBufferLengthConstants.Constants.Num32BitValues =
dynamicStorageBufferLengthsShaderRegisterOffset;
dynamicStorageBufferLengthConstants.Constants.RegisterSpace =
kDynamicStorageBufferLengthsRegisterSpace;
dynamicStorageBufferLengthConstants.Constants.ShaderRegister =
kDynamicStorageBufferLengthsBaseRegister;
mDynamicStorageBufferLengthsParameterIndex = rootParameters.size();
rootParameters.emplace_back(dynamicStorageBufferLengthConstants);
if (dynamicStorageBufferLengthsShaderRegisterOffset > 0) {
D3D12_ROOT_PARAMETER dynamicStorageBufferLengthConstants{};
dynamicStorageBufferLengthConstants.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
dynamicStorageBufferLengthConstants.ParameterType =
D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
dynamicStorageBufferLengthConstants.Constants.Num32BitValues =
dynamicStorageBufferLengthsShaderRegisterOffset;
dynamicStorageBufferLengthConstants.Constants.RegisterSpace =
kDynamicStorageBufferLengthsRegisterSpace;
dynamicStorageBufferLengthConstants.Constants.ShaderRegister =
kDynamicStorageBufferLengthsBaseRegister;
mDynamicStorageBufferLengthsParameterIndex = rootParameters.size();
rootParameters.emplace_back(dynamicStorageBufferLengthConstants);
} else {
mDynamicStorageBufferLengthsParameterIndex =
kInvalidDynamicStorageBufferLengthsParameterIndex;
}
D3D12_ROOT_SIGNATURE_DESC rootSignatureDescriptor;
rootSignatureDescriptor.NumParameters = rootParameters.size();
@ -330,6 +338,8 @@ namespace dawn::native::d3d12 {
}
uint32_t PipelineLayout::GetDynamicStorageBufferLengthsParameterIndex() const {
ASSERT(mDynamicStorageBufferLengthsParameterIndex !=
kInvalidDynamicStorageBufferLengthsParameterIndex);
return mDynamicStorageBufferLengthsParameterIndex;
}