Skip to content

Commit

Permalink
Playstation RHI Support
Browse files Browse the repository at this point in the history
Diffs=
f161bf4679 Tighter RHI integration, extra build options (#9149)

Co-authored-by: Jonathon Copeland <[email protected]>
  • Loading branch information
blakdragan7 and blakdragan7 committed Mar 5, 2025
1 parent 695dfda commit a778f64
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57d81702cb268580c8fbbb23084aa8a069982a0e
f161bf467917880176e3ded8ca0571879a76ff94
34 changes: 26 additions & 8 deletions decoders/premake5_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ if _OPTIONS['no-rive-decoders'] then
return
end

rive = path.getabsolute('../')

dofile(rive .. '/dependencies/premake5_libpng_v2.lua')
dofile(rive .. '/dependencies/premake5_libjpeg_v2.lua')
dofile(rive .. '/dependencies/premake5_libwebp_v2.lua')
local rive = path.getabsolute('../')

newoption({
trigger = 'no_rive_png',
Expand All @@ -20,6 +16,16 @@ newoption({
description = 'don\'t build jpeg support into the rive_decoders library (built-in jpeg decoding will fail)',
})

if not _OPTIONS["no_rive_png"] then
dofile(rive .. '/dependencies/premake5_libpng_v2.lua')
end

if not _OPTIONS["no_rive_jpeg"] then
dofile(rive .. '/dependencies/premake5_libjpeg_v2.lua')
end

dofile(rive .. '/dependencies/premake5_libwebp_v2.lua')

project('rive_decoders')
do
dependson('libwebp')
Expand All @@ -29,8 +35,6 @@ do
includedirs({
'include',
'../include',
libpng,
libjpeg,
libwebp .. '/src',
'%{cfg.targetdir}/include/libpng',
})
Expand Down Expand Up @@ -72,7 +76,21 @@ do
})
end

filter({ 'system:not macosx', 'system:not ios', 'options:not no_rive_png' })
filter({'options:not no_rive_png'})
do
includedirs({
libpng
})
end

filter({'options:not no_rive_jpeg'})
do
includedirs({
libjpeg
})
end

filter({ 'system:not macosx', 'system:not ios', 'options:not no_rive_png' })
do
dependson('zlib', 'libpng')
defines({ 'RIVE_PNG' })
Expand Down
17 changes: 17 additions & 0 deletions dependencies/premake5_harfbuzz_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ newoption({
description = 'don\'t rename harfbuzz symbols',
})

newoption({
trigger = 'harfbuzz_getenv_no_op',
description = 'force include the header to no add no op implementation for getenv',
})

project('rive_harfbuzz')
do
kind('StaticLib')
Expand Down Expand Up @@ -276,6 +281,18 @@ do
forceincludes({ 'rive_harfbuzz_renames.h' })
end

filter({ 'options:harfbuzz_getenv_no_op', 'files:**/src/hb-common.cc or **/src/hb-shaper.cc', 'options:no-harfbuzz-renames'})
do
includedirs({ './' })
forceincludes({ 'rive_harfbuzz_overrides.h'})
end

filter({ 'options:harfbuzz_getenv_no_op', 'files:**/src/hb-common.cc or **/src/hb-shaper.cc', 'options:not no-harfbuzz-renames'})
do
includedirs({ './' })
forceincludes({ 'rive_harfbuzz_overrides.h', 'rive_harfbuzz_renames.h' })
end

filter('system:macosx or system:ios')
do
defines({ 'HAVE_CORETEXT' })
Expand Down
1 change: 1 addition & 0 deletions dependencies/rive_harfbuzz_overrides.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
char* getenv(const char* _) { return nullptr; }
2 changes: 2 additions & 0 deletions include/rive/rive_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#define RIVE_BUILD_FOR_OSX
#endif

#define RIVE_NO_STD_SYSTEM

#endif

// We really like these headers, so we include them all the time.
Expand Down
7 changes: 6 additions & 1 deletion renderer/premake5_pls_renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ end

filter({})

newoption({
trigger = 'no_gl',
description = 'do not compile in support for opengl',
})

-- Minify and compile PLS shaders offline.
local nproc
if os.host() == 'windows' then
Expand Down Expand Up @@ -193,7 +198,7 @@ do
})
end

