From 0a113459a567159f8c5be7868f2f3baee1af8a04 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 30 Nov 2011 01:43:25 +0000 Subject: [PATCH] ps3: start implementing the PS3 threading system, and port the new Mandelbrot shader code to Cg. --- src/Makefile.am | 1 + src/platform/ps3/threadbase.h | 107 ++++++++++++++++++++++++++++++++ test/math/remez-solver.h | 2 + test/tutorial/tut03.cpp | 112 +++++++++++++++++----------------- 4 files changed, 167 insertions(+), 55 deletions(-) create mode 100644 src/platform/ps3/threadbase.h diff --git a/src/Makefile.am b/src/Makefile.am index 8d91c922..38789e6b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -55,6 +55,7 @@ endif if HAVE_PS3 ps3_sources = \ + platform/ps3/threadbase.h \ platform/ps3/ps3app.cpp platform/ps3/ps3app.h \ platform/ps3/ps3input.cpp platform/ps3/ps3input.h endif diff --git a/src/platform/ps3/threadbase.h b/src/platform/ps3/threadbase.h new file mode 100644 index 00000000..673c9eac --- /dev/null +++ b/src/platform/ps3/threadbase.h @@ -0,0 +1,107 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The ThreadBase class +// -------------------- +// + +#if !defined __LOL_THREADBASE_H__ +#define __LOL_THREADBASE_H__ + +#include +#include + +namespace lol +{ + +class MutexBase +{ +public: + MutexBase() + { + sys_lwmutex_attribute_t attr; + sys_lwmutex_attribute_initialize(attr); + sys_lwmutex_create(&m_mutex, &attr); + } + + ~MutexBase() + { + while (sys_lwmutex_destroy(&m_mutex) == EBUSY) + ; + } + + void Lock() + { + sys_lwmutex_lock(&m_mutex, 0); + } + + void Unlock() + { + sys_lwmutex_unlock(&m_mutex); + } + +private: + sys_lwmutex_t m_mutex; +}; + +class ConditionBase +{ +public: + ConditionBase() + { + } + + ~ConditionBase() + { + } + + void Acquire() + { + } + + void Release() + { + } + + void Wait() + { + } + + void Notify() + { + } + +private: +}; + +class ThreadBase +{ +public: + ThreadBase(void *(*fn)(void *), void *data) + { + /* FIXME: choose priority more wisely */ + sys_ppu_thread_create(&m_thread, (void (*)(uint64_t))fn, + (uint64_t)data, 1000, 0, 0, "new thread"); + } + + virtual ~ThreadBase() + { + sys_ppu_thread_join(m_thread, NULL); + } + +private: + sys_ppu_thread_t m_thread; +}; + +} /* namespace lol */ + +#endif // __LOL_THREADBASE_H__ + diff --git a/test/math/remez-solver.h b/test/math/remez-solver.h index a7f7afb0..d3d7cc08 100644 --- a/test/math/remez-solver.h +++ b/test/math/remez-solver.h @@ -141,6 +141,8 @@ public: void FindExtrema() { + using std::printf; + /* Find ORDER + 2 extrema of the error function. We need to * compute the relative error, since its extrema are at slightly * different locations than the absolute error’s. */ diff --git a/test/tutorial/tut03.cpp b/test/tutorial/tut03.cpp index 6cbb546a..a1229c09 100644 --- a/test/tutorial/tut03.cpp +++ b/test/tutorial/tut03.cpp @@ -487,7 +487,7 @@ public: #endif "" "uniform vec4 u_TexelSize;" - "uniform sampler2D in_Texture;" + "uniform sampler2D u_Texture;" "" "varying vec4 v_CenterX, v_CenterY, v_IndexX, v_IndexY;" "" @@ -545,75 +545,77 @@ public: " ret.xy = ret.xz * t2.yy + ret.yw * t2.xx;" "\n#endif\n" /* Nearest neighbour */ - " gl_FragColor = texture2D(in_Texture, ret.xy);" + " gl_FragColor = texture2D(u_Texture, ret.xy);" #else /* Alternate version: some kind of linear interpolation */ - " vec4 p0 = texture2D(in_Texture, vec2(rx.x, ry.x));" - " vec4 p1 = texture2D(in_Texture, vec2(rx.y, ry.y));" - " vec4 p2 = texture2D(in_Texture, vec2(rx.z, ry.z));" - " vec4 p3 = texture2D(in_Texture, vec2(rx.w, ry.w));" + " vec4 p0 = texture2D(u_Texture, vec2(rx.x, ry.x));" + " vec4 p1 = texture2D(u_Texture, vec2(rx.y, ry.y));" + " vec4 p2 = texture2D(u_Texture, vec2(rx.z, ry.z));" + " vec4 p3 = texture2D(u_Texture, vec2(rx.w, ry.w));" " gl_FragColor = 1.0 / (dd.x + dd.y + dd.z + dd.w)" " * (dd.x * p0 + dd.y * p1 + dd.z * p2 + dd.w * p3);" #endif "}" #else - "void main(float4 in_Position : POSITION," + "void main(float4 a_Vertex : POSITION," " float2 a_TexCoord : TEXCOORD0," + " uniform float4x4 u_ZoomSettings," + " uniform float4 u_TexelSize," + " uniform float4 u_ScreenSize," " out float4 out_Position : POSITION," - " out float2 out_TexCoord : TEXCOORD0)" + " out float4 v_CenterX," + " out float4 v_CenterY," + " out float4 v_IndexX," + " out float4 v_IndexY)" "{" - " out_TexCoord = a_TexCoord;" - " out_Position = in_Position;" + " out_Position = a_Vertex;" + " float4 offsets = float4(0.5, -0.5, 0.015625, -0.015625);" + " float4 zoomscale = float4(u_ZoomSettings[2][0]," + " u_ZoomSettings[2][1]," + " u_ZoomSettings[2][2]," + " u_ZoomSettings[2][3]);" + " float4 zoomtx = float4(u_ZoomSettings[0][0]," + " u_ZoomSettings[0][1]," + " u_ZoomSettings[0][2]," + " u_ZoomSettings[0][3]);" + " float4 zoomty = float4(u_ZoomSettings[1][0]," + " u_ZoomSettings[1][1]," + " u_ZoomSettings[1][2]," + " u_ZoomSettings[1][3]);" + " v_CenterX = zoomscale * a_TexCoord.x + zoomtx" + " + offsets.xyxy * u_TexelSize.x;" + " v_CenterY = zoomscale * a_TexCoord.y - zoomty" + " + offsets.xyyx * u_TexelSize.y;" + " v_IndexX = v_CenterX * u_ScreenSize.z - (offsets.zwzw + float4(0.001, 0.002, 0.003, 0.004));" + " v_IndexY = v_CenterY * u_ScreenSize.w - (offsets.zwwz + float4(0.0015, 0.0025, 0.0035, 0.0045));" "}", - "float3 nearest0(float2 p, float4 u_TexelSize)" - "{" - " float2 q = p + 0.5 * u_TexelSize.xy;" - " q -= fmod(q, 2.0 * u_TexelSize.xy);" - " q += 0.5 * u_TexelSize.xy;" - " return float3(q * float2(1.0, 0.25)," - " length(q - p));" - "}" - "" - "float3 nearest1(float2 p, float4 u_TexelSize)" - "{" - " float2 q = p - 0.5 * u_TexelSize.xy;" - " q -= fmod(q, 2.0 * u_TexelSize.xy);" - " q += 1.5 * u_TexelSize.xy;" - " return float3(q * float2(1.0, 0.25) + float2(0.0, 0.25)," - " length(q - p));" - "}" - "" - "float3 nearest2(float2 p, float4 u_TexelSize)" - "{" - " float2 q = p + float2(0.5, -0.5) * u_TexelSize.xy;" - " q -= fmod(q, 2.0 * u_TexelSize.xy);" - " q += float2(0.5, 1.5) * u_TexelSize.xy;" - " return float3(q * float2(1.0, 0.25) + float2(0.0, 0.50)," - " length(q - p));" - "}" - "" - "float3 nearest3(float2 p, float4 u_TexelSize)" - "{" - " float2 q = p + float2(-0.5, 0.5) * u_TexelSize.xy;" - " q -= fmod(q, 2.0 * u_TexelSize.xy);" - " q += float2(1.5, 0.5) * u_TexelSize.xy;" - " return float3(q * float2(1.0, 0.25) + float2(0.0, 0.75)," - " length(q - p));" - "}" - "" - "void main(float2 a_TexCoord : TEXCOORD0," + "void main(in float4 v_CenterX," + " in float4 v_CenterY," + " in float4 v_IndexX," + " in float4 v_IndexY," " uniform float4 u_TexelSize," - " uniform sampler2D in_Texture," + " uniform sampler2D u_Texture," " out float4 out_FragColor : COLOR)" "{" - " float2 coord = a_TexCoord.xy;" - " coord -= 0.1 * u_TexelSize.xy;" - " float4 p0 = tex2D(in_Texture, nearest0(coord, u_TexelSize).xy);" - " float4 p1 = tex2D(in_Texture, nearest1(coord, u_TexelSize).xy);" - " float4 p2 = tex2D(in_Texture, nearest2(coord, u_TexelSize).xy);" - " float4 p3 = tex2D(in_Texture, nearest3(coord, u_TexelSize).xy);" - " out_FragColor = 0.25 * (p0 + p1 + p2 + p3);" + " float4 v05 = float4(0.5, 0.5, 0.5, 0.5);" + " float4 rx, ry, t0, dx, dy, dd;" + " rx = u_TexelSize.x + u_TexelSize.z * floor(v_IndexX);" + " ry = u_TexelSize.y + u_TexelSize.w * floor(v_IndexY);" + " t0 = step(abs(rx - v05), v05) * step(abs(ry - v05), v05);" + " dx = rx - v_CenterX;" + " dy = ry - v_CenterY;" + " dd = t0 / (0.000001 + (dx * dx) + (dy * dy));" + " ry = ry * 0.25 + float4(0.0, 0.25, 0.5, 0.75);" + " float2 t1 = step(dd.xz, dd.yw);" + " float4 ret = lerp(float4(rx.xz, ry.xz)," + " float4(rx.yw, ry.yw), t1.xyxy);" + " dd.xy = lerp(dd.xz, dd.yw, t1);" + " float t2 = step(dd.x, dd.y);" + " ret.xy = lerp(ret.xz, ret.yw, t2);" + /* FIXME: above currently broken; fall back to this */ + " ret.xy = float2(v_CenterX.x, v_CenterY.x * 0.25);" + " out_FragColor = tex2D(u_Texture, ret.xy);" "}" #endif );