所以我有以下功能可以渲染动画实体
void DeferredRenderer::DrawAnimated(ID3D12GraphicsCommandList * clist, std::vector<Entity*> entities)
{
clist->SetPipelineState(sysRM->GetPSO(StringID("animDeferredPSO")));
clist->SetGraphicsRootDescriptorTable(RootSigCBAll1, frame->GetGPUHandle(frameHeapParams.PerFrameCB));
auto boneCBIndex = 0;
for (auto e : entities)
{
//Set start of material texture in root descriptor, binds successfully
clist->SetGraphicsRootDescriptorTable(RootSigSRVPixel1, frame->GetGPUHandle(frameHeapParams.Textures, e->GetMaterial()->GetStartIndex()));
//Binds successfully
clist->SetGraphicsRootDescriptorTable(RootSigCBVertex0, frame->GetGPUHandle(frameHeapParams.Entities, e->GetID()));
// Not binding!
clist->SetGraphicsRootDescriptorTable(RootSigCBAll2, frame->GetGPUHandle(frameHeapParams.BoneCB, boneCBIndex));
DrawAnimated(e->GetMesh(), clist);
boneCBIndex++;
}
}
寄存器b0(RootSigCBVertex0)和b1(RootSigCBAll1)的缓冲区绑定,但b2不绑定(在NSight调试器中调试时发现)
我在AnimationVS.hlsl中的常量缓冲区如下所示:
cbuffer ConstantBuffer : register(b0)
{
float4x4 worldViewProjection;
float4x4 world;
float4x4 view;
float4x4 projection;
float4x4 shadowView;
float4x4 shadowProjection;
};
cbuffer PerFrame : register(b1)
{
float nearZ;
float farZ;
float2 lightPerspectiveValues;
};
cbuffer PerArmature: register(b2)
{
float4x4 bones[MAX_BONES];
}
float4x4 SkinTransform(float4 weights, uint4 bones)
{
// Calculate the skin transform from up to four bones and weights
float4x4 skinTransform =
bones[bones.x] * weights.x +
bones[bones.y] * weights.y +
bones[bones.z] * weights.z +
bones[bones.w] * weights.w;
return skinTransform;
}
我的根签名似乎与传递的参数匹配,甚至Visual Studio图形调试器也说 Root参数已绑定,但资源对象本身未绑定
我的根签名看起来像这样
CD3DX12_DESCRIPTOR_RANGE range[5];
//view dependent CBV
range[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);
//light dependent CBV
range[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);
//G-Buffer inputs
range[2].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 16, 0);
//per frame CBV
range[3].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 1);
//per bone
range[4].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 2);
CD3DX12_ROOT_PARAMETER rootParameters[5];
rootParameters[0].InitAsDescriptorTable(1, &range[0], D3D12_SHADER_VISIBILITY_VERTEX);
rootParameters[1].InitAsDescriptorTable(1, &range[1], D3D12_SHADER_VISIBILITY_PIXEL);
rootParameters[2].InitAsDescriptorTable(1, &range[2], D3D12_SHADER_VISIBILITY_ALL);
rootParameters[3].InitAsDescriptorTable(1, &range[3], D3D12_SHADER_VISIBILITY_ALL);
rootParameters[4].InitAsDescriptorTable(1, &range[4], D3D12_SHADER_VISIBILITY_ALL);
知道为什么会发生这种情况吗?
编辑:添加了更多上下文。
答案 0 :(得分:0)
所以,事实证明,从我的角度来看这是一个非常愚蠢的错误。
SkinTransfrom
函数具有一个float4 bones
参数,而常量缓冲区骨骼矩阵数组也称为bones
。这导致函数在其范围内使用float4 bones
,而完全忽略了常量缓冲区。
这也意味着着色器优化了常量缓冲区,即从不绑定常量缓冲区。当答案就在我眼前时,这几乎使我转圈!
以下更改为我修复了此问题:
float4x4 SkinTransform(float4 weights, uint4 boneIndices) // <-- bone to boneIndices
{
float4x4 skinTransform =
bones[boneIndices.x] * weights.x +
bones[boneIndices.y] * weights.y +
bones[boneIndices.z] * weights.z +
bones[boneIndices.w] * weights.w;
return skinTransform;
}