From ce07d2be5a1028866e175bf48456478625127b2a Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Wed, 8 Apr 2015 23:06:17 +0600 Subject: [PATCH] Fix depth buffer creation. Corrected crash in Blast Corps, issue #125 --- DepthBuffer.cpp | 6 ++---- FrameBuffer.cpp | 5 ++++- FrameBufferEmulationIssues.txt | 8 ++++++++ gDP.cpp | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/DepthBuffer.cpp b/DepthBuffer.cpp index 5e9ec099..583d5dbb 100644 --- a/DepthBuffer.cpp +++ b/DepthBuffer.cpp @@ -100,7 +100,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture else { _pTexture->width = video().getWidth(); _pTexture->height = video().getHeight(); - _pTexture->address = VI.lastOrigin; + _pTexture->address = gDP.depthImageAddress; _pTexture->clampWidth = VI.width; _pTexture->clampHeight = VI.height; } @@ -273,9 +273,7 @@ void DepthBufferList::saveBuffer(u32 _address) return; FrameBuffer * pFrameBuffer = frameBufferList().findBuffer(_address); - if (pFrameBuffer == NULL) - pFrameBuffer = frameBufferList().getCurrent(); - else + if (pFrameBuffer != NULL) pFrameBuffer->m_isDepthBuffer = true; if (m_pCurrent == NULL || m_pCurrent->m_address != _address) diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 24a1b584..4bd6a5a4 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -409,7 +409,10 @@ void FrameBufferList::saveBuffer(u32 _address, u16 _format, u16 _size, u16 _widt m_pCurrent = &buffer; } - attachDepthBuffer(); + if (_address == gDP.depthImageAddress) + depthBufferList().saveBuffer(_address); + else + attachDepthBuffer(); #ifdef DEBUG DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "FrameBuffer_SaveBuffer( 0x%08X ); depth buffer is 0x%08X\n", diff --git a/FrameBufferEmulationIssues.txt b/FrameBufferEmulationIssues.txt index cf75ad69..0388d6b9 100644 --- a/FrameBufferEmulationIssues.txt +++ b/FrameBufferEmulationIssues.txt @@ -90,3 +90,11 @@ Pokemon Stadium: Пришлось править код коррекции высоты буфера, и вызывать метод поиска пересечений после коррекции. +Blast Corps: +Возникла проблема с depth image, которая приводила к остановке видео драйвера. Игра создавала вспомогательный depth image +для вспомогательного color image. Адрес вспомогательного depth image совпадал с адресом основного, но ширина ставилась такая же +как у вспомогательного color image. Из-за последовательности команд плагин не вовремя просекал изменение размеров depth image, +что приводило к установке неверного depth buffer для FBO и к краху драйвера. + +Решение: При вызове setcolorimage, если color image == depth image, вызывать depthBufferList().saveBuffer, который +при необходимости пересоздаст depth buffer. diff --git a/gDP.cpp b/gDP.cpp index 3b59e461..59b985b2 100644 --- a/gDP.cpp +++ b/gDP.cpp @@ -192,8 +192,8 @@ void gDPSetTextureImage(u32 format, u32 size, u32 width, u32 address) void gDPSetDepthImage( u32 address ) { address = RSP_SegmentToPhysical( address ); - depthBufferList().saveBuffer(address); gDP.depthImageAddress = address; + depthBufferList().saveBuffer(address); #ifdef DEBUG DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "gDPSetDepthImage( 0x%08X );\n", gDP.depthImageAddress );