Skip to content

Commit

Permalink
Merge branch 'master' into specialized-shaders-2
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Jul 14, 2024
2 parents 4e9f824 + 8eab353 commit c737589
Show file tree
Hide file tree
Showing 28 changed files with 5,204 additions and 67 deletions.
65 changes: 56 additions & 9 deletions .github/workflows/Hydra_Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,27 @@ jobs:
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Upload core
uses: actions/upload-artifact@v2
- name: Upload Hydra core
uses: actions/upload-artifact@v4
with:
name: Windows core
name: Windows Hydra core
path: '${{github.workspace}}/build/${{ env.BUILD_TYPE }}/Alber.dll'

- name: Configure CMake (Again)
run: |
rm -r -fo ${{github.workspace}}/build
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_USER_BUILD=ON -DBUILD_LIBRETRO_CORE=ON
- name: Build (Again)
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Upload Libretro core
uses: actions/upload-artifact@v4
with:
name: Windows Libretro core
path: |
${{github.workspace}}/build/panda3ds_libretro.dll
${{github.workspace}}/docs/libretro/panda3ds_libretro.info
MacOS:
runs-on: macos-13
Expand All @@ -61,11 +76,27 @@ jobs:
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Upload core
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: MacOS core
name: MacOS Hydra core
path: '${{github.workspace}}/build/libAlber.dylib'

- name: Configure CMake (Again)
run: |
rm -rf ${{github.workspace}}/build
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_USER_BUILD=ON -DBUILD_LIBRETRO_CORE=ON
- name: Build (Again)
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} && ls -R ${{github.workspace}}/build

- name: Upload Libretro core
uses: actions/upload-artifact@v4
with:
name: MacOS Libretro core
path: |
${{github.workspace}}/build/panda3ds_libretro.dylib
${{github.workspace}}/docs/libretro/panda3ds_libretro.info
Linux:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -98,11 +129,27 @@ jobs:
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Upload core
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Linux core
name: Linux Hydra core
path: '${{github.workspace}}/build/libAlber.so'

- name: Configure CMake (Again)
run: |
rm -rf ${{github.workspace}}/build
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17 -DENABLE_USER_BUILD=ON -DBUILD_LIBRETRO_CORE=ON
- name: Build (Again)
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Upload Libretro core
uses: actions/upload-artifact@v4
with:
name: Linux Libretro core
path: |
${{github.workspace}}/build/panda3ds_libretro.so
${{github.workspace}}/docs/libretro/panda3ds_libretro.info
Android-x64:
runs-on: ubuntu-latest

