Skip to content

Commit

Permalink
Add a "player" app to the tools
Browse files Browse the repository at this point in the history
"player" is a tool that draws multiple copies of a .riv fullscreen and reports the FPS. It's (sort of) a simplification and rewrite of path_fiddle. "player" takes advantage of the built-in TestingWindow and TestHarness server so it can be easily deployed remotely. Currently, only android is supported as a remote target.

This PR also overhauls and simplifies the android_tools app to use NativeActivities, and deletes almost all the kotlin code.

https://github.com/user-attachments/assets/ff31cc6b-c7fb-42f0-8159-f7b1d9aad9b6

Diffs=
b172dca87 Add a "player" app to the tools (#8004)

Co-authored-by: Chris Dalton <[email protected]>
  • Loading branch information
csmartdalton and csmartdalton committed Aug 30, 2024
1 parent edcc111 commit 1e3954e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9b755ed5b65a33a096ddca69a202658cb70b5a6d
b172dca87ca2dfd92c5ddb18c9142d059dff367c
2 changes: 1 addition & 1 deletion build/rive_build_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ filter({})
if _OPTIONS['os'] == 'android' then
pic('on') -- Position-independent code is required for NDK libraries.

local ndk = os.getenv('NDK_PATH') or os.getenv('ANDROID_NDK')
ndk = os.getenv('NDK_PATH') or os.getenv('ANDROID_NDK')
if not ndk then
error('export $NDK_PATH or $ANDROID_NDK')
end
Expand Down
3 changes: 1 addition & 2 deletions renderer/path_fiddle/fiddle_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class FiddleContext
virtual void end(GLFWwindow*, std::vector<uint8_t>* pixelData = nullptr) = 0;
virtual void tick(){};

static std::unique_ptr<FiddleContext> MakeGLSkia();
static std::unique_ptr<FiddleContext> MakeGLPLS();
static std::unique_ptr<FiddleContext> MakeGLPLS(FiddleContextOptions = {});
#ifdef RIVE_MACOSX
static std::unique_ptr<FiddleContext> MakeMetalPLS(FiddleContextOptions = {});
#else
Expand Down
110 changes: 10 additions & 100 deletions renderer/path_fiddle/fiddle_context_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

#ifdef RIVE_TOOLS_NO_GLFW

std::unique_ptr<FiddleContext> FiddleContext::MakeGLPLS() { return nullptr; }
std::unique_ptr<FiddleContext> FiddleContext::MakeGLPLS(FiddleContextOptions) { return nullptr; }

#else

#include "path_fiddle.hpp"
#include "rive/renderer/gl/gles3.hpp"
#include "rive/renderer/rive_renderer.hpp"
#include "rive/renderer/gl/render_context_gl_impl.hpp"
#include "rive/renderer/gl/render_target_gl.hpp"
Expand Down Expand Up @@ -173,7 +172,7 @@ class FiddleContextGL : public FiddleContext
0,
kZoomWindowWidth * kZoomWindowScale + 2,
kZoomWindowHeight * kZoomWindowScale + 2);
glClearColor(.6, .6, .6, 1);
glClearColor(.6f, .6f, .6f, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_zoomWindowFBO);
glBlitFramebuffer(0,
Expand All @@ -200,7 +199,10 @@ class FiddleContextGL : public FiddleContext
class FiddleContextGLPLS : public FiddleContextGL
{
public:
FiddleContextGLPLS()
FiddleContextGLPLS(FiddleContextOptions options) :
m_renderContext(RenderContextGLImpl::MakeContext({
.disableFragmentShaderInterlock = options.disableRasterOrdering,
}))
{
if (!m_renderContext)
{
Expand All @@ -218,6 +220,7 @@ class FiddleContextGLPLS : public FiddleContextGL
void onSizeChanged(GLFWwindow* window, int width, int height, uint32_t sampleCount) override
{
m_renderTarget = make_rcp<FramebufferRenderTargetGL>(width, height, 0, sampleCount);
glViewport(0, 0, width, height);
}

std::unique_ptr<Renderer> makeRenderer(int width, int height) override
Expand All @@ -243,106 +246,13 @@ class FiddleContextGLPLS : public FiddleContextGL
}

private:
std::unique_ptr<RenderContext> m_renderContext =
RenderContextGLImpl::MakeContext(RenderContextGLImpl::ContextOptions());
const std::unique_ptr<RenderContext> m_renderContext;
rcp<RenderTargetGL> m_renderTarget;
};

std::unique_ptr<FiddleContext> FiddleContext::MakeGLPLS()
std::unique_ptr<FiddleContext> FiddleContext::MakeGLPLS(FiddleContextOptions options)
{
return std::make_unique<FiddleContextGLPLS>();
}

#endif

#ifndef RIVE_SKIA

std::unique_ptr<FiddleContext> FiddleContext::MakeGLSkia() { return nullptr; }

#else

#include "skia_factory.hpp"
#include "skia_renderer.hpp"
#include "skia/include/core/SkCanvas.h"
#include "skia/include/core/SkSurface.h"
#include "skia/include/gpu/GrDirectContext.h"
#include "skia/include/gpu/gl/GrGLAssembleInterface.h"
#include "skia/include/gpu/gl/GrGLInterface.h"
#include "include/effects/SkImageFilters.h"

static GrGLFuncPtr get_skia_gl_proc_address(void* ctx, const char name[])
{
return glfwGetProcAddress(name);
}

class FiddleContextGLSkia : public FiddleContextGL
{
public:
FiddleContextGLSkia() :
m_grContext(
GrDirectContext::MakeGL(GrGLMakeAssembledInterface(nullptr, get_skia_gl_proc_address)))
{
if (!m_grContext)
{
fprintf(stderr, "GrDirectContext::MakeGL failed.\n");
abort();
}
}

rive::Factory* factory() override { return &m_factory; }

rive::gpu::RenderContext* renderContextOrNull() override { return nullptr; }

rive::gpu::RenderTarget* renderTargetOrNull() override { return nullptr; }

std::unique_ptr<Renderer> makeRenderer(int width, int height) override
{
GrBackendRenderTarget backendRT(width,
height,
1 /*samples*/,
0 /*stencilBits*/,
{0 /*fbo 0*/, GL_RGBA8});

SkSurfaceProps surfProps(0, kUnknown_SkPixelGeometry);

m_skSurface = SkSurface::MakeFromBackendRenderTarget(m_grContext.get(),
backendRT,
kBottomLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
nullptr,
&surfProps);
if (!m_skSurface)
{
fprintf(stderr, "SkSurface::MakeFromBackendRenderTarget failed.\n");
abort();
}
return std::make_unique<SkiaRenderer>(m_skSurface->getCanvas());
}

void begin(const RenderContext::FrameDescriptor& frameDescriptor) override
{
m_skSurface->getCanvas()->clear(frameDescriptor.clearColor);
m_grContext->resetContext();
m_skSurface->getCanvas()->save();
}

void onEnd() override
{
m_skSurface->getCanvas()->restore();
m_skSurface->flush();
}

void flushPLSContext() override {}

private:
SkiaFactory m_factory;
const sk_sp<GrDirectContext> m_grContext;
sk_sp<SkSurface> m_skSurface;
};

std::unique_ptr<FiddleContext> FiddleContext::MakeGLSkia()
{
return std::make_unique<FiddleContextGLSkia>();
return std::make_unique<FiddleContextGLPLS>(options);
}

#endif
2 changes: 1 addition & 1 deletion renderer/path_fiddle/fiddle_context_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class FiddleContextVulkanPLS : public FiddleContext
.set_engine_name("Rive Renderer")
#ifdef DEBUG
.set_debug_callback(rive_vkb::default_debug_callback)
#endif
.enable_validation_layers(m_options.enableVulkanValidationLayers)
#endif
.enable_extensions(glfwExtensionCount, glfwExtensions)
.build());
m_instanceDispatch = m_instance.make_table();
Expand Down
33 changes: 1 addition & 32 deletions renderer/path_fiddle/path_fiddle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ static void set_environment_variable(const char* name, const char* value)
#endif
}

