16
ShaderX3 6.1 An Extensible Direct3D Resource Management System Shader study 2007.7.25 이이이

ShaderX3 6.1 An Extensible Direct3D Resource Management System

  • Upload
    noe

  • View
    21

  • Download
    0

Embed Size (px)

DESCRIPTION

ShaderX3 6.1 An Extensible Direct3D Resource Management System. Shader study 2007.7.25 이동 현. But Why?. Game and Windows applications can exist together on the desktop. When some event occurs, all video memory resources owned by the game can be lost. - PowerPoint PPT Presentation

Citation preview

Page 1: ShaderX3 6.1 An Extensible Direct3D Resource Management System

ShaderX3 6.1 An Extensi-ble Direct3D Resource Management System

Shader study2007.7.25

이동현

Page 2: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But Why? Game and Windows applications can exist to-

gether on the desktop. When some event occurs, all video memory re-

sources owned by the game can be lost. Lost video memory need to be restored before

they can be used again. Changing from HAL to REF Rasterizer.

• What the hell…( if your frame rate counter drops from 60FPS to 60SPF!!!)

• But this is not easy, because your 3d device becomes lost.

Page 3: ShaderX3 6.1 An Extensible Direct3D Resource Management System

Solution Disable application and relevant key combos.(Alt-

tab…)• It gives a negative felling to end-users.

You must keep track of each and every Direct3D resource you created in your application.

“Notifications” – use virtual functions to deal with all Direct3D resources.• Per-instance basis. So we have to add annoying restoration

code for each D3D resource instance.• This is not suitable for large scale applications.

Page 4: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But When? If a d3d app is minimized, or switched to another

app using Alt-Tab.• The surfaces that are located in display could be lost.

When changing display modes, display memory surfaces will be lost.

Device lost scenarios.• Full screen display mode -> minimized to different desktop dis-

play mode.• A power management event( e.g., sleep or standby)• Device running in windowed mode. Some process causes desk-

top display mode to change.• Failure of the IDirect3DDevice9::Reset() method.• A mysterious internal driver error. This is rare but happens.

Page 5: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But When? When device is reset( IDirect3DDevice9::Reset()).

• Release all resources allocated in D3DPOOL_DEFAULT. When device is recreted.

• All must be released no matter what pool it is placed in.

Page 6: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But How? SXProbe

• This will be responsible for “probing” the device to know whether it is lost or not.

SXResource• This is a base class that will be used to wrap Direct3D resources

needed to persist device loss and recreation.

SXResource

SXProbe

SXTexture SXVertexBuffer

D3DDeviceAttach

Page 7: ShaderX3 6.1 An Extensible Direct3D Resource Management System

SXResource

Reset devicebefore m_pD3DDevice->Re-

set

Detach Device or Re-Create Device

Reset deviceafter m_pD3DDevice->Reset

orCreated( Re- ) device

Page 8: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But Where? “A lost device must recreate resources (including

video memory resources) after it has been reset. If a device is lost, the application queries the de-vice to see if it can be restored to the operational state. If not, the application waits until the device can be restored” – [DXSDK02]

Attach D3DDevice to SXProbe

Page 9: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But Where? Place our probe

• Prior to rendering a scene. For example, just before IDirect3DDevice9::BeginScene(); This is usually better, simply because this way the application can avoid

rendering at all if the device is lost and cannot be restored at the moment.• Just after calling IDirect3DDevice9::Present.

This works by intercepting the call’s return value, and resetting the device upon failure.

Page 10: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But Where?

Page 11: ShaderX3 6.1 An Extensible Direct3D Resource Management System

But What? All video memory must be released before a device

can be reset from a lost state to an operational state.• Any swap chains – IDirect3DDevice9::CreateAdditionalSwapChain.• Any resources placed in the D3DPOOL_DEFAULT memory class. • Need not release resources in the D3DPOOL_MANAGED or D3D-

POOL_SYSTEMMEM memory classes.• Other state data is automatically destroyed by the transition to an

operational state. For device recreate, every Direct3D resources must

be released. Static vertex buffer -> placed in video memory Dynamic vertex buffer -> placed in AGP memory.

Page 12: ShaderX3 6.1 An Extensible Direct3D Resource Management System

Benefits Persistent States

• In order to guarantee that are always correctly applied to the device no matter if it gets lost/recreated, a class can inherit from SXResource.

Memory Approximation• If the D3DPOOL_DEFAULT resources, check the backup copy.• Rough estimation.

Event-based Device State Information• An application can inject an “information resource”• Ex) When an application wants to suspend its operation upon

device loss. Device Memory Management

• The Direct3D API recommends all D3DPOOL_DEFAULT resource first, then following them by D3DPOOL_MANAGED ones.

Page 13: ShaderX3 6.1 An Extensible Direct3D Resource Management System

Managing Resources Base d3d management algorithm is “least-recently-

used priority” In a single frame, switches to a most-recently-used

priority.(between BeginScene and EndScene) D3DPOOL_MANAGED flag

• Persist through transitions between the lost and operational states of the device.

• The device can be restored with a call to …::Reset()• But if the device must be destroyed and re-created, all resources

created using D3DPOOL_MANAGED must be re-created. D3DPOOL_DEFAULT flag

• Not persist through transitions between the lost and operational states of the device.

• These resources must be released before calling reset.

Page 14: ShaderX3 6.1 An Extensible Direct3D Resource Management System

Resource Management Best Practices

D3DSDK Document 참고 하세요

Page 15: ShaderX3 6.1 An Extensible Direct3D Resource Management System

Video memory

Local video memory

Non-local video memory

Page 16: ShaderX3 6.1 An Extensible Direct3D Resource Management System