2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2010-04-24 21:37:39 +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
|
|
|
*
|
2010-04-24 21:37:39 +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
|
|
|
*
|
2010-04-24 21:37:39 +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.
|
2010-04-24 21:37:39 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GSLocalMemory.h"
|
|
|
|
#include "GSVector.h"
|
|
|
|
|
|
|
|
union GSScanlineSelector
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 fpsm:2; // 0
|
|
|
|
uint32 zpsm:2; // 2
|
|
|
|
uint32 ztst:2; // 4 (0: off, 1: write, 2: test (ge), 3: test (g))
|
|
|
|
uint32 atst:3; // 6
|
|
|
|
uint32 afail:2; // 9
|
|
|
|
uint32 iip:1; // 11
|
|
|
|
uint32 tfx:3; // 12
|
|
|
|
uint32 tcc:1; // 15
|
|
|
|
uint32 fst:1; // 16
|
|
|
|
uint32 ltf:1; // 17
|
|
|
|
uint32 tlu:1; // 18
|
|
|
|
uint32 fge:1; // 19
|
|
|
|
uint32 date:1; // 20
|
|
|
|
uint32 abe:1; // 21
|
|
|
|
uint32 aba:2; // 22
|
|
|
|
uint32 abb:2; // 24
|
|
|
|
uint32 abc:2; // 26
|
|
|
|
uint32 abd:2; // 28
|
|
|
|
uint32 pabe:1; // 30
|
|
|
|
uint32 aa1:1; // 31
|
|
|
|
|
|
|
|
uint32 fwrite:1; // 32
|
|
|
|
uint32 ftest:1; // 33
|
|
|
|
uint32 rfb:1; // 34
|
|
|
|
uint32 zwrite:1; // 35
|
|
|
|
uint32 ztest:1; // 36
|
|
|
|
uint32 zoverflow:1; // 37 (z max >= 0x80000000)
|
|
|
|
uint32 wms:2; // 38
|
|
|
|
uint32 wmt:2; // 40
|
|
|
|
uint32 datm:1; // 42
|
|
|
|
uint32 colclamp:1; // 43
|
|
|
|
uint32 fba:1; // 44
|
|
|
|
uint32 dthe:1; // 45
|
2012-01-05 02:40:24 +00:00
|
|
|
uint32 prim:2; // 46
|
2011-02-12 21:45:16 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
uint32 edge:1; // 48
|
|
|
|
uint32 tw:3; // 49 (encodes values between 3 -> 10, texture cache makes sure it is at least 3)
|
2012-02-08 16:57:14 +00:00
|
|
|
uint32 lcm:1; // 52
|
|
|
|
uint32 mmin:2; // 53
|
|
|
|
uint32 notest:1; // 54 (no ztest, no atest, no date, no scissor test, and horizontally aligned to 4 pixels)
|
2012-02-12 17:56:06 +00:00
|
|
|
// TODO: 1D texture flag? could save 2 texture reads and 4 lerps with bilinear, and also the texture coordinate clamp/wrap code in one direction
|
2016-11-15 18:12:31 +00:00
|
|
|
|
|
|
|
uint32 breakpoint:1; // Insert a trap to stop the program, helpful to stop debugger on a program
|
2010-04-24 21:37:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 _pad1:22;
|
|
|
|
uint32 ababcd:8;
|
|
|
|
uint32 _pad2:2;
|
2016-11-15 18:12:31 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
uint32 fb:2;
|
|
|
|
uint32 _pad3:1;
|
|
|
|
uint32 zb:2;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32 lo;
|
|
|
|
uint32 hi;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint64 key;
|
|
|
|
|
2016-11-15 18:12:31 +00:00
|
|
|
GSScanlineSelector() = default;
|
|
|
|
GSScanlineSelector(uint64 k) : key(k) {}
|
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
operator uint32() const {return lo;}
|
|
|
|
operator uint64() const {return key;}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
bool IsSolidRect() const
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2012-01-05 02:40:24 +00:00
|
|
|
return prim == GS_SPRITE_CLASS
|
2010-04-24 21:37:39 +00:00
|
|
|
&& iip == 0
|
|
|
|
&& tfx == TFX_NONE
|
2010-04-25 00:31:27 +00:00
|
|
|
&& abe == 0
|
|
|
|
&& ztst <= 1
|
2010-04-24 21:37:39 +00:00
|
|
|
&& atst <= 1
|
|
|
|
&& date == 0
|
|
|
|
&& fge == 0;
|
|
|
|
}
|
2016-11-15 18:12:31 +00:00
|
|
|
|
|
|
|
void Print() const
|
|
|
|
{
|
|
|
|
fprintf(stderr, "fpsm:%d zpsm:%d ztst:%d ztest:%d atst:%d afail:%d iip:%d rfb:%d fb:%d zb:%d zw:%d "
|
|
|
|
"tfx:%d tcc:%d fst:%d ltf:%d tlu:%d wms:%d wmt:%d mmin:%d lcm:%d tw:%d "
|
|
|
|
"fba:%d cclamp:%d date:%d datm:%d "
|
|
|
|
"prim:%d abe:%d %d%d%d%d fge:%d dthe:%d notest:%d\n",
|
|
|
|
fpsm, zpsm, ztst, ztest, atst, afail, iip, rfb, fb, zb, zwrite,
|
|
|
|
tfx, tcc, fst, ltf, tlu, wms, wmt, mmin, lcm, tw,
|
|
|
|
fba, colclamp, date, datm,
|
|
|
|
prim, abe, aba, abb, abc, abd , fge, dthe, notest);
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 23:24:37 +00:00
|
|
|
struct alignas(32) GSScanlineGlobalData // per batch variables, this is like a pixel shader constant buffer
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
|
|
|
GSScanlineSelector sel;
|
|
|
|
|
2011-12-18 08:13:20 +00:00
|
|
|
// - the data of vm, tex may change, multi-threaded drawing must be finished before that happens, clut and dimx are copies
|
2011-02-17 03:24:37 +00:00
|
|
|
// - tex is a cached texture, it may be recycled to free up memory, its absolute address cannot be compiled into code
|
|
|
|
// - row and column pointers are allocated once and never change or freed, thier address can be used directly
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
void* vm;
|
2011-03-17 02:55:20 +00:00
|
|
|
const void* tex[7];
|
2011-12-18 08:13:20 +00:00
|
|
|
uint32* clut;
|
2013-06-20 05:07:52 +00:00
|
|
|
GSVector4i* dimx;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
const int* fbr;
|
|
|
|
const int* zbr;
|
|
|
|
const int* fbc;
|
|
|
|
const int* zbc;
|
|
|
|
const GSVector2i* fzbr;
|
|
|
|
const GSVector2i* fzbc;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
GSVector4i aref;
|
|
|
|
GSVector4i afix;
|
2013-06-20 05:07:52 +00:00
|
|
|
struct {GSVector4i min, max, minmax, mask, invmask;} t; // [u] x 4 [v] x 4
|
|
|
|
|
|
|
|
#if _M_SSE >= 0x501
|
|
|
|
|
|
|
|
uint32 fm, zm;
|
|
|
|
uint32 frb, fga;
|
|
|
|
GSVector8 mxl;
|
|
|
|
GSVector8 k; // TEX1.K * 0x10000
|
|
|
|
GSVector8 l; // TEX1.L * -0x10000
|
|
|
|
struct {GSVector8i i, f;} lod; // lcm == 1
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
GSVector4i fm, zm;
|
2010-04-24 21:37:39 +00:00
|
|
|
GSVector4i frb, fga;
|
2011-03-17 02:55:20 +00:00
|
|
|
GSVector4 mxl;
|
2011-03-14 03:32:28 +00:00
|
|
|
GSVector4 k; // TEX1.K * 0x10000
|
|
|
|
GSVector4 l; // TEX1.L * -0x10000
|
2011-03-17 02:55:20 +00:00
|
|
|
struct {GSVector4i i, f;} lod; // lcm == 1
|
2013-06-20 05:07:52 +00:00
|
|
|
|
|
|
|
#endif
|
2011-02-17 03:24:37 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 23:24:37 +00:00
|
|
|
struct alignas(32) GSScanlineLocalData // per prim variables, each thread has its own
|
2011-02-17 03:24:37 +00:00
|
|
|
{
|
2013-06-20 05:07:52 +00:00
|
|
|
#if _M_SSE >= 0x501
|
|
|
|
|
|
|
|
struct skip {GSVector8 z, s, t, q; GSVector8i rb, ga, f, _pad;} d[8];
|
2013-06-24 01:11:00 +00:00
|
|
|
struct step {GSVector4 stq; struct {uint32 rb, ga;} c; struct {uint32 z, f;} p;} d8;
|
2013-06-20 05:07:52 +00:00
|
|
|
struct {GSVector8i rb, ga;} c;
|
|
|
|
struct {uint32 z, f;} p;
|
|
|
|
|
|
|
|
// these should be stored on stack as normal local variables (no free regs to use, esp cannot be saved to anywhere, and we need an aligned stack)
|
|
|
|
|
2016-11-20 13:07:58 +00:00
|
|
|
struct
|
2013-06-20 05:07:52 +00:00
|
|
|
{
|
|
|
|
GSVector8 z, zo;
|
|
|
|
GSVector8i f;
|
|
|
|
GSVector8 s, t, q;
|
|
|
|
GSVector8i rb, ga;
|
|
|
|
GSVector8i zs, zd;
|
|
|
|
GSVector8i uf, vf;
|
|
|
|
GSVector8i cov;
|
|
|
|
|
|
|
|
// mipmapping
|
|
|
|
|
|
|
|
struct {GSVector8i i, f;} lod;
|
|
|
|
GSVector8i uv[2];
|
|
|
|
GSVector8i uv_minmax[2];
|
|
|
|
GSVector8i trb, tga;
|
|
|
|
GSVector8i test;
|
2016-11-20 13:07:58 +00:00
|
|
|
} temp;
|
2013-06-20 05:07:52 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2011-03-14 03:32:28 +00:00
|
|
|
struct skip {GSVector4 z, s, t, q; GSVector4i rb, ga, f, _pad;} d[4];
|
|
|
|
struct step {GSVector4 z, stq; GSVector4i c, f;} d4;
|
2010-04-24 21:37:39 +00:00
|
|
|
struct {GSVector4i rb, ga;} c;
|
|
|
|
struct {GSVector4i z, f;} p;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
|
|
|
// these should be stored on stack as normal local variables (no free regs to use, esp cannot be saved to anywhere, and we need an aligned stack)
|
|
|
|
|
2016-11-20 13:07:58 +00:00
|
|
|
struct
|
2011-03-17 02:55:20 +00:00
|
|
|
{
|
2011-12-04 09:49:55 +00:00
|
|
|
GSVector4 z, zo;
|
2011-11-25 23:48:59 +00:00
|
|
|
GSVector4i f;
|
|
|
|
GSVector4 s, t, q;
|
2011-03-17 02:55:20 +00:00
|
|
|
GSVector4i rb, ga;
|
|
|
|
GSVector4i zs, zd;
|
|
|
|
GSVector4i uf, vf;
|
|
|
|
GSVector4i cov;
|
|
|
|
|
|
|
|
// mipmapping
|
2011-04-01 12:36:21 +00:00
|
|
|
|
2011-03-17 02:55:20 +00:00
|
|
|
struct {GSVector4i i, f;} lod;
|
|
|
|
GSVector4i uv[2];
|
|
|
|
GSVector4i uv_minmax[2];
|
|
|
|
GSVector4i trb, tga;
|
|
|
|
GSVector4i test;
|
2016-11-20 13:07:58 +00:00
|
|
|
} temp;
|
2011-04-01 12:36:21 +00:00
|
|
|
|
2013-06-20 05:07:52 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-01 12:36:21 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
const GSScanlineGlobalData* gd;
|
2010-04-24 21:37:39 +00:00
|
|
|
};
|
2016-11-24 09:11:16 +00:00
|
|
|
|
|
|
|
// Constant shared by all threads (to reduce cache miss)
|
|
|
|
//
|
|
|
|
// Note: Avoid GSVector* to support all ISA at once
|
|
|
|
//
|
|
|
|
// WARNING: Don't use static storage. Static variables are relocated to random
|
|
|
|
// location (above 2GB). Small allocation on the heap could be below 2GB, this way we can use
|
|
|
|
// absolute addressing. Otherwise we need to store a base address in a register.
|
|
|
|
struct GSScanlineConstantData : public GSAlignedClass<32>
|
|
|
|
{
|
|
|
|
alignas(32) uint8 m_test_256b[16][8];
|
|
|
|
alignas(32) float m_shift_256b[9][8];
|
|
|
|
alignas(32) float m_log2_coef_256b[4][8];
|
|
|
|
|
|
|
|
alignas(16) uint32 m_test_128b[8][4];
|
|
|
|
alignas(16) float m_shift_128b[5][4];
|
|
|
|
alignas(16) float m_log2_coef_128b[4][4];
|
|
|
|
|
2016-11-28 18:40:25 +00:00
|
|
|
GSScanlineConstantData() {}
|
|
|
|
|
|
|
|
// GCC will be clever enough to stick some AVX instruction here
|
|
|
|
// So it must be defered to post global constructor
|
|
|
|
void Init()
|
2016-11-24 09:11:16 +00:00
|
|
|
{
|
|
|
|
uint8 I_hate_vs2013_m_test_256b[16][8] = {
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00},
|
|
|
|
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00},
|
|
|
|
{0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
|
|
|
{0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
|
|
|
{0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff},
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32 I_hate_vs2013_m_test_128b[8][4] = {
|
|
|
|
{ 0x00000000, 0x00000000, 0x00000000, 0x00000000},
|
|
|
|
{ 0xffffffff, 0x00000000, 0x00000000, 0x00000000},
|
|
|
|
{ 0xffffffff, 0xffffffff, 0x00000000, 0x00000000},
|
|
|
|
{ 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000},
|
|
|
|
{ 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
|
|
|
|
{ 0x00000000, 0x00000000, 0xffffffff, 0xffffffff},
|
|
|
|
{ 0x00000000, 0x00000000, 0x00000000, 0xffffffff},
|
|
|
|
{ 0x00000000, 0x00000000, 0x00000000, 0x00000000}
|
|
|
|
};
|
|
|
|
|
|
|
|
float I_hate_vs2013_m_shift_256b[9][8] = {
|
|
|
|
{ 8.0f , 8.0f , 8.0f , 8.0f , 8.0f , 8.0f , 8.0f , 8.0f},
|
|
|
|
{ 0.0f , 1.0f , 2.0f , 3.0f , 4.0f , 5.0f , 6.0f , 7.0f},
|
|
|
|
{ -1.0f , 0.0f , 1.0f , 2.0f , 3.0f , 4.0f , 5.0f , 6.0f},
|
|
|
|
{ -2.0f , -1.0f , 0.0f , 1.0f , 2.0f , 3.0f , 4.0f , 5.0f},
|
|
|
|
{ -3.0f , -2.0f , -1.0f , 0.0f , 1.0f , 2.0f , 3.0f , 4.0f},
|
|
|
|
{ -4.0f , -3.0f , -2.0f , -1.0f , 0.0f , 1.0f , 2.0f , 3.0f},
|
|
|
|
{ -5.0f , -4.0f , -3.0f , -2.0f , -1.0f , 0.0f , 1.0f , 2.0f},
|
|
|
|
{ -6.0f , -5.0f , -4.0f , -3.0f , -2.0f , -1.0f , 0.0f , 1.0f},
|
|
|
|
{ -7.0f , -6.0f , -5.0f , -4.0f , -3.0f , -2.0f , -1.0f , 0.0f}
|
|
|
|
};
|
|
|
|
|
|
|
|
float I_hate_vs2013_m_shift_128b[5][4] = {
|
|
|
|
{ 4.0f , 4.0f , 4.0f , 4.0f},
|
|
|
|
{ 0.0f , 1.0f , 2.0f , 3.0f},
|
|
|
|
{ -1.0f , 0.0f , 1.0f , 2.0f},
|
|
|
|
{ -2.0f , -1.0f , 0.0f , 1.0f},
|
|
|
|
{ -3.0f , -2.0f , -1.0f , 0.0f}
|
|
|
|
};
|
|
|
|
|
|
|
|
memcpy(m_test_256b, I_hate_vs2013_m_test_256b, sizeof(I_hate_vs2013_m_test_256b));
|
|
|
|
memcpy(m_test_128b, I_hate_vs2013_m_test_128b, sizeof(I_hate_vs2013_m_test_128b));
|
|
|
|
memcpy(m_shift_256b, I_hate_vs2013_m_shift_256b, sizeof(I_hate_vs2013_m_shift_256b));
|
|
|
|
memcpy(m_shift_128b, I_hate_vs2013_m_shift_128b, sizeof(I_hate_vs2013_m_shift_128b));
|
|
|
|
|
|
|
|
float log2_coef[] = {
|
|
|
|
0.204446009836232697516f,
|
|
|
|
-1.04913055217340124191f,
|
|
|
|
2.28330284476918490682f,
|
|
|
|
1.0f
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t n = 0; n < countof(log2_coef); ++n) {
|
|
|
|
for (size_t i = 0; i < 4; ++i) {
|
|
|
|
m_log2_coef_128b[n][i] = log2_coef[n];
|
|
|
|
m_log2_coef_256b[n][i] = log2_coef[n];
|
|
|
|
m_log2_coef_256b[n][i+4] = log2_coef[n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern std::unique_ptr<GSScanlineConstantData> g_const;
|