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
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, 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"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
__aligned(class, 32) GSRasterizerData
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GSVector4i scissor;
|
2011-03-27 03:12:12 +00:00
|
|
|
bool scissor_test;
|
2009-02-09 21:15:56 +00:00
|
|
|
GS_PRIM_CLASS primclass;
|
|
|
|
const GSVertexSW* vertices;
|
|
|
|
int count;
|
2011-02-17 03:24:37 +00:00
|
|
|
uint64 frame;
|
2009-02-09 21:15:56 +00:00
|
|
|
const void* param;
|
2011-03-27 03:12:12 +00:00
|
|
|
|
|
|
|
GSRasterizerData() : scissor_test(true) {}
|
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:
|
2011-02-16 03:19:36 +00:00
|
|
|
typedef void (__fastcall *SetupPrimPtr)(const GSVertexSW* vertices, 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() {}
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
virtual void BeginDraw(const void* param) = 0;
|
2011-02-17 03:24:37 +00:00
|
|
|
virtual void EndDraw(const GSRasterizerStats& stats, uint64 frame) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual void PrintStats() = 0;
|
2011-02-16 03:19:36 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
__forceinline void SetupPrim(const GSVertexSW* vertices, const GSVertexSW& dscan) {m_sp(vertices, 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);}
|
|
|
|
|
|
|
|
__forceinline bool IsEdge() const {return m_de != NULL;}
|
|
|
|
__forceinline bool IsRect() const {return m_dr != NULL;}
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
class IRasterizer
|
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-02-16 03:19:36 +00:00
|
|
|
virtual void Draw(const GSRasterizerData* data) = 0;
|
|
|
|
virtual void GetStats(GSRasterizerStats& stats) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual void PrintStats() = 0;
|
2011-02-17 18:22:47 +00:00
|
|
|
virtual void SetThreadId(int id, int threads) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
__aligned(class, 32) GSRasterizer : public GSAlignedClass<32>, public IRasterizer
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
IDrawScanline* m_ds;
|
|
|
|
int m_id;
|
|
|
|
int m_threads;
|
|
|
|
GSRasterizerStats m_stats;
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4i m_scissor;
|
|
|
|
GSVector4 m_fscissor;
|
2011-03-09 11:52:53 +00:00
|
|
|
struct {GSVertexSW* buff; int count;} m_edge;
|
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>
|
|
|
|
void DrawPoint(const GSVertexSW* v, int count);
|
2011-03-08 01:48:15 +00:00
|
|
|
void DrawLine(const GSVertexSW* v);
|
|
|
|
void DrawTriangle(const GSVertexSW* v);
|
|
|
|
void DrawSprite(const GSVertexSW* v);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-27 15:46:32 +00:00
|
|
|
__forceinline void DrawTriangleSection(int top, int bottom, GSVertexSW& edge, const GSVertexSW& dedge, const GSVertexSW& dscan, const GSVector4& x0);
|
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-08 01:48:15 +00:00
|
|
|
__forceinline bool IsOneOfMyScanlines(int scanline) const;
|
2011-03-27 03:12:12 +00:00
|
|
|
__forceinline void AddScanline(GSVertexSW* e, int pixels, int left, int top, const GSVertexSW& scan);
|
2011-03-09 11:52:53 +00:00
|
|
|
__forceinline void Flush(const GSVertexSW* vertices, const GSVertexSW& dscan, bool edge = false);
|
2009-12-03 23:08:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public:
|
2011-02-17 18:22:47 +00:00
|
|
|
GSRasterizer(IDrawScanline* ds);
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual ~GSRasterizer();
|
|
|
|
|
|
|
|
// IRasterizer
|
|
|
|
|
|
|
|
void Draw(const GSRasterizerData* data);
|
|
|
|
void GetStats(GSRasterizerStats& stats);
|
|
|
|
void PrintStats() {m_ds->PrintStats();}
|
2011-02-17 18:22:47 +00:00
|
|
|
void SetThreadId(int id, int threads) {m_id = id; m_threads = threads;}
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
class GSRasterizerMT : public GSRasterizer, private GSThread
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-12-03 23:08:52 +00:00
|
|
|
protected:
|
|
|
|
volatile long& m_sync;
|
2011-02-19 03:36:30 +00:00
|
|
|
GSAutoResetEvent m_draw;
|
2009-02-09 21:15:56 +00:00
|
|
|
const GSRasterizerData* m_data;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
void ThreadProc();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
2011-02-19 03:36:30 +00:00
|
|
|
GSRasterizerMT(IDrawScanline* ds, volatile long& sync);
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual ~GSRasterizerMT();
|
|
|
|
|
|
|
|
// IRasterizer
|
|
|
|
|
|
|
|
void Draw(const GSRasterizerData* data);
|
|
|
|
};
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
class GSRasterizerList : protected vector<IRasterizer*>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-12-03 23:08:52 +00:00
|
|
|
protected:
|
|
|
|
volatile long m_sync;
|
2009-02-09 21:15:56 +00:00
|
|
|
GSRasterizerStats m_stats;
|
2011-02-16 03:19:36 +00:00
|
|
|
int64 m_start;
|
2011-02-17 18:22:47 +00:00
|
|
|
int m_threads;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GSRasterizerList();
|
|
|
|
virtual ~GSRasterizerList();
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
template<class DS> void Create(int threads)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-12 21:45:16 +00:00
|
|
|
threads = std::max<int>(threads, 1); // TODO: min(threads, number of cpu cores)
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
push_back(new GSRasterizer(new DS()));
|
2011-02-16 03:19:36 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
for(int i = 1; i < threads; i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
push_back(new GSRasterizerMT(new DS(), m_sync));
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
void Sync();
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
void Draw(const GSRasterizerData* data, int width, int height);
|
2009-02-09 21:15:56 +00:00
|
|
|
void GetStats(GSRasterizerStats& stats);
|
|
|
|
void PrintStats();
|
|
|
|
};
|