Code Search for Developers
 
 
  

GSTextureCache.h from guliverkli at Krugle


Show GSTextureCache.h syntax highlighted

/* 
 *	Copyright (C) 2003-2005 Gabest
 *	http://www.gabest.org
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma once

#include "GS.h"
#include "GSLocalMemory.h"

template <class T> class CSurfMap : public CMap<DWORD, DWORD, CComPtr<T>, CComPtr<T>& > {};

extern bool IsRenderTarget(IDirect3DTexture9* pTexture);
extern bool HasSharedBits(DWORD sbp, DWORD spsm, DWORD dbp, DWORD dpsm);

// TODO: get rid of this *PrivateData

#ifdef __INTEL_COMPILER
struct __declspec(uuid("5D5EFE0E-5407-4BCF-855D-C46CBCD075FA"))
#else
[uuid("5D5EFE0E-5407-4BCF-855D-C46CBCD075FA")] struct 
#endif
scale_t
{
	float x, y;
	struct scale_t() {x = y = 1;}
	struct scale_t(float x, float y) {this->x = x; this->y = y;}
	struct scale_t(IDirect3DResource9* p) {Get(p);}
	bool operator == (const struct scale_t& s) {return fabs(x - s.x) < 0.001 && fabs(y - s.y) < 0.001;}
	void Set(IDirect3DResource9* p) {p->SetPrivateData(__uuidof(*this), this, sizeof(*this), 0);}
	void Get(IDirect3DResource9* p) {DWORD size = sizeof(*this); p->GetPrivateData(__uuidof(*this), this, &size);}
};

class GSDirtyRect
{
	DWORD m_PSM;
	CRect m_rcDirty;

public:
	GSDirtyRect() : m_PSM(PSM_PSMCT32), m_rcDirty(0, 0, 0, 0) {}
	GSDirtyRect(DWORD PSM, CRect r);
	CRect GetDirtyRect(const GIFRegTEX0& TEX0);
};

class GSDirtyRectList : public CAtlList<GSDirtyRect>
{
public:
	GSDirtyRectList() {}
	GSDirtyRectList(const GSDirtyRectList& l) {*this = l;}
	void operator = (const GSDirtyRectList& l);
	CRect GetDirtyRect(const GIFRegTEX0& TEX0);
};

struct GSTextureBase
{
	CComPtr<IDirect3DTexture9> m_pTexture, m_pPalette;
	scale_t m_scale;
	bool m_fRT;
	D3DSURFACE_DESC m_desc;

	GSTextureBase();
};

struct GSTexture : public GSTextureBase
{
	GIFRegCLAMP m_CLAMP;
	GIFRegTEX0 m_TEX0;
	GIFRegTEXA m_TEXA; // *
	DWORD m_clut[256]; // *
	GSDirtyRectList m_rcDirty;
	CRect m_rcValid;
	CRect m_rcHash;
	DWORD m_dwHash, m_nHashDiff, m_nHashSame;
	DWORD m_nBytes;
	int m_nAge, m_nVsyncs;
	CInterfaceList<IDirect3DTexture9> m_pSubTextures;
	bool m_fTemp;

	GSTexture();
};

class GSState;

class GSTextureCache : private CAtlList<GSTexture*>
{
protected:
	CInterfaceList<IDirect3DTexture9> m_pTexturePool;
	HRESULT CreateTexture(GSState* s, GSTexture* pt, DWORD PSM, DWORD CPSM = PSM_PSMCT32);
	bool IsTextureInCache(IDirect3DTexture9* pTexture);
	void RemoveOldTextures(GSState* s);
	bool GetDirtyRect(GSState* s, GSTexture* pt, CRect& r);

	DWORD HashTexture(const CRect& r, int pitch, void* bits);
	HRESULT UpdateTexture(GSState* s, GSTexture* pt, GSLocalMemory::readTexture rt);

	GSTexture* ConvertRT(GSState* s, GSTexture* pt);
	GSTexture* ConvertRTPitch(GSState* s, GSTexture* pt);
	GSTexture* ConvertRTWidthHeight(GSState* s, GSTexture* pt);

	CInterfaceList<IDirect3DTexture9> m_pRTPool;
	HRESULT CreateRT(GSState* s, int w, int h, IDirect3DTexture9** ppRT);

public:
	GSTextureCache();
	~GSTextureCache();

	bool Fetch(GSState* s, GSTextureBase& t);
	bool FetchP(GSState* s, GSTextureBase& t);
	bool FetchNP(GSState* s, GSTextureBase& t);

	void IncAge(CSurfMap<IDirect3DTexture9>& pRTs);
	void ResetAge(DWORD TBP0);
	void RemoveAll();
	void InvalidateTexture(GSState* s, const GIFRegBITBLTBUF& BITBLTBUF, const CRect& r);
	void InvalidateLocalMem(GSState* s, DWORD TBP0, DWORD BW, DWORD PSM, const CRect& r);
	void AddRT(GIFRegTEX0& TEX0, IDirect3DTexture9* pRT, scale_t scale);
};




See more files for this project here

guliverkli

Home of VobSub, Media Player Classic (MPC) and other misc utils.

Project homepage: http://sourceforge.net/projects/guliverkli
Programming language(s): C,C++,PHP
License: other

  res/
    GSdx9.rc2
    hlsl_merge.fx
    hlsl_rb.fx
    hlsl_tfx.fx
    logo1.bmp
    ps11_en00.psh
    ps11_en01.psh
    ps11_en10.psh
    ps11_en11.psh
    ps11_tfx000.psh
    ps11_tfx010.psh
    ps11_tfx011.psh
    ps11_tfx1x0.psh
    ps11_tfx1x1.psh
    ps11_tfx200.psh
    ps11_tfx210.psh
    ps11_tfx211.psh
    ps11_tfx300.psh
    ps11_tfx310.psh
    ps11_tfx311.psh
    ps11_tfx4xx.psh
    ps14_en00.psh
    ps14_en01.psh
    ps14_en10.psh
    ps14_en11.psh
  GS.cpp
  GS.h
  GSCapture.cpp
  GSCapture.h
  GSCaptureDlg.cpp
  GSCaptureDlg.h
  GSHash.cpp
  GSHash.h
  GSLocalMemory.cpp
  GSLocalMemory.h
  GSPerfMon.cpp
  GSPerfMon.h
  GSRegs.cpp
  GSRenderer.cpp
  GSRenderer.h
  GSRendererHW.cpp
  GSRendererHW.h
  GSRendererNull.cpp
  GSRendererNull.h
  GSRendererSoft.cpp
  GSRendererSoft.h
  GSSettingsDlg.cpp
  GSSettingsDlg.h
  GSSoftVertex.cpp
  GSSoftVertex.h
  GSState.cpp
  GSState.h
  GSTables.cpp
  GSTables.h
  GSTextureCache.cpp
  GSTextureCache.h
  GSTransfer.cpp
  GSUtil.cpp
  GSUtil.h
  GSVertexList.cpp
  GSVertexList.h
  GSWnd.cpp
  GSWnd.h
  GSdx9.cpp
  GSdx9.def
  GSdx9.h
  GSdx9.icproj
  GSdx9.rc
  GSdx9.sln
  GSdx9.vcproj
  GSdx9_ic.sln
  GSdx9_vs2005.sln
  GSdx9_vs2005.vcproj
  resource.h
  stdafx.cpp
  stdafx.h
  x86-32.asm
  x86-64.asm
  x86.cpp
  x86.h