PFND3D10DDI_RESOURCEMAP回调函数 (d3d10umddi.h)
ResourceMap 函数映射资源的子资源。
语法
PFND3D10DDI_RESOURCEMAP Pfnd3d10ddiResourcemap;
void Pfnd3d10ddiResourcemap(
D3D10DDI_HDEVICE unnamedParam1,
D3D10DDI_HRESOURCE unnamedParam2,
UINT unnamedParam3,
D3D10_DDI_MAP unnamedParam4,
UINT unnamedParam5,
D3D10DDI_MAPPED_SUBRESOURCE *unnamedParam6
)
{...}
参数
unnamedParam1
hDevice [in]
显示设备的句柄 (图形上下文) 。
unnamedParam2
hResource [in]
要映射的资源的句柄。
unnamedParam3
子资源 [in]
指示要映射的子资源的索引。
unnamedParam4
DDIMap [in]
一个D3D10_DDI_MAP类型的值,指示将子资源映射到的访问级别。
unnamedParam5
Flags [in]
一个 D3D10_DDI_MAP_FLAG类型的值,该值指示如何映射子资源。
unnamedParam6
pMappedSubResource [out]
指向 D3D10DDI_MAPPED_SUBRESOURCE 结构的指针,该结构接收有关映射的子资源的信息。
返回值
无
备注
驱动程序可以使用 pfnSetErrorCb 回调函数来设置错误代码。
驱动程序可以调用 pfnSetErrorCb 来设置D3DDDIERR_DEVICEREMOVED错误代码。
通常,在运行时收到D3DDDIERR_DEVICEREMOVED错误代码后,除了取消绑定、销毁和其他清理操作) 外,运行时将不再 (用户模式显示驱动程序。
通常,每次调用用户模式显示驱动程序的 ResourceMap 函数都会附带对驱动程序的 ResourceUnmap 函数的调用;但是,在运行时收到D3DDDIERR_DEVICEREMOVED错误代码后,它不会调用 ResourceUnmap。
如果运行时在 Flags 参数中传递了 D3D10_DDI_MAP_FLAG_DONOTWAIT 标志,驱动程序可以调用 pfnSetErrorCb 来设置DXGI_DDI_ERR_WASSTILLDRAWING错误代码。
驱动程序可以实现一对 ResourceMap 和 ResourceUnmap 函数,这些函数可以包含用于处理各种功能的 switch 语句。 也就是说,驱动程序可以实现一个 ResourceMap-ResourceUnmap 对,并且可以将 D3D10DDI_DEVICEFUNCS 结构的以下成员设置为指向此实现对:
pfnDynamicIABufferMapDiscard-pfnDynamicIABufferUnmap
pfnDynamicIABufferMapNoOverwrite-pfnDynamicIABufferUnmap
pfnDynamicConstantBufferMapDiscard-pfnDynamicConstantBufferUnmap
pfnDynamicResourceMapDiscard-pfnDynamicResourceUnmap
pfnStagingResourceMap-pfnStagingResourceUnmap
但是,为了提高性能,驱动程序可以实现单独的 map-unmap 函数对。 Microsoft Direct3D 运行时根据资源类型 (调用相应的 map-unmap 函数对,例如,缓冲区或纹理) 以及创建和映射资源时指定的 D3D10_DDI_RESOURCE_USAGE、 D3D10_DDI_RESOURCE_BIND_FLAG和 D3D10_DDI_MAP 值的类型。
注意
如果要映射和取消映射的资源类型是缓冲区,则 Direct3D 运行时将 Subresource 参数设置为零。
尽管 Direct3D 运行时通常为动态纹理调用 pfnDynamicResourceMapDiscard-pfnDynamicResourceUnmap 函数对,但运行时也为使用D3D10_DDI_BIND_SHADER_RESOURCE绑定标志设置创建的动态缓冲区调用此函数对。
以下示例代码演示 Direct3D 运行时调用特定 map 或 unmap 函数时设置的值:
//-----------------------------------------------
void APIENTRY UMDevice::DynamicIABufferMapNoOverwrite_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource,
D3D10_DDI_MAP MapType,
UINT MapFlags,
D3D10DDI_MAPPED_SUBRESOURCE* pMappedSubresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.ResourceDimension == D3D10DDIRESOURCE_BUFFER &&
pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_DYNAMIC &&
(pResource->m_DDICreateResource.BindFlags & (D3D10_DDI_BIND_VERTEX_BUFFER | D3D10_DDI_BIND_INDEX_BUFFER)) &&
!(pResource->m_DDICreateResource.BindFlags & ~(D3D10_DDI_BIND_VERTEX_BUFFER | D3D10_DDI_BIND_INDEX_BUFFER)) &&
Subresource == 0 &&
MapType == D3D10_DDI_MAP_WRITE_NOOVERWRITE &&
MapFlags == 0 );
pResource->Map( Subresource, MapType, MapFlags, pMappedSubresource );
}
//------------------------------------------------
void APIENTRY UMDevice::DynamicIABufferMapDiscard_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource,
D3D10_DDI_MAP MapType,
UINT MapFlags,
D3D10DDI_MAPPED_SUBRESOURCE* pMappedSubresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.ResourceDimension == D3D10DDIRESOURCE_BUFFER &&
pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_DYNAMIC &&
(pResource->m_DDICreateResource.BindFlags & (D3D10_DDI_BIND_VERTEX_BUFFER | D3D10_DDI_BIND_INDEX_BUFFER)) &&
!(pResource->m_DDICreateResource.BindFlags & ~(D3D10_DDI_BIND_VERTEX_BUFFER | D3D10_DDI_BIND_INDEX_BUFFER)) &&
Subresource == 0 &&
MapType == D3D10_DDI_MAP_WRITE_DISCARD &&
MapFlags == 0 );
pResource->Map( Subresource, MapType, MapFlags, pMappedSubresource );
}
//------------------------------------------------
void APIENTRY UMDevice::DynamicIABufferUnmap_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.ResourceDimension == D3D10DDIRESOURCE_BUFFER &&
pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_DYNAMIC &&
(pResource->m_DDICreateResource.BindFlags & (D3D10_DDI_BIND_VERTEX_BUFFER | D3D10_DDI_BIND_INDEX_BUFFER)) &&
!(pResource->m_DDICreateResource.BindFlags & ~(D3D10_DDI_BIND_VERTEX_BUFFER | D3D10_DDI_BIND_INDEX_BUFFER)) &&
Subresource == 0 );
pResource->Unmap( Subresource );
}
//------------------------------------------------
void APIENTRY UMDevice::DynamicConstantBufferMapDiscard_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource,
D3D10_DDI_MAP MapType,
UINT MapFlags,
D3D10DDI_MAPPED_SUBRESOURCE* pMappedSubresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.ResourceDimension == D3D10DDIRESOURCE_BUFFER &&
pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_DYNAMIC &&
(pResource->m_DDICreateResource.BindFlags & D3D10_DDI_BIND_CONSTANT_BUFFER) &&
!(pResource->m_DDICreateResource.BindFlags & ~D3D10_DDI_BIND_CONSTANT_BUFFER) &&
Subresource == 0 &&
MapType == D3D10_DDI_MAP_WRITE_DISCARD &&
MapFlags == 0 );
pResource->Map( Subresource, MapType, MapFlags, pMappedSubresource );
}
//------------------------------------------------
void APIENTRY UMDevice::DynamicConstantBufferUnmap_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.ResourceDimension == D3D10DDIRESOURCE_BUFFER &&
pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_DYNAMIC &&
(pResource->m_DDICreateResource.BindFlags & D3D10_DDI_BIND_CONSTANT_BUFFER) &&
!(pResource->m_DDICreateResource.BindFlags & ~D3D10_DDI_BIND_CONSTANT_BUFFER) &&
Subresource == 0 );
pResource->Unmap( Subresource );
}
//------------------------------------------------
void APIENTRY UMDevice::DynamicResourceMapDiscard_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource,
D3D10_DDI_MAP MapType,
UINT MapFlags,
D3D10DDI_MAPPED_SUBRESOURCE* pMappedSubresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_DYNAMIC &&
pResource->m_DDICreateResource.Subresources == 1 &&
Subresource == 0 &&
MapType == D3D10_DDI_MAP_WRITE_DISCARD &&
MapFlags == 0 );
pResource->Map( Subresource, MapType, MapFlags, pMappedSubresource );
}
//------------------------------------------------
void APIENTRY UMDevice::DynamicResourceUnmap_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_DYNAMIC &&
pResource->m_DDICreateResource.Subresources == 1 &&
Subresource == 0 );
pResource->Unmap( Subresource );
}
//------------------------------------------------
void APIENTRY UMDevice::StagingResourceMap_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource,
D3D10_DDI_MAP MapType,
UINT MapFlags,
D3D10DDI_MAPPED_SUBRESOURCE* pMappedSubresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_STAGING &&
(MapType == D3D10_DDI_MAP_READ || MapType == D3D10_DDI_MAP_WRITE || MapType == D3D10_DDI_MAP_READWRITE) );
pResource->Map( Subresource, MapType, MapFlags, pMappedSubresource );
}
//------------------------------------------------
void APIENTRY UMDevice::StagingResourceUnmap_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.Usage == D3D10_DDI_USAGE_STAGING );
pResource->Unmap( Subresource );
}
//------------------------------------------------
void APIENTRY UMDevice::ResourceMap_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource,
D3D10_DDI_MAP MapType,
UINT MapFlags,
D3D10DDI_MAPPED_SUBRESOURCE* pMappedSubresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.Usage != D3D10_DDI_USAGE_DYNAMIC &&
pResource->m_DDICreateResource.Usage != D3D10_DDI_USAGE_STAGING );
// Generally true; but allow last second change:
assert( false );
pResource->Map( Subresource, MapType, MapFlags, pMappedSubresource );
}
//------------------------------------------------
void APIENTRY UMDevice::ResourceUnmap_Default(
D3D10DDI_HDEVICE hDevice,
D3D10DDI_HRESOURCE hResource,
UINT Subresource )
{
UMDevice* pThis = UMDevice::CastFrom( hDevice );
UMResource* pResource = UMResource::CastFrom( hResource );
assert( pResource->m_DDICreateResource.Usage != D3D10_DDI
_USAGE_DYNAMIC &&
pResource->m_DDICreateResource.Usage != D3D10_DDI_USAGE_STAGING );
// Generally true; but allow last second change:
assert( false );
pResource->Unmap( Subresource );
}
对输入值的限制
对于 Windows 显示驱动程序模型 (WDDM) 1.3 及更高版本的驱动程序,Microsoft Direct3D 运行时提供此函数使用的一组受限输入值。 有关所有受限值的列表,请参阅 Direct3D 呈现性能改进。
要求
要求 | 值 |
---|---|
最低受支持的客户端 | 在 Windows Vista 和更高版本的 Windows 操作系统中可用。 |
目标平台 | 桌面 |
标头 | d3d10umddi.h (包括 D3d10umddi.h) |