1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-07 03:13:49 +00:00

Fix multi-threaded work of DePosterize.

Fixed #1301
This commit is contained in:
Sergey Lipskiy 2016-12-15 18:02:07 +07:00
parent 9cb094a99a
commit e8522e7034
4 changed files with 19 additions and 14 deletions

View File

@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <vector>
#include "TextureFilters.h" #include "TextureFilters.h"
#include "TxUtil.h" #include "TxUtil.h"
@ -745,7 +746,8 @@ void deposterizeV(uint32* data, uint32* out, int w, int h, int l, int u) {
static static
void DePosterize(uint32* source, uint32* dest, int width, int height) { void DePosterize(uint32* source, uint32* dest, int width, int height) {
uint32 * buf = (uint32*)TxMemBuf::getInstance()->get(3); std::vector<uint32> tmpvec(width*height);
uint32 * buf = tmpvec.data();
deposterizeH(source, buf, width, 0, height); deposterizeH(source, buf, width, 0, height);
deposterizeV(buf, dest, width, height, 0, height); deposterizeV(buf, dest, width, height, 0, height);
deposterizeH(dest, buf, width, 0, height); deposterizeH(dest, buf, width, 0, height);
@ -753,8 +755,10 @@ void DePosterize(uint32* source, uint32* dest, int width, int height) {
} }
void filter_8888(uint32 *src, uint32 srcwidth, uint32 srcheight, uint32 *dest, uint32 filter) { void filter_8888(uint32 *src, uint32 srcwidth, uint32 srcheight, uint32 *dest, uint32 filter) {
std::vector<uint32> tmpvec;
if (filter & DEPOSTERIZE) { if (filter & DEPOSTERIZE) {
uint32 * tex = (uint32*)TxMemBuf::getInstance()->get(2); tmpvec.resize(srcwidth * srcheight);
uint32 * tex = tmpvec.data();
DePosterize(src, tex, srcwidth, srcheight); DePosterize(src, tex, srcwidth, srcheight);
src = tex; src = tex;
} }

View File

@ -116,7 +116,7 @@ TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options,
if (ident && wcscmp(ident, wst("DEFAULT")) != 0) if (ident && wcscmp(ident, wst("DEFAULT")) != 0)
_ident.assign(ident); _ident.assign(ident);
if (TxMemBuf::getInstance()->init(_maxwidth, _maxheight, (_options & DEPOSTERIZE) ? 1 : 0)) { if (TxMemBuf::getInstance()->init(_maxwidth, _maxheight)) {
if (!_tex1) if (!_tex1)
_tex1 = TxMemBuf::getInstance()->get(0); _tex1 = TxMemBuf::getInstance()->get(0);

View File

@ -25,6 +25,7 @@
#include "TxDbg.h" #include "TxDbg.h"
#include <zlib.h> #include <zlib.h>
#include <malloc.h> #include <malloc.h>
#include <assert.h>
#if defined (OS_MAC_OS_X) #if defined (OS_MAC_OS_X)
#include <sys/param.h> #include <sys/param.h>
@ -530,7 +531,7 @@ TxUtil::getNumberofProcessors()
TxMemBuf::TxMemBuf() TxMemBuf::TxMemBuf()
{ {
int i; int i;
for (i = 0; i < 4; i++) { for (i = 0; i < 2; i++) {
_tex[i] = nullptr; _tex[i] = nullptr;
_size[i] = 0; _size[i] = 0;
} }
@ -542,10 +543,9 @@ TxMemBuf::~TxMemBuf()
} }
boolean boolean
TxMemBuf::init(int maxwidth, int maxheight, boolean deposterize) TxMemBuf::init(int maxwidth, int maxheight)
{ {
_numBufs = deposterize ? 4 : 2; for (uint32 i = 0; i < 2; i++) {
for (uint32 i = 0; i < _numBufs; i++) {
if (!_tex[i]) { if (!_tex[i]) {
_tex[i] = (uint8 *)malloc(maxwidth * maxheight * 4); _tex[i] = (uint8 *)malloc(maxwidth * maxheight * 4);
_size[i] = maxwidth * maxheight * 4; _size[i] = maxwidth * maxheight * 4;
@ -563,7 +563,7 @@ void
TxMemBuf::shutdown() TxMemBuf::shutdown()
{ {
int i; int i;
for (i = 0; i < _numBufs; i++) { for (i = 0; i < 2; i++) {
if (_tex[i]) free(_tex[i]); if (_tex[i]) free(_tex[i]);
_tex[i] = nullptr; _tex[i] = nullptr;
_size[i] = 0; _size[i] = 0;
@ -573,13 +573,15 @@ TxMemBuf::shutdown()
uint8* uint8*
TxMemBuf::get(unsigned int num) TxMemBuf::get(unsigned int num)
{ {
return ((num < _numBufs) ? _tex[num] : nullptr); assert(num < 2);
return _tex[num];
} }
uint32 uint32
TxMemBuf::size_of(unsigned int num) TxMemBuf::size_of(unsigned int num)
{ {
return ((num < _numBufs) ? _size[num] : 0); assert(num < 2);
return _size[num];
} }
void setTextureFormat(uint16 internalFormat, GHQTexInfo * info) void setTextureFormat(uint16 internalFormat, GHQTexInfo * info)

View File

@ -56,9 +56,8 @@ public:
class TxMemBuf class TxMemBuf
{ {
private: private:
uint8 *_tex[4]; uint8 *_tex[2];
uint32 _size[4]; uint32 _size[2];
uint32 _numBufs;
TxMemBuf(); TxMemBuf();
public: public:
static TxMemBuf* getInstance() { static TxMemBuf* getInstance() {
@ -66,7 +65,7 @@ public:
return &txMemBuf; return &txMemBuf;
} }
~TxMemBuf(); ~TxMemBuf();
boolean init(int maxwidth, int maxheight, boolean deposterize); boolean init(int maxwidth, int maxheight);
void shutdown(void); void shutdown(void);
uint8 *get(unsigned int num); uint8 *get(unsigned int num);
uint32 size_of(unsigned int num); uint32 size_of(unsigned int num);