filter({ 'system:not ios' })
filter({ 'system:not ios', 'options:not no_gl' })
do
files({
'src/gl/gl_state.cpp',
Expand Down
4 changes: 3 additions & 1 deletion renderer/shader_hotload/shader_hotload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ static size_t load_bytecode_file_into_buffer(std::ifstream& shaderBytecodeFile,
char* bytecodeAllocation)
{
// Read entire file into buffer
shaderBytecodeFile.read(bytecodeAllocation, fileSize);
shaderBytecodeFile.read(
bytecodeAllocation,
rive::math::lossless_numeric_cast<std::streamsize>(fileSize));
const size_t numActualBytesRead = shaderBytecodeFile.gcount();
if (shaderBytecodeFile.good() && numActualBytesRead == fileSize)
{
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/shaders/draw_path_common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ INLINE bool unpack_tessellated_path_vertex(float4 patchVertexData,

// Extend the vertex by half the width of the AA ramp.
float2 vertexOffset =
MUL(norm, strokeRadius + aaRadius); // Bloat stroke width for AA.
norm * (strokeRadius + aaRadius); // Bloat stroke width for AA.

#ifndef @RENDER_MODE_MSAA
// Calculate the AA distance to both the outset and inset edges of the
Expand Down
22 changes: 16 additions & 6 deletions renderer/src/shaders/rhi.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ $typedef float3 packed_float3;

#ifdef @ENABLE_MIN_16_PRECISION

#if COMPILER_HLSL || COMPILER_VULKAN

$typedef $min16uint ushort;

#endif // COMPILER_HLSL

#else

#if COMPILER_HLSL || COMPILER_VULKAN

$typedef $uint ushort;

#endif
#endif // COMPILER_HLSL

#endif // ENABLE_MIN_16_PRECISION

#define SPLAT(A, B) A##B

Expand Down Expand Up @@ -117,7 +125,7 @@ $typedef $uint ushort;

#define TEXTURE_RGBA32UI(SET, IDX, NAME) uniform $Texture2D<uint4> NAME
#define TEXTURE_RGBA32F(SET, IDX, NAME) uniform $Texture2D<float4> NAME
#define TEXTURE_RGBA8(SET, IDX, NAME) uniform $Texture2D<$unorm float4> NAME
#define TEXTURE_RGBA8(SET, IDX, NAME) uniform $Texture2D<UNORM half4> NAME
#define TEXTURE_R16F(SET, IDX, NAME) uniform $Texture2D<half> NAME
#define TEXTURE_R16F_1D_ARRAY(SET, IDX, NAME) uniform $Texture2DArray<half> NAME
#define SAMPLED_R16F_REF(NAME, SAMPLER_NAME) \
Expand Down Expand Up @@ -159,7 +167,7 @@ $typedef $uint ushort;

#define PLS_BLOCK_BEGIN
#ifdef @ENABLE_TYPED_UAV_LOAD_STORE
#define PLS_DECL4F(IDX, NAME) uniform PLS_TEX2D<$unorm half4> NAME
#define PLS_DECL4F(IDX, NAME) uniform PLS_TEX2D<UNORM half4> NAME
#else
#define PLS_DECL4F(IDX, NAME) uniform PLS_TEX2D<uint> NAME
#endif
Expand Down Expand Up @@ -257,16 +265,18 @@ INLINE uint pls_atomic_add(PLS_TEX2D<uint> plane, int2 _plsCoord, uint x)
#define PLS_CONTEXT_DECL , int2 _plsCoord
#define PLS_CONTEXT_UNPACK , _plsCoord

#define PLS_MAIN(NAME) [$earlydepthstencil] void NAME(Varyings _varyings) { \
float2 _fragCoord = _varyings._pos.xy;\
#define PLS_MAIN(NAME) \
EARLYDEPTHSTENCIL void NAME(Varyings _varyings) \
{ \
float2 _fragCoord = _varyings._pos.xy; \
int2 _plsCoord = int2(floor(_fragCoord));

#define PLS_MAIN_WITH_IMAGE_UNIFORMS(NAME) PLS_MAIN(NAME)

#define EMIT_PLS }

#define PLS_FRAG_COLOR_MAIN(NAME) \
[$earlydepthstencil] half4 NAME(Varyings _varyings) : $SV_Target \
EARLYDEPTHSTENCIL half4 NAME(Varyings _varyings) : $SV_Target \
{ \
float2 _fragCoord = _varyings._pos.xy; \
int2 _plsCoord = int2(floor(_fragCoord)); \
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/shaders/unreal/draw_atlas_fill.usf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#include "Generated/constants.minified.ush"
#include "Generated/common.minified.ush"
#include "Generated/draw_path_common.minified.ush"
#include "Generated/draw_atlas.minified.ush"
#include "Generated/render_atlas.minified.ush"
2 changes: 1 addition & 1 deletion renderer/src/shaders/unreal/draw_atlas_stroke.usf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#include "Generated/constants.minified.ush"
#include "Generated/common.minified.ush"
#include "Generated/draw_path_common.minified.ush"
#include "Generated/draw_atlas.minified.ush"
#include "Generated/render_atlas.minified.ush"
1 change: 1 addition & 0 deletions tests/check_golds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ while :; do
-u)
TARGET="unreal"
DEFAULT_BACKEND=rhi
ARGS="$ARGS --no-rebuild --no-install"
shift
;;
-i)
Expand Down
3 changes: 3 additions & 0 deletions tests/common/tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <stdio.h>
#include <string.h>

#ifndef EXTERNAL_TCP_CLIENT_DEFINITION

std::unique_ptr<TCPClient> TCPClient::Connect(
const char* serverAddress /*server:port*/)
{
Expand Down Expand Up @@ -206,3 +208,4 @@ std::string TCPClient::recvString()
recvall(str.data(), length);
return str;
}
#endif
17 changes: 16 additions & 1 deletion tests/common/test_harness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
#include "png.h"
#include "zlib.h"
#include <vector>

#ifdef SYS_SIGNAL_H
#include <sys/signal.h>
const char* strsignal(int)
{
return "(strsignal) not suported on this platform";
}
#else
#include <signal.h>
#endif

#ifdef _WIN32
#include <io.h>
Expand Down Expand Up @@ -79,6 +88,7 @@ TestHarness& TestHarness::Instance()

TestHarness::TestHarness()
{
#ifndef NO_SIGNAL_FORWARD
// Forward signals to the test harness.
for (int i = 1; i <= SIGTERM; ++i)
{
Expand All @@ -88,6 +98,7 @@ TestHarness::TestHarness()
// Check for if the app exits early (before calling
// TestHarness::shutdown()).
atexit(check_early_exit);
#endif
}

void TestHarness::init(std::unique_ptr<TCPClient> tcpClient,
Expand Down Expand Up @@ -126,19 +137,21 @@ void TestHarness::init(std::filesystem::path outputDir, size_t pngThreadCount)

void TestHarness::initStdioThread()
{
#ifndef NO_REDIRECT_OUTPUT

#ifndef _WIN32
// Make stdout & stderr line buffered. (This is not supported on Windows.)
setvbuf(stdout, NULL, _IOLBF, 0);
setvbuf(stderr, NULL, _IOLBF, 0);
#endif

// Pipe stdout and sterr back to the server.
m_savedStdout = dup(1);
m_savedStderr = dup(2);
pipe(m_stdioPipe.data());
dup2(m_stdioPipe[1], 1);
dup2(m_stdioPipe[1], 2);
m_stdioThread = std::thread(MonitorStdIOThread, this);
#endif
}

void TestHarness::monitorStdIOThread()
Expand Down Expand Up @@ -427,6 +440,7 @@ void TestHarness::shutdown()

void TestHarness::shutdownStdioThread()
{
#ifndef NO_REDIRECT_OUTPUT
if (m_savedStdout != 0 || m_savedStderr != 0)
{
// Restore stdout and stderr.
Expand All @@ -442,6 +456,7 @@ void TestHarness::shutdownStdioThread()
close(m_stdioPipe[0]);
m_stdioPipe = {0, 0};
}
#endif
}

void TestHarness::shutdownInputPumpThread()
Expand Down
2 changes: 2 additions & 0 deletions tests/common/testing_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ TestingWindow::Backend TestingWindow::ParseBackend(const char* name,

static void set_environment_variable(const char* name, const char* value)
{
#ifndef PLATFORM_NO_ENV_API
if (const char* existingValue = getenv(name))
{
printf("warning: %s=%s already set. Overriding with %s=%s\n",
Expand All @@ -155,6 +156,7 @@ static void set_environment_variable(const char* name, const char* value)
#else
setenv(name, value, /*overwrite=*/true);
#endif
#endif
}

TestingWindow* TestingWindow::Init(Backend backend,
Expand Down
2 changes: 1 addition & 1 deletion tests/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int main(int argc, const char* argv[])
if (hotloadShaders)
{
hotloadShaders = false;
#ifndef RIVE_BUILD_FOR_IOS
#ifndef RIVE_NO_STD_SYSTEM
std::system("sh rebuild_shaders.sh /tmp/rive");
TestingWindow::Get()->hotloadShaders();
#endif
Expand Down
13 changes: 9 additions & 4 deletions tests/rive_tools_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,19 @@ function rive_tools_project(name, project_kind)
'rive',
'libpng',
'zlib',
'libjpeg',
'libwebp',
'rive_yoga',
'rive_harfbuzz',
'rive_sheenbidi',
})

filter({ 'kind:ConsoleApp or SharedLib or WindowedApp', 'options:not no_rive_jpeg' })
do
links({
'libjpeg',
})
end

if ndk then
relative_ndk = ndk
if string.sub(ndk, 1, 1) == '/' then
Expand Down Expand Up @@ -274,11 +280,10 @@ do
RIVE_PLS_DIR .. '/path_fiddle/fiddle_context_vulkan.cpp',
RIVE_PLS_DIR .. '/path_fiddle/fiddle_context_dawn.cpp',
})

filter({ 'options:for_unreal' })
filter({ 'options:for_unreal'})
do
defines({ 'RIVE_UNREAL', 'RIVE_TOOLS_NO_GLFW', 'RIVE_TOOLS_NO_GL' })
cppdialect('C++20')
end

filter({ 'toolset:not msc' })
Expand Down

0 comments on commit a778f64

Please sign in to comment.