D3dpool and d3d Resources

Source: Internet
Author: User

Original article: http://www.cnblogs.com/maxice/archive/2010/02/04/1663436.html

D3d Resource Management

Resource category
Vertexbuffer)
Index Buffer)
Texture)

Resource Storage
Video memory)
Memory that is directly accessed through AGP (AGP aperture, also called non-local memory)
System memory)

Performance trade-offs
When creating a d3d resource, we need to fill in two parameters: d3dpool and d3dusage. These two parameters jointly determine whether resources are ultimately stored in the video memory, non-local video memory, or system memory.

Enumeration type d3dpool

D3dpool_default

D3dpool_managed

D3dpool_systemmem

D3dpool_scratch

d3dpool_managed:
resource storage location: this resource is managed internally by d3d and is usually created in the system memory. When the video card needs this resource, d3d copies it from the memory to the video memory.
when the device is lost, d3d automatically restores the data in the video memory.
Applicability: Because the Resource Management Solution of d3d is efficient and easy to use, most resources in the game can be created using this identifier.
example: Most texture maps and static models used in the game.

D3dpool_default:
Resource storage location: This type of resource cannot be managed by d3d, and is usually created in the video storage or AGP aperture.
When the device is lost, you must manually restore the resource.CodeComplexity.
Applicability: Sometimes we want to keep some resources in the video memory to speed up access. Using the d3dusage_writeonly tag increases the efficiency.
Example: The cursor pasters used in the game are always used during the game operation and can be directly created in the video memory.
If the data needs to be updated frequently (constant lock and unlock), you also need to use d3dpool_default and d3dusage_dynamic tag. This means that the resource will be created in the AGP aperture.
Example: A particle system that uses CPU for Physical Operations and a skeleton animation that uses CPU for skin calculation.

 

Displays the storage of resources created using different usage and pool parameters.


Example: direct3d simple drawingCubeBody.

 

[Copy to clipboard]
Code:
// Create a vertex buffer
If (failed (g_pd3ddevice-> createvertexbuffer (3 * sizeof (customvertex), 0, d3dfvf_customvertex, d3dpool_default, & g_pvertexbuffer, null )))
{
Return e_fail;
}


This Code uses d3dpool_default to create vertexbuffer, but usage is not specified as d3dusage_writeonly, which causes serious performance loss. Should be changed:

 

[Copy to clipboard]
Code:
// Create a vertex buffer
If (failed (g_pd3ddevice-> createvertexbuffer (3 * sizeof (customvertex), d3dusage_writeonly, d3dfvf_customvertex, d3dpool_default, & g_pvertexbuffer, null )))
{
Return e_fail;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.