bool skia = false;

enum class API
{
gl,
Expand Down Expand Up @@ -433,10 +431,6 @@ int main(int argc, const char** argv)
api = API::vulkan;
s_forceAtomicMode = true;
}
else if (!strcmp(argv[i], "--skia"))
{
skia = true;
}
#ifdef RIVE_DESKTOP_GL
else if (!strcmp(argv[i], "--angle_gl"))
{
Expand Down Expand Up @@ -573,43 +567,18 @@ int main(int argc, const char** argv)
switch (api)
{
case API::metal:
if (skia)
{
fprintf(stderr, "Skia not supported on Metal yet.\n");
break;
}
s_fiddleContext = FiddleContext::MakeMetalPLS(s_options);
break;
case API::d3d:
if (skia)
{
fprintf(stderr, "Skia not supported on d3d yet.\n");
break;
}
s_fiddleContext = FiddleContext::MakeD3DPLS(s_options);
break;
case API::dawn:
if (skia)
{
fprintf(stderr, "Skia not supported on dawn yet.\n");
break;
}
s_fiddleContext = FiddleContext::MakeDawnPLS(s_options);
break;
case API::vulkan:
if (skia)
{
fprintf(stderr, "Skia not supported on Vulkan yet.\n");
break;
}
s_fiddleContext = FiddleContext::MakeVulkanPLS(s_options);
break;
case API::gl:
if (skia)
{
s_fiddleContext = FiddleContext::MakeGLSkia();
break;
}
s_fiddleContext = FiddleContext::MakeGLPLS();
break;
}
Expand Down Expand Up @@ -667,7 +636,7 @@ static void update_window_title(double fps, int instances, int width, int height
{
title << " (x" << instances << " instances)";
}
title << " | " << (skia ? "Skia" : "Rive") << " Renderer";
title << " | Rive Renderer";
if (s_msaa)
{
title << " (msaa" << s_msaa << ')';
Expand Down
51 changes: 28 additions & 23 deletions renderer/rive_vk_bootstrap/rive_vk_bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ default_debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
break;
}
fprintf(stderr,
"PLS Vulkan error: %i: %s: %s\n",
"Rive Vulkan error: %i: %s: %s\n",
pCallbackData->messageIdNumber,
pCallbackData->pMessageIdName,
pCallbackData->pMessage);
abort();
case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT:
fprintf(stderr,
"PLS Vulkan Validation error: %i: %s: %s\n",
"Rive Vulkan Validation error: %i: %s: %s\n",
pCallbackData->messageIdNumber,
pCallbackData->pMessageIdName,
pCallbackData->pMessage);
abort();
case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT:
fprintf(stderr,
"PLS Vulkan Performance warning: %i: %s: %s\n",
"Rive Vulkan Performance warning: %i: %s: %s\n",
pCallbackData->messageIdNumber,
pCallbackData->pMessageIdName,
pCallbackData->pMessage);
Expand Down Expand Up @@ -149,32 +149,38 @@ std::tuple<vkb::PhysicalDevice, rive::gpu::VulkanFeatures> select_physical_devic
}
auto physicalDevice = VKB_CHECK(selectResult);

printf("==== Vulkan GPU (%s): %s ====\n",
rive_vkb::physical_device_type_name(physicalDevice.properties.deviceType),
physicalDevice.properties.deviceName);

rive::gpu::VulkanFeatures plsVulkanFeatures;
physicalDevice.enable_features_if_present({
.independentBlend = VK_TRUE,
.fillModeNonSolid = VK_TRUE,
.fragmentStoresAndAtomics = VK_TRUE,
});
printf("PLS Vulkan features: [");
if (physicalDevice.features.independentBlend)
{
plsVulkanFeatures.independentBlend = true;
printf(" independentBlend");
}
if (physicalDevice.features.fillModeNonSolid)

rive::gpu::VulkanFeatures riveVulkanFeatures;
riveVulkanFeatures.independentBlend = physicalDevice.features.independentBlend;
riveVulkanFeatures.fillModeNonSolid = physicalDevice.features.fillModeNonSolid;
riveVulkanFeatures.fragmentStoresAndAtomics = physicalDevice.features.fragmentStoresAndAtomics;

{
plsVulkanFeatures.fillModeNonSolid = true;
printf(" fillModeNonSolid");
printf("==== Vulkan GPU (%s): %s [",
physical_device_type_name(physicalDevice.properties.deviceType),
physicalDevice.properties.deviceName);
const char* prefix = "";
if (riveVulkanFeatures.independentBlend)
printf("%sindependentBlend", std::exchange(prefix, ", "));
if (riveVulkanFeatures.fillModeNonSolid)
printf("%sfillModeNonSolid", std::exchange(prefix, ", "));
if (riveVulkanFeatures.fragmentStoresAndAtomics)
printf("%sfragmentStoresAndAtomics", std::exchange(prefix, ", "));
printf("] ====\n");
}
if (physicalDevice.features.fragmentStoresAndAtomics)

#if 0
printf("Extensions:\n");
for (const auto& ext : physicalDevice.get_available_extensions())
{
plsVulkanFeatures.fragmentStoresAndAtomics = true;
printf(" fragmentStoresAndAtomics");
printf(" %s\n", ext.c_str());
}
#endif
if (physicalDevice.enable_extension_if_present(
VK_EXT_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME) ||
physicalDevice.enable_extension_if_present("VK_AMD_rasterization_order_attachment_access"))
Expand All @@ -187,12 +193,11 @@ std::tuple<vkb::PhysicalDevice, rive::gpu::VulkanFeatures> select_physical_devic
};
if (physicalDevice.enable_extension_features_if_present(rasterOrderFeatures))
{
plsVulkanFeatures.rasterizationOrderColorAttachmentAccess = true;
riveVulkanFeatures.rasterizationOrderColorAttachmentAccess = true;
printf(" rasterizationOrderColorAttachmentAccess");
}
}
printf(" ]\n");

return {physicalDevice, plsVulkanFeatures};
return {physicalDevice, riveVulkanFeatures};
}
} // namespace rive_vkb
5 changes: 5 additions & 0 deletions renderer/src/shaders/glsl.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,14 @@

#ifdef @USING_PLS_STORAGE_TEXTURES

#ifdef @TARGET_VULKAN
#define PLS_DECLUI_ATOMIC(IDX, NAME) \
layout(set = PLS_TEXTURE_BINDINGS_SET, binding = IDX, r32ui) \
uniform highp coherent uimage2D NAME
#else
#define PLS_DECLUI_ATOMIC(IDX, NAME) \
layout(binding = IDX, r32ui) uniform highp coherent uimage2D NAME
#endif
#define PLS_LOADUI_ATOMIC(PLANE) imageLoad(PLANE, _plsCoord).r
#define PLS_STOREUI_ATOMIC(PLANE, VALUE) imageStore(PLANE, _plsCoord, uvec4(VALUE))
#define PLS_ATOMIC_MAX(PLANE, X) imageAtomicMax(PLANE, _plsCoord, X)
Expand Down

0 comments on commit 1e3954e

Please sign in to comment.