2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +00:00
|
|
|
* Copyright (C) 2007-2009 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GS.h"
|
|
|
|
#include "GSVertexSW.h"
|
|
|
|
#include "GSFunctionMap.h"
|
2009-05-14 16:41:52 +00:00
|
|
|
#include "GSThread.h"
|
2009-07-05 00:18:33 +00:00
|
|
|
#include "GSAlignedClass.h"
|
2011-12-22 14:36:54 +00:00
|
|
|
#include "GSPerfMon.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
__aligned(class, 32) GSRasterizerData : public GSAlignedClass<32>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-02-08 16:57:14 +00:00
|
|
|
static int s_counter;
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public:
|
|
|
|
GSVector4i scissor;
|
2011-12-18 08:13:20 +00:00
|
|
|
GSVector4i bbox;
|
2009-02-09 21:15:56 +00:00
|
|
|
GS_PRIM_CLASS primclass;
|
2012-01-05 02:40:24 +00:00
|
|
|
uint8* buff;
|
|
|
|
GSVertexSW* vertex;
|
|
|
|
int vertex_count;
|
|
|
|
uint32* index;
|
|
|
|
int index_count;
|
2011-02-17 03:24:37 +00:00
|
|
|
uint64 frame;
|
2012-02-08 16:57:14 +00:00
|
|
|
uint64 start;
|
|
|
|
int pixels;
|
|
|
|
int counter;
|
2011-12-27 09:15:35 +00:00
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
GSRasterizerData()
|
2011-12-25 07:26:42 +00:00
|
|
|
: scissor(GSVector4i::zero())
|
|
|
|
, bbox(GSVector4i::zero())
|
|
|
|
, primclass(GS_INVALID_CLASS)
|
2012-01-05 02:40:24 +00:00
|
|
|
, buff(NULL)
|
|
|
|
, vertex(NULL)
|
|
|
|
, vertex_count(0)
|
|
|
|
, index(NULL)
|
|
|
|
, index_count(0)
|
2011-12-25 07:26:42 +00:00
|
|
|
, frame(0)
|
2012-02-08 16:57:14 +00:00
|
|
|
, start(0)
|
|
|
|
, pixels(0)
|
2011-12-18 08:13:20 +00:00
|
|
|
{
|
2012-02-08 16:57:14 +00:00
|
|
|
counter = s_counter++;
|
2011-12-18 08:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GSRasterizerData()
|
|
|
|
{
|
2012-01-05 02:40:24 +00:00
|
|
|
if(buff != NULL) _aligned_free(buff);
|
2011-12-22 14:36:54 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
class IDrawScanline : public GSAlignedClass<32>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-01-09 08:41:33 +00:00
|
|
|
typedef void (*SetupPrimPtr)(const GSVertexSW* vertex, const uint32* index, const GSVertexSW& dscan);
|
2011-03-12 22:10:58 +00:00
|
|
|
typedef void (__fastcall *DrawScanlinePtr)(int pixels, int left, int top, const GSVertexSW& scan);
|
2011-02-16 03:19:36 +00:00
|
|
|
typedef void (IDrawScanline::*DrawRectPtr)(const GSVector4i& r, const GSVertexSW& v); // TODO: jit
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
protected:
|
|
|
|
SetupPrimPtr m_sp;
|
|
|
|
DrawScanlinePtr m_ds;
|
|
|
|
DrawScanlinePtr m_de;
|
|
|
|
DrawRectPtr m_dr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
IDrawScanline() : m_sp(NULL), m_ds(NULL), m_de(NULL), m_dr(NULL) {}
|
|
|
|
virtual ~IDrawScanline() {}
|
|
|
|
|
2012-01-08 17:10:00 +00:00
|
|
|
virtual void BeginDraw(const GSRasterizerData* data) = 0;
|
2011-12-18 08:13:20 +00:00
|
|
|
virtual void EndDraw(uint64 frame, uint64 ticks, int pixels) = 0;
|
2011-02-16 03:19:36 +00:00
|
|
|
|
2011-12-16 19:13:58 +00:00
|
|
|
#ifdef ENABLE_JIT_RASTERIZER
|
2011-11-25 23:48:59 +00:00
|
|
|
|
2012-01-09 08:41:33 +00:00
|
|
|
__forceinline void SetupPrim(const GSVertexSW* vertex, const uint32* index, const GSVertexSW& dscan) {m_sp(vertex, index, dscan);}
|
2011-03-27 03:12:12 +00:00
|
|
|
__forceinline void DrawScanline(int pixels, int left, int top, const GSVertexSW& scan) {m_ds(pixels, left, top, scan);}
|
|
|
|
__forceinline void DrawEdge(int pixels, int left, int top, const GSVertexSW& scan) {m_de(pixels, left, top, scan);}
|
2011-02-16 03:19:36 +00:00
|
|
|
__forceinline void DrawRect(const GSVector4i& r, const GSVertexSW& v) {(this->*m_dr)(r, v);}
|
|
|
|
|
2011-11-25 23:48:59 +00:00
|
|
|
#else
|
|
|
|
|
2012-01-09 08:41:33 +00:00
|
|
|
virtual void SetupPrim(const GSVertexSW* vertex, const uint32* index, const GSVertexSW& dscan) = 0;
|
2011-11-25 23:48:59 +00:00
|
|
|
virtual void DrawScanline(int pixels, int left, int top, const GSVertexSW& scan) = 0;
|
|
|
|
virtual void DrawEdge(int pixels, int left, int top, const GSVertexSW& scan) = 0;
|
|
|
|
virtual void DrawRect(const GSVector4i& r, const GSVertexSW& v) = 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
__forceinline bool HasEdge() const {return m_de != NULL;}
|
2012-01-13 18:10:05 +00:00
|
|
|
__forceinline bool IsSolidRect() const {return m_dr != NULL;}
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
class IRasterizer : public GSAlignedClass<32>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-02-16 03:19:36 +00:00
|
|
|
virtual ~IRasterizer() {}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
virtual void Queue(shared_ptr<GSRasterizerData> data) = 0;
|
|
|
|
virtual void Sync() = 0;
|
2012-01-18 11:47:31 +00:00
|
|
|
virtual bool IsSynced() const = 0;
|
2012-01-08 17:10:00 +00:00
|
|
|
virtual int GetPixels(bool reset = true) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
__aligned(class, 32) GSRasterizer : public IRasterizer
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
2011-12-22 01:48:16 +00:00
|
|
|
GSPerfMon* m_perfmon;
|
2009-02-09 21:15:56 +00:00
|
|
|
IDrawScanline* m_ds;
|
|
|
|
int m_id;
|
|
|
|
int m_threads;
|
2012-01-18 11:47:31 +00:00
|
|
|
uint8* m_scanline;
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4i m_scissor;
|
2011-12-31 15:41:07 +00:00
|
|
|
GSVector4 m_fscissor_x;
|
|
|
|
GSVector4 m_fscissor_y;
|
2011-03-09 11:52:53 +00:00
|
|
|
struct {GSVertexSW* buff; int count;} m_edge;
|
2011-12-18 08:13:20 +00:00
|
|
|
int m_pixels;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-27 03:12:12 +00:00
|
|
|
typedef void (GSRasterizer::*DrawPrimPtr)(const GSVertexSW* v, int count);
|
|
|
|
|
|
|
|
template<bool scissor_test>
|
2012-01-05 02:40:24 +00:00
|
|
|
void DrawPoint(const GSVertexSW* vertex, int vertex_count, const uint32* index, int index_count);
|
|
|
|
void DrawLine(const GSVertexSW* vertex, const uint32* index);
|
|
|
|
void DrawTriangle(const GSVertexSW* vertex, const uint32* index);
|
2012-01-13 18:10:05 +00:00
|
|
|
void DrawSprite(const GSVertexSW* vertex, const uint32* index);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-12-16 19:13:58 +00:00
|
|
|
__forceinline void DrawTriangleSection(int top, int bottom, GSVertexSW& edge, const GSVertexSW& dedge, const GSVertexSW& dscan, const GSVector4& p0);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
void DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GSVertexSW& dv, int orientation, int side);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-27 03:12:12 +00:00
|
|
|
__forceinline void AddScanline(GSVertexSW* e, int pixels, int left, int top, const GSVertexSW& scan);
|
2012-01-09 08:41:33 +00:00
|
|
|
__forceinline void Flush(const GSVertexSW* vertex, const uint32* index, const GSVertexSW& dscan, bool edge = false);
|
2009-12-03 23:08:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public:
|
2011-12-22 01:48:16 +00:00
|
|
|
GSRasterizer(IDrawScanline* ds, int id, int threads, GSPerfMon* perfmon);
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual ~GSRasterizer();
|
|
|
|
|
2011-12-23 15:53:53 +00:00
|
|
|
__forceinline bool IsOneOfMyScanlines(int top) const;
|
2011-12-18 21:57:48 +00:00
|
|
|
__forceinline bool IsOneOfMyScanlines(int top, int bottom) const;
|
2011-12-23 15:53:53 +00:00
|
|
|
__forceinline int FindMyNextScanline(int top) const;
|
2011-12-18 21:57:48 +00:00
|
|
|
|
2012-01-08 17:10:00 +00:00
|
|
|
void Draw(GSRasterizerData* data);
|
2011-12-18 08:13:20 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
// IRasterizer
|
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
void Queue(shared_ptr<GSRasterizerData> data);
|
2011-12-20 14:33:28 +00:00
|
|
|
void Sync() {}
|
2012-01-18 11:47:31 +00:00
|
|
|
bool IsSynced() const {return true;}
|
2012-01-08 17:10:00 +00:00
|
|
|
int GetPixels(bool reset);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-12-22 14:36:54 +00:00
|
|
|
class GSRasterizerList
|
|
|
|
: public IRasterizer
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-12-03 23:08:52 +00:00
|
|
|
protected:
|
2011-12-22 14:36:54 +00:00
|
|
|
class GSWorker : public GSJobQueue<shared_ptr<GSRasterizerData> >
|
|
|
|
{
|
|
|
|
GSRasterizer* m_r;
|
2011-12-22 01:48:16 +00:00
|
|
|
|
2011-12-22 14:36:54 +00:00
|
|
|
public:
|
|
|
|
GSWorker(GSRasterizer* r);
|
|
|
|
virtual ~GSWorker();
|
2011-12-22 01:48:16 +00:00
|
|
|
|
2012-01-08 17:10:00 +00:00
|
|
|
int GetPixels(bool reset);
|
|
|
|
|
2011-12-22 14:36:54 +00:00
|
|
|
// GSJobQueue
|
2011-12-22 01:48:16 +00:00
|
|
|
|
2011-12-22 14:36:54 +00:00
|
|
|
void Process(shared_ptr<GSRasterizerData>& item);
|
|
|
|
};
|
2011-12-22 01:48:16 +00:00
|
|
|
|
2012-01-18 11:47:31 +00:00
|
|
|
GSPerfMon* m_perfmon;
|
2011-12-22 14:36:54 +00:00
|
|
|
vector<GSWorker*> m_workers;
|
2012-01-18 11:47:31 +00:00
|
|
|
uint8* m_scanline;
|
2011-12-22 01:48:16 +00:00
|
|
|
|
2012-01-18 11:47:31 +00:00
|
|
|
GSRasterizerList(int threads, GSPerfMon* perfmon);
|
2011-12-18 08:13:20 +00:00
|
|
|
|
|
|
|
public:
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual ~GSRasterizerList();
|
|
|
|
|
2011-12-22 01:48:16 +00:00
|
|
|
template<class DS> static IRasterizer* Create(int threads, GSPerfMon* perfmon)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-12-20 14:33:28 +00:00
|
|
|
threads = std::max<int>(threads, 0);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-12-20 14:33:28 +00:00
|
|
|
if(threads == 0)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-12-22 01:48:16 +00:00
|
|
|
return new GSRasterizer(new DS(), 0, 1, perfmon);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2011-12-20 14:33:28 +00:00
|
|
|
else
|
|
|
|
{
|
2012-01-18 11:47:31 +00:00
|
|
|
GSRasterizerList* rl = new GSRasterizerList(threads, perfmon);
|
2011-12-18 08:13:20 +00:00
|
|
|
|
2011-12-20 14:33:28 +00:00
|
|
|
for(int i = 0; i < threads; i++)
|
|
|
|
{
|
2011-12-22 14:36:54 +00:00
|
|
|
rl->m_workers.push_back(new GSWorker(new GSRasterizer(new DS(), i, threads, perfmon)));
|
2011-12-20 14:33:28 +00:00
|
|
|
}
|
2011-12-18 21:57:48 +00:00
|
|
|
|
2011-12-20 14:33:28 +00:00
|
|
|
return rl;
|
|
|
|
}
|
|
|
|
}
|
2011-12-18 21:57:48 +00:00
|
|
|
|
|
|
|
// IRasterizer
|
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
void Queue(shared_ptr<GSRasterizerData> data);
|
2011-12-16 19:13:58 +00:00
|
|
|
void Sync();
|
2012-01-18 11:47:31 +00:00
|
|
|
bool IsSynced() const;
|
2012-01-08 17:10:00 +00:00
|
|
|
int GetPixels(bool reset);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|