我试图在我的CreateShaderResourceView类中为Texture
方法编写一个包装器,这应该不会有任何问题,因为在类之外一切都很正常。但是,当在创建管道状态时调用断言时,调试层会报告一个错误:
D3D12 ERROR: ID3D12Device::CreateShaderResourceView: The PlaneSlice -858993460 is invalid when the resource format is B8G8R8A8_UNORM and the view format is B8G8R8A8_UNORM. Only Plane Slice 0 is valid when creating a view on a non-planar format. [ STATE_CREATION ERROR #344: CREATEUNORDEREDACCESSVIEW_INVALIDPLANESLICE]
D3D12 ERROR: ID3D12Device::CreateShaderResourceView: The Dimensions of the View are invalid due to at least one of the following conditions. MostDetailedMip (value = -858993460) must be between 0 and MipLevels-1 of the Texture Resource, 0, inclusively. With the current MostDetailedMip, MipLevels (value = 1) must be between 1 and 0, inclusively, or -1 to default to all mips from MostDetailedMip, in order that the View fit on the Texture. [ STATE_CREATION ERROR #31: CREATESHADERRESOURCEVIEW_INVALIDDIMENSIONS]
D3D12: Removing Device.
包装器函数很简单,可以在地图上操作:
void Texture::CreateSRVFromTexture(const Textures::ID & id, CD3DX12_CPU_DESCRIPTOR_HANDLE & cpuHandle)
{
auto found = m_textures.find(id);
//Create SRV with the CPU handle
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Format = found->second.textureDesc.Format;
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 1;
m_device->CreateShaderResourceView(found->second.textureBuffer, &srvDesc, cpuHandle);
}
调用此函数如下所示:
CD3DX12_CPU_DESCRIPTOR_HANDLE srvHandle1(m_textureDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), 0,
m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
m_texture->CreateSRVFromTexture(Textures::ID::Fatboy, srvHandle1);
现在,我不明白为什么它在我没有包装方法并使用Get方法访问纹理之前(没有报告错误)非常好。这是什么原因,因为错误信息有点模糊,没有多大帮助?
发布于 2018-02-09 21:11:01
D3D12_SHADER_RESOURCE_VIEW_DESC
是一个结构;它没有可以默认初始化任何字段的构造函数。
因此,当您在堆栈上创建一个实例时,所有字段的值基本上都是随机垃圾。然后继续将值赋值到某些字段。但是,并不是所有的值都分配给它们。您可以单独使用几个嵌套的成员。Texture2D
成员,包括PlaneSlice
和MostDetailedMip
,这是API正在抱怨的两个。
应该显式地初始化结构的所有字段,或者至少(在有效的情况下)使用类似于D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {0};
的内容。
https://gamedev.stackexchange.com/questions/154179
复制相似问题