Expand All @@ -129,7 +176,7 @@ jobs:
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Upload core
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Android core
name: Android Hydra core
path: '${{github.workspace}}/build/libAlber.so'
27 changes: 21 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ option(ENABLE_DISCORD_RPC "Compile with Discord RPC support (disabled by default
option(ENABLE_LUAJIT "Enable scripting with the Lua programming language" ON)
option(ENABLE_QT_GUI "Enable the Qt GUI. If not selected then the emulator uses a minimal SDL-based UI instead" OFF)
option(BUILD_HYDRA_CORE "Build a Hydra core" OFF)
option(BUILD_LIBRETRO_CORE "Build a Libretro core" OFF)

if(BUILD_HYDRA_CORE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

if(BUILD_LIBRETRO_CORE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_compile_definitions(__LIBRETRO__)
endif()

add_library(AlberCore STATIC)

include_directories(${PROJECT_SOURCE_DIR}/include/)
Expand Down Expand Up @@ -338,8 +344,8 @@ endif()

if(ENABLE_VULKAN)
find_package(
Vulkan 1.3.206 REQUIRED
COMPONENTS glslangValidator
Vulkan REQUIRED
COMPONENTS glslang
)

set(RENDERER_VK_INCLUDE_FILES include/renderer_vk/renderer_vk.hpp
Expand Down Expand Up @@ -382,7 +388,7 @@ if(ENABLE_VULKAN)
add_custom_command(
OUTPUT ${HOST_SHADER_SPIRV}
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/host_shaders/"
COMMAND Vulkan::glslangValidator ${RENDERER_VK_HOST_SHADERS_FLAGS} -V "${PROJECT_SOURCE_DIR}/${HOST_SHADER_SOURCE}" -o ${HOST_SHADER_SPIRV}
COMMAND glslang ${RENDERER_VK_HOST_SHADERS_FLAGS} -V "${PROJECT_SOURCE_DIR}/${HOST_SHADER_SOURCE}" -o ${HOST_SHADER_SPIRV}
DEPENDS ${HOST_SHADER_SOURCE}
)
list( APPEND RENDERER_VK_HOST_SHADERS_SPIRV ${HOST_SHADER_SPIRV} )
Expand Down Expand Up @@ -438,7 +444,7 @@ else()
target_compile_definitions(AlberCore PUBLIC "PANDA3DS_FRONTEND_SDL=1")
endif()

if(NOT BUILD_HYDRA_CORE)
if(NOT BUILD_HYDRA_CORE AND NOT BUILD_LIBRETRO_CORE)
add_executable(Alber)

if(ENABLE_QT_GUI)
Expand All @@ -449,11 +455,11 @@ if(NOT BUILD_HYDRA_CORE)

set(FRONTEND_SOURCE_FILES src/panda_qt/main.cpp src/panda_qt/screen.cpp src/panda_qt/main_window.cpp src/panda_qt/about_window.cpp
src/panda_qt/config_window.cpp src/panda_qt/zep.cpp src/panda_qt/text_editor.cpp src/panda_qt/cheats_window.cpp src/panda_qt/mappings.cpp
src/panda_qt/patch_window.cpp src/panda_qt/elided_label.cpp
src/panda_qt/patch_window.cpp src/panda_qt/elided_label.cpp src/panda_qt/shader_editor.cpp
)
set(FRONTEND_HEADER_FILES include/panda_qt/screen.hpp include/panda_qt/main_window.hpp include/panda_qt/about_window.hpp
include/panda_qt/config_window.hpp include/panda_qt/text_editor.hpp include/panda_qt/cheats_window.hpp
include/panda_qt/patch_window.hpp include/panda_qt/elided_label.hpp
include/panda_qt/patch_window.hpp include/panda_qt/elided_label.hpp include/panda_qt/shader_editor.hpp
)

source_group("Source Files\\Qt" FILES ${FRONTEND_SOURCE_FILES})
Expand Down Expand Up @@ -500,6 +506,15 @@ elseif(BUILD_HYDRA_CORE)
include_directories(third_party/hydra_core/include)
add_library(Alber SHARED src/hydra_core.cpp)
target_link_libraries(Alber PUBLIC AlberCore)
elseif(BUILD_LIBRETRO_CORE)
include_directories(third_party/libretro/include)
add_library(Alber SHARED src/libretro_core.cpp)
target_link_libraries(Alber PUBLIC AlberCore)

set_target_properties(Alber PROPERTIES
OUTPUT_NAME "panda3ds_libretro"
PREFIX ""
)
endif()

if(ENABLE_LTO OR ENABLE_USER_BUILD)
Expand Down
34 changes: 34 additions & 0 deletions docs/libretro/panda3ds_libretro.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Software Information
display_name = "Nintendo - 3DS (Panda3DS)"
authors = "Panda3DS Authors (tm)"
supported_extensions = "3ds|3dsx|elf|axf|cci|cxi|app"
corename = "Panda3DS"
categories = "Emulator"
license = "GPLv3"
permissions = ""
display_version = "Git"

# Hardware Information
manufacturer = "Nintendo"
systemname = "3DS"
systemid = "3ds"

# Libretro Information
database = "Nintendo - Nintendo 3DS"
supports_no_game = "false"
savestate = "true"
savestate_features = "basic"
cheats = "false"
input_descriptors = "true"
memory_descriptors = "false"
libretro_saves = "true"
core_options = "true"
core_options_version = "1.0"
load_subsystem = "false"
hw_render = "true"
required_hw_api = "OpenGL Core >= 4.1"
needs_fullpath = "true"
disk_control = "false"
is_experimental = "true"

description = "Panda3DS !"
1 change: 1 addition & 0 deletions include/audio/hle_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ namespace Audio {
// Decode an entire buffer worth of audio
void decodeBuffer(DSPSource& source);

SampleBuffer decodePCM8(const u8* data, usize sampleCount, Source& source);
SampleBuffer decodePCM16(const u8* data, usize sampleCount, Source& source);
SampleBuffer decodeADPCM(const u8* data, usize sampleCount, Source& source);

Expand Down
2 changes: 1 addition & 1 deletion include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Remember to initialize every field here to its default value otherwise bad things will happen
struct EmulatorConfig {
// Only enable the shader JIT by default on platforms where it's completely tested
#ifdef PANDA3DS_X64_HOST
#if defined(PANDA3DS_X64_HOST) || defined(PANDA3DS_ARM64_HOST)
static constexpr bool shaderJitDefault = true;
#else
static constexpr bool shaderJitDefault = false;
Expand Down
2 changes: 2 additions & 0 deletions include/kernel/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "services/service_manager.hpp"

class CPU;
struct Scheduler;

class Kernel {
std::span<u32, 16> regs;
Expand Down Expand Up @@ -243,6 +244,7 @@ class Kernel {
}

ServiceManager& getServiceManager() { return serviceManager; }
Scheduler& getScheduler();

void sendGPUInterrupt(GPUInterrupt type) { serviceManager.sendGPUInterrupt(type); }
void clearInstructionCache();
Expand Down
2 changes: 2 additions & 0 deletions include/loader/ncch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct NCCH {
CodeSetInfo text, data, rodata;
FSInfo partitionInfo;

std::optional<Crypto::AESKey> primaryKey, secondaryKey;

// Contents of the .code file in the ExeFS
std::vector<u8> codeFile;
// Contains of the cart's save data
Expand Down
7 changes: 4 additions & 3 deletions include/panda_qt/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "panda_qt/config_window.hpp"
#include "panda_qt/patch_window.hpp"
#include "panda_qt/screen.hpp"
#include "panda_qt/shader_editor.hpp"
#include "panda_qt/text_editor.hpp"
#include "services/hid.hpp"

Expand Down Expand Up @@ -48,6 +49,7 @@ class MainWindow : public QMainWindow {
EditCheat,
PressTouchscreen,
ReleaseTouchscreen,
ReloadUbershader,
};

// Tagged union representing our message queue messages
Expand Down Expand Up @@ -99,6 +101,7 @@ class MainWindow : public QMainWindow {
CheatsWindow* cheatsEditor;
TextEditorWindow* luaEditor;
PatchWindow* patchWindow;
ShaderEditorWindow* shaderEditor;

// We use SDL's game controller API since it's the sanest API that supports as many controllers as possible
SDL_GameController* gameController = nullptr;
Expand All @@ -110,9 +113,6 @@ class MainWindow : public QMainWindow {
void selectROM();
void dumpDspFirmware();
void dumpRomFS();
void openLuaEditor();
void openCheatsEditor();
void openPatchWindow();
void showAboutMenu();
void initControllers();
void pollControllers();
Expand All @@ -139,5 +139,6 @@ class MainWindow : public QMainWindow {
void mouseReleaseEvent(QMouseEvent* event) override;

void loadLuaScript(const std::string& code);
void reloadShader(const std::string& shader);
void editCheat(u32 handle, const std::vector<uint8_t>& cheat, const std::function<void(u32)>& callback);
};
27 changes: 27 additions & 0 deletions include/panda_qt/shader_editor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <QApplication>
#include <QDialog>
#include <QWidget>
#include <string>

#include "zep.h"
#include "zep/mode_repl.h"
#include "zep/regress.h"

class ShaderEditorWindow : public QDialog {
Q_OBJECT

private:
Zep::ZepWidget_Qt zepWidget;
Zep::IZepReplProvider replProvider;
static constexpr float fontSize = 14.0f;

public:
// Whether this backend supports shader editor
bool supported = true;

ShaderEditorWindow(QWidget* parent, const std::string& filename, const std::string& initialText);
void setText(const std::string& text) { zepWidget.GetEditor().GetMRUBuffer()->SetText(text); }
void setEnable(bool enable);
};
8 changes: 8 additions & 0 deletions include/renderer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <span>
#include <string>
#include <optional>

#include "PICA/pica_vertex.hpp"
Expand Down Expand Up @@ -66,6 +67,13 @@ class Renderer {
// This function does things like write back or cache necessary state before we delete our context
virtual void deinitGraphicsContext() = 0;

// Functions for hooking up the renderer core to the frontend's shader editor for editing ubershaders in real time
// SupportsShaderReload: Indicates whether the backend offers ubershader reload support or not
// GetUbershader/SetUbershader: Gets or sets the renderer's current ubershader
virtual bool supportsShaderReload() { return false; }
virtual std::string getUbershader() { return ""; }
virtual void setUbershader(const std::string& shader) {}

// Functions for initializing the graphics context for the Qt frontend, where we don't have the convenience of SDL_Window
#ifdef PANDA3DS_FRONTEND_QT
virtual void initGraphicsContext(GL::Context* context) { Helpers::panic("Tried to initialize incompatible renderer with GL context"); }
Expand Down
7 changes: 6 additions & 1 deletion include/renderer_gl/renderer_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ class RendererGL final : public Renderer {
void textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 inputSize, u32 outputSize, u32 flags) override;
void drawVertices(PICA::PrimType primType, std::span<const PICA::Vertex> vertices) override; // Draw the given vertices
void deinitGraphicsContext() override;


virtual bool supportsShaderReload() override { return true; }
virtual std::string getUbershader() override;
virtual void setUbershader(const std::string& shader) override;

std::optional<ColourBuffer> getColourBuffer(u32 addr, PICA::ColorFmt format, u32 width, u32 height, bool createIfnotFound = true);

// Note: The caller is responsible for deleting the currently bound FBO before calling this
void setFBO(uint handle) { screenFramebuffer.m_handle = handle; }
void resetStateManager() { gl.reset(); }
void initUbershader(OpenGL::Program& program);

#ifdef PANDA3DS_FRONTEND_QT
virtual void initGraphicsContext([[maybe_unused]] GL::Context* context) override { initGraphicsContextInternal(); }
Expand Down
3 changes: 2 additions & 1 deletion include/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct Scheduler {
VBlank = 0, // End of frame event
UpdateTimers = 1, // Update kernel timer objects
RunDSP = 2, // Make the emulated DSP run for one audio frame
Panic = 3, // Dummy event that is always pending and should never be triggered (Timestamp = UINT64_MAX)
SignalY2R = 3, // Signal that a Y2R conversion has finished
Panic = 4, // Dummy event that is always pending and should never be triggered (Timestamp = UINT64_MAX)
TotalNumberOfEvents // How many event types do we have in total?
};
static constexpr usize totalNumberOfEvents = static_cast<usize>(EventType::TotalNumberOfEvents);
Expand Down
1 change: 1 addition & 0 deletions include/services/service_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ class ServiceManager {
HIDService& getHID() { return hid; }
NFCService& getNFC() { return nfc; }
DSPService& getDSP() { return dsp; }
Y2RService& getY2R() { return y2r; }
};
6 changes: 5 additions & 1 deletion include/services/y2r.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ class Y2RService {
void startConversion(u32 messagePointer);
void stopConversion(u32 messagePointer);

public:
bool isBusy;

public:
Y2RService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}
void reset();
void handleSyncRequest(u32 messagePointer);

void signalConversionDone();
};
Loading

0 comments on commit c737589

Please sign in to comment.