Set some svn:eol-style properties.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5173 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
sudonim1@gmail.com 2012-04-23 18:56:22 +00:00
parent 3d700b9264
commit a27142f1a6
6 changed files with 3508 additions and 3508 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,145 +1,145 @@
/*
* 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.
*
* 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 "GSRenderer.h"
#include "GSDevice11.h"
class GSRendererCS : public GSRenderer
{
struct VSSelector
{
union
{
struct
{
uint32 tme:1;
uint32 fst:1;
};
uint32 key;
};
operator uint32() {return key & 0x3;}
VSSelector() : key(0) {}
};
__aligned(struct, 32) VSConstantBuffer
{
GSVector4 VertexScale;
GSVector4 VertexOffset;
};
struct GSSelector
{
union
{
struct
{
uint32 iip:1;
uint32 prim:2;
};
uint32 key;
};
operator uint32() {return key & 0x7;}
GSSelector() : key(0) {}
};
struct PSSelector
{
union
{
struct
{
uint32 fpsm:6;
uint32 zpsm:6;
};
uint32 key;
};
operator uint32() {return key & 0x3ff;}
PSSelector() : key(0) {}
};
__aligned(struct, 32) PSConstantBuffer
{
uint32 fm;
uint32 zm;
};
CComPtr<ID3D11DepthStencilState> m_dss;
CComPtr<ID3D11BlendState> m_bs;
CComPtr<ID3D11SamplerState> m_ss;
CComPtr<ID3D11Buffer> m_lb;
CComPtr<ID3D11UnorderedAccessView> m_lb_uav;
CComPtr<ID3D11ShaderResourceView> m_lb_srv;
CComPtr<ID3D11Buffer> m_sob;
CComPtr<ID3D11UnorderedAccessView> m_sob_uav;
CComPtr<ID3D11ShaderResourceView> m_sob_srv;
CComPtr<ID3D11Buffer> m_vm;
//CComPtr<ID3D11Texture2D> m_vm;
CComPtr<ID3D11UnorderedAccessView> m_vm_uav;
uint32 m_vm_valid[16];
CComPtr<ID3D11Buffer> m_pb;
//CComPtr<ID3D11Texture2D> m_pb;
hash_map<uint32, GSVertexShader11 > m_vs;
CComPtr<ID3D11Buffer> m_vs_cb;
hash_map<uint32, CComPtr<ID3D11GeometryShader> > m_gs;
CComPtr<ID3D11PixelShader> m_ps0;
hash_map<uint32, CComPtr<ID3D11PixelShader> > m_ps1;
CComPtr<ID3D11Buffer> m_ps_cb;
void Write(GSOffset* o, const GSVector4i& r);
void Read(GSOffset* o, const GSVector4i& r, bool invalidate);
struct OffsetBuffer
{
CComPtr<ID3D11Buffer> row, col;
CComPtr<ID3D11ShaderResourceView> row_srv, col_srv;
};
hash_map<uint32, OffsetBuffer> m_offset;
bool GetOffsetBuffer(OffsetBuffer** fzbo);
protected:
GSTexture* m_texture[2];
uint8* m_output;
bool CreateDevice(GSDevice* dev);
void ResetDevice();
void VSync(int field);
GSTexture* GetOutput(int i);
void Draw();
void InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r);
void InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r, bool clut);
public:
GSRendererCS();
virtual ~GSRendererCS();
};
/*
* 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.
*
* 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 "GSRenderer.h"
#include "GSDevice11.h"
class GSRendererCS : public GSRenderer
{
struct VSSelector
{
union
{
struct
{
uint32 tme:1;
uint32 fst:1;
};
uint32 key;
};
operator uint32() {return key & 0x3;}
VSSelector() : key(0) {}
};
__aligned(struct, 32) VSConstantBuffer
{
GSVector4 VertexScale;
GSVector4 VertexOffset;
};
struct GSSelector
{
union
{
struct
{
uint32 iip:1;
uint32 prim:2;
};
uint32 key;
};
operator uint32() {return key & 0x7;}
GSSelector() : key(0) {}
};
struct PSSelector
{
union
{
struct
{
uint32 fpsm:6;
uint32 zpsm:6;
};
uint32 key;
};
operator uint32() {return key & 0x3ff;}
PSSelector() : key(0) {}
};
__aligned(struct, 32) PSConstantBuffer
{
uint32 fm;
uint32 zm;
};
CComPtr<ID3D11DepthStencilState> m_dss;
CComPtr<ID3D11BlendState> m_bs;
CComPtr<ID3D11SamplerState> m_ss;
CComPtr<ID3D11Buffer> m_lb;
CComPtr<ID3D11UnorderedAccessView> m_lb_uav;
CComPtr<ID3D11ShaderResourceView> m_lb_srv;
CComPtr<ID3D11Buffer> m_sob;
CComPtr<ID3D11UnorderedAccessView> m_sob_uav;
CComPtr<ID3D11ShaderResourceView> m_sob_srv;
CComPtr<ID3D11Buffer> m_vm;
//CComPtr<ID3D11Texture2D> m_vm;
CComPtr<ID3D11UnorderedAccessView> m_vm_uav;
uint32 m_vm_valid[16];
CComPtr<ID3D11Buffer> m_pb;
//CComPtr<ID3D11Texture2D> m_pb;
hash_map<uint32, GSVertexShader11 > m_vs;
CComPtr<ID3D11Buffer> m_vs_cb;
hash_map<uint32, CComPtr<ID3D11GeometryShader> > m_gs;
CComPtr<ID3D11PixelShader> m_ps0;
hash_map<uint32, CComPtr<ID3D11PixelShader> > m_ps1;
CComPtr<ID3D11Buffer> m_ps_cb;
void Write(GSOffset* o, const GSVector4i& r);
void Read(GSOffset* o, const GSVector4i& r, bool invalidate);
struct OffsetBuffer
{
CComPtr<ID3D11Buffer> row, col;
CComPtr<ID3D11ShaderResourceView> row_srv, col_srv;
};
hash_map<uint32, OffsetBuffer> m_offset;
bool GetOffsetBuffer(OffsetBuffer** fzbo);
protected:
GSTexture* m_texture[2];
uint8* m_output;
bool CreateDevice(GSDevice* dev);
void ResetDevice();
void VSync(int field);
GSTexture* GetOutput(int i);
void Draw();
void InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r);
void InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r, bool clut);
public:
GSRendererCS();
virtual ~GSRendererCS();
};

View File

@ -1,44 +1,44 @@
/*
* 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.
*
* 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
//#define ENABLE_VTUNE
#define ENABLE_JIT_RASTERIZER
//#define ENABLE_DYNAMIC_CRC_HACK
#define ENABLE_UPSCALE_HACKS // Hacks intended to fix upscaling / rendering glitches in HW renderers
//#define DISABLE_HW_TEXTURE_CACHE // Slow but fixes a lot of bugs
//#define DISABLE_CRC_HACKS // Disable all game specific hacks
#if defined(DISABLE_HW_TEXTURE_CACHE) && !defined(DISABLE_CRC_HACKS)
#define DISABLE_CRC_HACKS
#endif
//#define DISABLE_BITMASKING
//#define DISABLE_COLCLAMP
//#define DISABLE_DATE
/*
* 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.
*
* 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
//#define ENABLE_VTUNE
#define ENABLE_JIT_RASTERIZER
//#define ENABLE_DYNAMIC_CRC_HACK
#define ENABLE_UPSCALE_HACKS // Hacks intended to fix upscaling / rendering glitches in HW renderers
//#define DISABLE_HW_TEXTURE_CACHE // Slow but fixes a lot of bugs
//#define DISABLE_CRC_HACKS // Disable all game specific hacks
#if defined(DISABLE_HW_TEXTURE_CACHE) && !defined(DISABLE_CRC_HACKS)
#define DISABLE_CRC_HACKS
#endif
//#define DISABLE_BITMASKING
//#define DISABLE_COLCLAMP
//#define DISABLE_DATE

View File

@ -1,383 +1,383 @@
#ifndef VS_TME
#define VS_TME 1
#define VS_FST 1
#endif
#ifndef GS_IIP
#define GS_IIP 0
#define GS_PRIM 2
#endif
#ifndef PS_BATCH_SIZE
#define PS_BATCH_SIZE 2048
#define PS_FPSM PSM_PSMCT32
#define PS_ZPSM PSM_PSMZ16
#endif
#define PSM_PSMCT32 0
#define PSM_PSMCT24 1
#define PSM_PSMCT16 2
#define PSM_PSMCT16S 10
#define PSM_PSMT8 19
#define PSM_PSMT4 20
#define PSM_PSMT8H 27
#define PSM_PSMT4HL 36
#define PSM_PSMT4HH 44
#define PSM_PSMZ32 48
#define PSM_PSMZ24 49
#define PSM_PSMZ16 50
#define PSM_PSMZ16S 58
struct VS_INPUT
{
float2 st : TEXCOORD0;
float4 c : COLOR0;
float q : TEXCOORD1;
uint2 p : POSITION0;
uint z : POSITION1;
uint2 uv : TEXCOORD2;
float4 f : COLOR1;
};
struct VS_OUTPUT
{
float4 p : SV_Position;
float2 z : TEXCOORD0;
float4 t : TEXCOORD1;
float4 c : COLOR0;
};
struct GS_OUTPUT
{
float4 p : SV_Position;
float2 z : TEXCOORD0;
float4 t : TEXCOORD1;
float4 c : COLOR0;
uint id : SV_PrimitiveID;
};
cbuffer VSConstantBuffer : register(c0)
{
float4 VertexScale;
float4 VertexOffset;
};
cbuffer PSConstantBuffer : register(c0)
{
uint2 WriteMask;
};
struct FragmentLinkItem
{
uint c, z, id, next;
};
RWByteAddressBuffer VideoMemory : register(u0);
RWStructuredBuffer<FragmentLinkItem> FragmentLinkBuffer : register(u1);
RWByteAddressBuffer StartOffsetBuffer : register(u2);
//RWTexture2D<uint> VideoMemory : register(u2); // 8192 * 512 R8_UINT
Buffer<int2> FZRowOffset : register(t0);
Buffer<int2> FZColOffset : register(t1);
Texture2D<float4> Palette : register(t2);
Texture2D<float4> Texture : register(t3);
VS_OUTPUT vs_main(VS_INPUT input)
{
VS_OUTPUT output;
output.p = float4(input.p, 0.0f, 0.0f) * VertexScale - VertexOffset;
output.z = float2(input.z & 0xffff, input.z >> 16); // TODO: min(input.z, 0xffffff00) ?
if(VS_TME)
{
if(VS_FST)
{
output.t.xy = input.uv;
output.t.w = 1.0f;
}
else
{
output.t.xy = input.st;
output.t.w = input.q;
}
}
else
{
output.t.xy = 0;
output.t.w = 1.0f;
}
output.c = input.c;
output.t.z = input.f.r;
return output;
}
#if GS_PRIM == 0
[maxvertexcount(1)]
void gs_main(point VS_OUTPUT input[1], inout PointStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
GS_OUTPUT output;
output.p = input[0].p;
output.z = input[0].z;
output.t = input[0].t;
output.c = input[0].c;
output.id = id;
stream.Append(output);
}
#elif GS_PRIM == 1
[maxvertexcount(2)]
void gs_main(line VS_OUTPUT input[2], inout LineStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
[unroll]
for(int i = 0; i < 2; i++)
{
GS_OUTPUT output;
output.p = input[i].p;
output.z = input[i].z;
output.t = input[i].t;
output.c = input[i].c;
output.id = id;
#if GS_IIP == 0
if(i != 1) output.c = input[1].c;
#endif
stream.Append(output);
}
}
#elif GS_PRIM == 2
[maxvertexcount(3)]
void gs_main(triangle VS_OUTPUT input[3], inout TriangleStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
[unroll]
for(int i = 0; i < 3; i++)
{
GS_OUTPUT output;
output.p = input[i].p;
output.z = input[i].z;
output.t = input[i].t;
output.c = input[i].c;
output.id = id;
#if GS_IIP == 0
if(i != 2) output.c = input[2].c;
#endif
stream.Append(output);
}
}
#elif GS_PRIM == 3
[maxvertexcount(4)]
void gs_main(line VS_OUTPUT input[2], inout TriangleStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
GS_OUTPUT lt, rb, lb, rt;
lt.p = input[0].p;
lt.z = input[1].z;
lt.t.xy = input[0].t.xy;
lt.t.zw = input[1].t.zw;
lt.c = input[0].c;
lt.id = id;
#if GS_IIP == 0
lt.c = input[1].c;
#endif
rb.p = input[1].p;
rb.z = input[1].z;
rb.t = input[1].t;
rb.c = input[1].c;
rb.id = id;
lb = lt;
lb.p.y = rb.p.y;
lb.t.y = rb.t.y;
rt = rb;
rt.p.y = lt.p.y;
rt.t.y = lt.t.y;
stream.Append(lt);
stream.Append(lb);
stream.Append(rt);
stream.Append(rb);
}
#endif
uint CompressColor32(float4 f)
{
uint4 c = (uint4)(f * 0xff) << uint4(0, 8, 16, 24);
return c.r | c.g | c.b | c.a;
}
uint DecompressColor16(uint c)
{
uint r = (c & 0x001f) << 3;
uint g = (c & 0x03e0) << 6;
uint b = (c & 0x7c00) << 9;
uint a = (c & 0x8000) << 15;
return r | g | b | a;
}
uint ReadPixel(uint addr)
{
return VideoMemory.Load(addr) >> ((addr & 2) << 3);
}
void WritePixel(uint addr, uint value, uint psm)
{
uint tmp;
switch(psm)
{
case PSM_PSMCT32:
case PSM_PSMZ32:
case PSM_PSMCT24:
case PSM_PSMZ24:
VideoMemory.Store(addr, value);
break;
case PSM_PSMCT16:
case PSM_PSMCT16S:
case PSM_PSMZ16:
case PSM_PSMZ16S:
tmp = (addr & 2) << 3;
value = ((value << tmp) ^ VideoMemory.Load(addr)) & (0x0000ffff << tmp);
VideoMemory.InterlockedXor(addr, value, tmp);
break;
}
}
void ps_main0(GS_OUTPUT input)
{
uint x = (uint)input.p.x;
uint y = (uint)input.p.y;
uint tail = FragmentLinkBuffer.IncrementCounter();
uint index = (y << 11) + x;
uint next = 0;
StartOffsetBuffer.InterlockedExchange(index * 4, tail, next);
FragmentLinkItem item;
// TODO: preprocess color (tfx, alpha test), z-test
item.c = CompressColor32(input.c);
item.z = (uint)(input.z.y * 0x10000 + input.z.x);
item.id = input.id;
item.next = next;
FragmentLinkBuffer[tail] = item;
}
void ps_main1(GS_OUTPUT input)
{
uint2 pos = (uint2)input.p.xy;
// sort fragments
uint StartOffsetIndex = (pos.y << 11) + pos.x;
int index[PS_BATCH_SIZE];
int count = 0;
uint next = StartOffsetBuffer.Load(StartOffsetIndex * 4);
StartOffsetBuffer.Store(StartOffsetIndex * 4, 0);
[allow_uav_condition]
while(next != 0)
{
index[count++] = next;
next = FragmentLinkBuffer[next].next;
}
int N2 = 1 << (int)(ceil(log2(count)));
[allow_uav_condition]
for(int i = count; i < N2; i++)
{
index[i] = 0;
}
[allow_uav_condition]
for(int k = 2; k <= N2; k = 2 * k)
{
[allow_uav_condition]
for(int j = k >> 1; j > 0 ; j = j >> 1)
{
[allow_uav_condition]
for(int i = 0; i < N2; i++)
{
uint i_id = FragmentLinkBuffer[index[i]].id;
int ixj = i ^ j;
if(ixj > i)
{
uint ixj_id = FragmentLinkBuffer[index[ixj]].id;
if((i & k) == 0 && i_id > ixj_id)
{
int temp = index[i];
index[i] = index[ixj];
index[ixj] = temp;
}
if((i & k) != 0 && i_id < ixj_id)
{
int temp = index[i];
index[i] = index[ixj];
index[ixj] = temp;
}
}
}
}
}
uint2 addr = (uint2)(FZRowOffset[pos.y] + FZColOffset[pos.x]) << 1;
uint dc = ReadPixel(addr.x);
uint dz = ReadPixel(addr.y);
uint sc = dc;
uint sz = dz;
[allow_uav_condition]
while(--count >= 0)
{
FragmentLinkItem f = FragmentLinkBuffer[index[count]];
// TODO
if(sz < f.z)
{
sc = f.c;
sz = f.z;
}
}
uint c = sc; // (dc & ~WriteMask.x) | (sc & WriteMask.x);
uint z = 0;//sz; //(dz & ~WriteMask.y) | (sz & WriteMask.y);
WritePixel(addr.x, c, PS_FPSM);
WritePixel(addr.y, z, PS_ZPSM);
}
#ifndef VS_TME
#define VS_TME 1
#define VS_FST 1
#endif
#ifndef GS_IIP
#define GS_IIP 0
#define GS_PRIM 2
#endif
#ifndef PS_BATCH_SIZE
#define PS_BATCH_SIZE 2048
#define PS_FPSM PSM_PSMCT32
#define PS_ZPSM PSM_PSMZ16
#endif
#define PSM_PSMCT32 0
#define PSM_PSMCT24 1
#define PSM_PSMCT16 2
#define PSM_PSMCT16S 10
#define PSM_PSMT8 19
#define PSM_PSMT4 20
#define PSM_PSMT8H 27
#define PSM_PSMT4HL 36
#define PSM_PSMT4HH 44
#define PSM_PSMZ32 48
#define PSM_PSMZ24 49
#define PSM_PSMZ16 50
#define PSM_PSMZ16S 58
struct VS_INPUT
{
float2 st : TEXCOORD0;
float4 c : COLOR0;
float q : TEXCOORD1;
uint2 p : POSITION0;
uint z : POSITION1;
uint2 uv : TEXCOORD2;
float4 f : COLOR1;
};
struct VS_OUTPUT
{
float4 p : SV_Position;
float2 z : TEXCOORD0;
float4 t : TEXCOORD1;
float4 c : COLOR0;
};
struct GS_OUTPUT
{
float4 p : SV_Position;
float2 z : TEXCOORD0;
float4 t : TEXCOORD1;
float4 c : COLOR0;
uint id : SV_PrimitiveID;
};
cbuffer VSConstantBuffer : register(c0)
{
float4 VertexScale;
float4 VertexOffset;
};
cbuffer PSConstantBuffer : register(c0)
{
uint2 WriteMask;
};
struct FragmentLinkItem
{
uint c, z, id, next;
};
RWByteAddressBuffer VideoMemory : register(u0);
RWStructuredBuffer<FragmentLinkItem> FragmentLinkBuffer : register(u1);
RWByteAddressBuffer StartOffsetBuffer : register(u2);
//RWTexture2D<uint> VideoMemory : register(u2); // 8192 * 512 R8_UINT
Buffer<int2> FZRowOffset : register(t0);
Buffer<int2> FZColOffset : register(t1);
Texture2D<float4> Palette : register(t2);
Texture2D<float4> Texture : register(t3);
VS_OUTPUT vs_main(VS_INPUT input)
{
VS_OUTPUT output;
output.p = float4(input.p, 0.0f, 0.0f) * VertexScale - VertexOffset;
output.z = float2(input.z & 0xffff, input.z >> 16); // TODO: min(input.z, 0xffffff00) ?
if(VS_TME)
{
if(VS_FST)
{
output.t.xy = input.uv;
output.t.w = 1.0f;
}
else
{
output.t.xy = input.st;
output.t.w = input.q;
}
}
else
{
output.t.xy = 0;
output.t.w = 1.0f;
}
output.c = input.c;
output.t.z = input.f.r;
return output;
}
#if GS_PRIM == 0
[maxvertexcount(1)]
void gs_main(point VS_OUTPUT input[1], inout PointStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
GS_OUTPUT output;
output.p = input[0].p;
output.z = input[0].z;
output.t = input[0].t;
output.c = input[0].c;
output.id = id;
stream.Append(output);
}
#elif GS_PRIM == 1
[maxvertexcount(2)]
void gs_main(line VS_OUTPUT input[2], inout LineStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
[unroll]
for(int i = 0; i < 2; i++)
{
GS_OUTPUT output;
output.p = input[i].p;
output.z = input[i].z;
output.t = input[i].t;
output.c = input[i].c;
output.id = id;
#if GS_IIP == 0
if(i != 1) output.c = input[1].c;
#endif
stream.Append(output);
}
}
#elif GS_PRIM == 2
[maxvertexcount(3)]
void gs_main(triangle VS_OUTPUT input[3], inout TriangleStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
[unroll]
for(int i = 0; i < 3; i++)
{
GS_OUTPUT output;
output.p = input[i].p;
output.z = input[i].z;
output.t = input[i].t;
output.c = input[i].c;
output.id = id;
#if GS_IIP == 0
if(i != 2) output.c = input[2].c;
#endif
stream.Append(output);
}
}
#elif GS_PRIM == 3
[maxvertexcount(4)]
void gs_main(line VS_OUTPUT input[2], inout TriangleStream<GS_OUTPUT> stream, uint id : SV_PrimitiveID)
{
GS_OUTPUT lt, rb, lb, rt;
lt.p = input[0].p;
lt.z = input[1].z;
lt.t.xy = input[0].t.xy;
lt.t.zw = input[1].t.zw;
lt.c = input[0].c;
lt.id = id;
#if GS_IIP == 0
lt.c = input[1].c;
#endif
rb.p = input[1].p;
rb.z = input[1].z;
rb.t = input[1].t;
rb.c = input[1].c;
rb.id = id;
lb = lt;
lb.p.y = rb.p.y;
lb.t.y = rb.t.y;
rt = rb;
rt.p.y = lt.p.y;
rt.t.y = lt.t.y;
stream.Append(lt);
stream.Append(lb);
stream.Append(rt);
stream.Append(rb);
}
#endif
uint CompressColor32(float4 f)
{
uint4 c = (uint4)(f * 0xff) << uint4(0, 8, 16, 24);
return c.r | c.g | c.b | c.a;
}
uint DecompressColor16(uint c)
{
uint r = (c & 0x001f) << 3;
uint g = (c & 0x03e0) << 6;
uint b = (c & 0x7c00) << 9;
uint a = (c & 0x8000) << 15;
return r | g | b | a;
}
uint ReadPixel(uint addr)
{
return VideoMemory.Load(addr) >> ((addr & 2) << 3);
}
void WritePixel(uint addr, uint value, uint psm)
{
uint tmp;
switch(psm)
{
case PSM_PSMCT32:
case PSM_PSMZ32:
case PSM_PSMCT24:
case PSM_PSMZ24:
VideoMemory.Store(addr, value);
break;
case PSM_PSMCT16:
case PSM_PSMCT16S:
case PSM_PSMZ16:
case PSM_PSMZ16S:
tmp = (addr & 2) << 3;
value = ((value << tmp) ^ VideoMemory.Load(addr)) & (0x0000ffff << tmp);
VideoMemory.InterlockedXor(addr, value, tmp);
break;
}
}
void ps_main0(GS_OUTPUT input)
{
uint x = (uint)input.p.x;
uint y = (uint)input.p.y;
uint tail = FragmentLinkBuffer.IncrementCounter();
uint index = (y << 11) + x;
uint next = 0;
StartOffsetBuffer.InterlockedExchange(index * 4, tail, next);
FragmentLinkItem item;
// TODO: preprocess color (tfx, alpha test), z-test
item.c = CompressColor32(input.c);
item.z = (uint)(input.z.y * 0x10000 + input.z.x);
item.id = input.id;
item.next = next;
FragmentLinkBuffer[tail] = item;
}
void ps_main1(GS_OUTPUT input)
{
uint2 pos = (uint2)input.p.xy;
// sort fragments
uint StartOffsetIndex = (pos.y << 11) + pos.x;
int index[PS_BATCH_SIZE];
int count = 0;
uint next = StartOffsetBuffer.Load(StartOffsetIndex * 4);
StartOffsetBuffer.Store(StartOffsetIndex * 4, 0);
[allow_uav_condition]
while(next != 0)
{
index[count++] = next;
next = FragmentLinkBuffer[next].next;
}
int N2 = 1 << (int)(ceil(log2(count)));
[allow_uav_condition]
for(int i = count; i < N2; i++)
{
index[i] = 0;
}
[allow_uav_condition]
for(int k = 2; k <= N2; k = 2 * k)
{
[allow_uav_condition]
for(int j = k >> 1; j > 0 ; j = j >> 1)
{
[allow_uav_condition]
for(int i = 0; i < N2; i++)
{
uint i_id = FragmentLinkBuffer[index[i]].id;
int ixj = i ^ j;
if(ixj > i)
{
uint ixj_id = FragmentLinkBuffer[index[ixj]].id;
if((i & k) == 0 && i_id > ixj_id)
{
int temp = index[i];
index[i] = index[ixj];
index[ixj] = temp;
}
if((i & k) != 0 && i_id < ixj_id)
{
int temp = index[i];
index[i] = index[ixj];
index[ixj] = temp;
}
}
}
}
}
uint2 addr = (uint2)(FZRowOffset[pos.y] + FZColOffset[pos.x]) << 1;
uint dc = ReadPixel(addr.x);
uint dz = ReadPixel(addr.y);
uint sc = dc;
uint sz = dz;
[allow_uav_condition]
while(--count >= 0)
{
FragmentLinkItem f = FragmentLinkBuffer[index[count]];
// TODO
if(sz < f.z)
{
sc = f.c;
sz = f.z;
}
}
uint c = sc; // (dc & ~WriteMask.x) | (sc & WriteMask.x);
uint z = 0;//sz; //(dz & ~WriteMask.y) | (sz & WriteMask.y);
WritePixel(addr.x, c, PS_FPSM);
WritePixel(addr.y, z, PS_ZPSM);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,76 +1,76 @@
#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
/*
** Contrast, saturation, brightness
** Code of this function is from TGM's shader pack
** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057
*/
// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%
float4 ContrastSaturationBrightness(float4 color) // Ported to HLSL
{
const float sat = SB_SATURATION / 50.0;
const float brt = SB_BRIGHTNESS / 50.0;
const float con = SB_CONTRAST / 50.0;
// Increase or decrease theese values to adjust r, g and b color channels seperately
const float AvgLumR = 0.5;
const float AvgLumG = 0.5;
const float AvgLumB = 0.5;
const float3 LumCoeff = float3(0.2125, 0.7154, 0.0721);
float3 AvgLumin = float3(AvgLumR, AvgLumG, AvgLumB);
float3 brtColor = color.rgb * brt;
float3 intensity = dot(brtColor, LumCoeff);
float3 satColor = lerp(intensity, brtColor, sat);
float3 conColor = lerp(AvgLumin, satColor, con);
color.rgb = conColor;
return color;
}
#if SHADER_MODEL >= 0x400
Texture2D Texture;
SamplerState Sampler;
cbuffer cb0
{
float4 BGColor;
};
struct PS_INPUT
{
float4 p : SV_Position;
float2 t : TEXCOORD0;
};
float4 ps_main(PS_INPUT input) : SV_Target0
{
float4 c = Texture.Sample(Sampler, input.t);
return ContrastSaturationBrightness(c);
}
#elif SHADER_MODEL <= 0x300
sampler Texture : register(s0);
float4 g_params[1];
#define BGColor (g_params[0])
struct PS_INPUT
{
float2 t : TEXCOORD0;
};
float4 ps_main(PS_INPUT input) : COLOR
{
float4 c = tex2D(Texture, input.t);
return ContrastSaturationBrightness(c);
}
#endif
#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
/*
** Contrast, saturation, brightness
** Code of this function is from TGM's shader pack
** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057
*/
// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%
float4 ContrastSaturationBrightness(float4 color) // Ported to HLSL
{
const float sat = SB_SATURATION / 50.0;
const float brt = SB_BRIGHTNESS / 50.0;
const float con = SB_CONTRAST / 50.0;
// Increase or decrease theese values to adjust r, g and b color channels seperately
const float AvgLumR = 0.5;
const float AvgLumG = 0.5;
const float AvgLumB = 0.5;
const float3 LumCoeff = float3(0.2125, 0.7154, 0.0721);
float3 AvgLumin = float3(AvgLumR, AvgLumG, AvgLumB);
float3 brtColor = color.rgb * brt;
float3 intensity = dot(brtColor, LumCoeff);
float3 satColor = lerp(intensity, brtColor, sat);
float3 conColor = lerp(AvgLumin, satColor, con);
color.rgb = conColor;
return color;
}
#if SHADER_MODEL >= 0x400
Texture2D Texture;
SamplerState Sampler;
cbuffer cb0
{
float4 BGColor;
};
struct PS_INPUT
{
float4 p : SV_Position;
float2 t : TEXCOORD0;
};
float4 ps_main(PS_INPUT input) : SV_Target0
{
float4 c = Texture.Sample(Sampler, input.t);
return ContrastSaturationBrightness(c);
}
#elif SHADER_MODEL <= 0x300
sampler Texture : register(s0);
float4 g_params[1];
#define BGColor (g_params[0])
struct PS_INPUT
{
float2 t : TEXCOORD0;
};
float4 ps_main(PS_INPUT input) : COLOR
{
float4 c = tex2D(Texture, input.t);
return ContrastSaturationBrightness(c);
}
#endif
#endif