Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Kako povratiti d3d device posle device lost-a ?

[es] :: 3D programiranje :: Kako povratiti d3d device posle device lost-a ?

[ Pregleda: 4043 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

eva01

Član broj: 49540
Poruke: 120
*.ptt.yu.

Jabber: eva01@jabber.3gnt.org


Profil

icon Kako povratiti d3d device posle device lost-a ?23.02.2005. u 13:16 - pre 232 meseci
Dakle procitao sam dokumentaciju uz direct 3d. Otprilike mi je jasno sta treba da uradim. Ono sto mi nije jasno jeste prvi korak koji su oni tamo naveli:

If the device can be restored, the application prepares the device by destroying all video-memory resources and any swap chains. Nije mi bas jasno sta konkretno treba da unistim. Takodje me interesuje i dali je potrebno nesto dodatno inicijalizovati posle device->Reset() ?

Dole sam naveo kod iz mog programa (mozda sam tu nesto pogresio).

Code:

deviceGreska=device->TestCooperativeLevel();
if(D3DERR_DEVICELOST==deviceGreska) {
      oslobadjanje_resursa();
      Sleep(100);

else if(D3DERR_DEVICENOTRESET==deviceGreska) {
      device->Reset(d3dpp);
}
else if(SUCCEEDED(deviceGreska=device->BeginScene())) {
.................
.................
}

 
Odgovor na temu

bkaradzic
Branimir Karadžić
ArenaNet
Seattle, WA

Član broj: 14953
Poruke: 1630
*.pandemicstudios.com.

Sajt: https://github.com/bkarad..


+11 Profil

icon Re: Kako povratiti d3d device posle device lost-a ?23.02.2005. u 23:41 - pre 232 meseci
Ovako bi trebao da ti izgleda deo za resetovanje:

Code:
HRESULT hResult;

hResult = m_pDevice->Present(NULL, NULL, NULL, NULL);

if ( D3DERR_DEVICELOST == hResult )
{
  // D3D razdevičen :)
  MSG msg;

  do 
  {
    // daj drugim procesima Šansu da "dišu"...
    if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
    {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }

    Sleep(100);

    // čekaj dok ne dobiješ odgovor da je D3D spreman za reset
    hResult = m_pDevice->TestCooperativeLevel();
  }
  while ( D3DERR_DEVICENOTRESET != hResult );
}

// ovaj deo koda možeš da koristiš za ALT-ENTER prebacivanje iz windowed 
// u full screen mod i za menjanje rezolucije
if ( D3DERR_DEVICENOTRESET == hResult )
{
  do
  {
    // izbriši sve dinamičke resurse

    m_pDevice->Reset(m_pPresentParameters);

    // kreiraj sve dinamičke resurse, ali ako bilo koji vrati 
    // negativan rezultat ponavljaj ovaj proces
  }
  while ( FAILED(hResult) )
}


Uključi maksimum debug level u D3D control panel-u pa će se posle Reseta ispisati šta je razlog neuspeha. Biće izlistane svi resursi koje trebaš da oslobodiš pre Reset poziva. U XP kada pritisneš CTRL-ALT-DEL automatski odmah dobijaš device lost (bez obzira da li radiš windowed ili full screen).

Branimir

 
Odgovor na temu

eva01

Član broj: 49540
Poruke: 120
*.ptt.yu.

Jabber: eva01@jabber.3gnt.org


Profil

icon Re: Kako povratiti d3d device posle device lost-a ?24.02.2005. u 01:33 - pre 232 meseci
Ukljucio sam d3d debag info. na maksimum ali mi i dalje nije jasno sta treba da oslobodim. Greska koju javlja je:

Citat:

Direct3D9: (ERROR) :All user created stateblocks must be freed before Reset can succeed. Reset Fails.


Nije mi jasno na sta se pod ovim konkretno misli. Sta je state block ?
Jedino sto sam ucitao u d3d su vertex i index bafer i teksture. Takodje koristio sam i ID3DXFont ali ako sam dobro shvatio on ima metod onLostDevice kojim oslobadja sve sto je potrebno. Valjda ne moram da unistavam verteks i indeks bafer (negde na net-u sam procitao da to nije neophodno).

Takodje sam oslobodio zbafer i swap chain (back buffer). Ovo je kao neophodno navedeno u d3d help-u. Evo i koda za to (uvek se plasim da nesto ne brljam pri ovakvim operacijama):

Code:

LPDIRECT3DSURFACE9 pZBuffer;
device->GetDepthStencilSurface(&pZBuffer);
pZBuffer->Release();

LPDIRECT3DSURFACE9 bBafer;
device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &bBafer);
bBafer->Release();

IDirect3DSwapChain9 *swapChain;
device->GetSwapChain(0, &swapChain);
swapChain->Release();
 
Odgovor na temu

bkaradzic
Branimir Karadžić
ArenaNet
Seattle, WA

Član broj: 14953
Poruke: 1630
*.pandemicstudios.com.

Sajt: https://github.com/bkarad..


+11 Profil

icon Re: Kako povratiti d3d device posle device lost-a ?24.02.2005. u 01:51 - pre 232 meseci
Citat:
eva 01: Nije mi jasno na sta se pod ovim konkretno misli. Sta je state block ?

Evo objašnjenja:
Citat:
What Is a State Block?

Before we get too deep into the discussion, we need to make sure we all know what state blocks are and how they are used. The XDK documentation is the proper place for this, but I'm happy to give you the basics here.

In DirectX 8, state blocks are essentially objects that contain a snapshot of a large number of D3D states (render states, current textures, materials, lights, shaders, and so on). State blocks are created and destroyed with calls to D3DDevice::CreateStateBlock and D3DDevice::DeleteStateBlock.

When created, a state block allocates memory for space to save all the states and then proceeds to "capture" or record the system's current state. At any later time, the application can then call D3DDevice::ApplyStateBlock and all the previously set state will again be set. The advantage is having one API call versus many individual state settings calls. From an engine design point-of-view, you may already be thinking in terms of broader effects (like an alpha-only pass with alpha-blending on, z-testing on, and z-writes disabled) in which case it's more convenient to organize state into larger groupings.

An existing state block can be updated with a call to D3DDevice::UpdateStateBlock. This will replace the contents of the state block with a snapshot of the system state at the time of that call. This would be useful for dynamic state blocks where you are trying to do the following:

1. Preserve state
2. Set new state
3. Render object
4. Restore previous state

So far, you may be thinking that state blocks sound like a good thing. The problem is the rather brain dead way that state blocks are implemented and that they sometimes record the entire state of the device (literally hundreds of states) because they don't have the foresight to know which states will need to be restored later on.

Ako ne koristiš state block nigde onda verovatno koristiš neku D3DX klasu koja koristi... Ja obično ne koristim D3DX pa nemam pojma šta bi moglo da bude u pitanju. Počni da eliminišeš delove koda pa ćeš videti šta uzrokuje ovaj problem.
Citat:
eva 01: Valjda ne moram da unistavam verteks i indeks bafer (negde na net-u sam procitao da to nije neophodno).

Zavisi kako si ih kreirao. Ako su u D3DPOOL_DEFAULT onda moraš...
Citat:
Reset will fail unless the application releases all resources that are allocated in D3DPOOL_DEFAULT, including those created by the IDirect3DDevice9::CreateRenderTarget and IDirect3DDevice9::CreateDepthStencilSurface methods.

http://msdn.microsoft.com/libr...irect3ddevices/lostdevices.asp

Branimir

 
Odgovor na temu

eva01

Član broj: 49540
Poruke: 120
*.ptt.yu.

Jabber: eva01@jabber.3gnt.org


Profil

icon Re: Kako povratiti d3d device posle device lost-a ?24.02.2005. u 02:56 - pre 232 meseci
Hvala na pomoci. Konacno sam resio taj problem. Promakao mi je jedan ID3DXFont.
 
Odgovor na temu

[es] :: 3D programiranje :: Kako povratiti d3d device posle device lost-a ?

[ Pregleda: 4043 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.