From 1aba604e1180feb29ad5f40c2bd5e8b81134eb4d Mon Sep 17 00:00:00 2001 From: TurtleP Date: Mon, 4 Nov 2024 08:38:40 -0500 Subject: [PATCH] get switch rendering started-ish --- CMakeLists.txt | 8 ++- include/driver/display/Renderer.tcc | 4 +- include/driver/graphics/StreamBuffer.tcc | 1 + include/modules/graphics/Shader.tcc | 3 + platform/cafe/CMakeLists.txt | 1 + platform/hac/CMakeLists.txt | 2 +- platform/hac/include/driver/display/deko.hpp | 8 ++- .../driver/display/deko3d/CCmdVtxRing.h | 6 +- .../include/driver/graphics/StreamBuffer.hpp | 29 +++++---- .../hac/include/modules/graphics/Graphics.hpp | 4 ++ .../hac/include/modules/graphics/Shader.hpp | 6 +- .../hac/include/modules/graphics/Texture.hpp | 44 +++++++++++++ platform/hac/romfs/shaders/transform_vsh.dksh | Bin 1024 -> 768 bytes platform/hac/source/driver/EventQueue.cpp | 10 +-- platform/hac/source/driver/display/deko.cpp | 20 +++++- .../hac/source/modules/graphics/Graphics.cpp | 59 ++++++++++++++++++ .../hac/source/modules/graphics/Shader.cpp | 19 +++--- .../modules/joystick/JoystickModule.cpp | 1 + source/modules/joystick/wrap_Joystick.cpp | 2 +- 19 files changed, 187 insertions(+), 40 deletions(-) create mode 100644 platform/hac/include/modules/graphics/Texture.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index aff940ddc..63307b085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,9 @@ if (NINTENDO_SWITCH) source/modules/image/magpie/KTXHandler.cpp source/modules/image/magpie/PKMHandler.cpp source/modules/image/magpie/PNGHandler.cpp + source/modules/font/freetype/Font.cpp + source/modules/font/freetype/TrueTypeRasterizer.cpp + source/modules/graphics/freetype/Font.cpp ) add_library(ddsparse @@ -131,7 +134,10 @@ if (NINTENDO_SWITCH) libraries/ddsparse/ddsinfo.h ) - target_link_libraries(${PROJECT_NAME} PRIVATE ddsparse) + find_package(Freetype REQUIRED) + target_link_libraries(${PROJECT_NAME} PRIVATE Freetype::Freetype bz2 png turbojpeg ddsparse) + + execute_process(COMMAND patch -d ${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket -N -i ${PROJECT_SOURCE_DIR}/platform/hac/libraries/luasocket.patch) endif() if (NINTENDO_WIIU) diff --git a/include/driver/display/Renderer.tcc b/include/driver/display/Renderer.tcc index 79c670869..58d9581bc 100644 --- a/include/driver/display/Renderer.tcc +++ b/include/driver/display/Renderer.tcc @@ -2,11 +2,11 @@ #include "common/Singleton.tcc" +#include "modules/graphics/Graphics.tcc" #include "modules/graphics/Shader.tcc" #include "modules/graphics/renderstate.hpp" -#include "modules/graphics/vertex.hpp" -#include "driver/graphics/DrawCommand.hpp" +#include "modules/graphics/vertex.hpp" #include #include diff --git a/include/driver/graphics/StreamBuffer.tcc b/include/driver/graphics/StreamBuffer.tcc index 188e09855..3749d63cb 100644 --- a/include/driver/graphics/StreamBuffer.tcc +++ b/include/driver/graphics/StreamBuffer.tcc @@ -2,6 +2,7 @@ #include "common/Object.hpp" +#include "modules/graphics/Resource.hpp" #include "modules/graphics/vertex.hpp" #include diff --git a/include/modules/graphics/Shader.tcc b/include/modules/graphics/Shader.tcc index 9d61d13fe..de2f850e1 100644 --- a/include/modules/graphics/Shader.tcc +++ b/include/modules/graphics/Shader.tcc @@ -31,6 +31,9 @@ namespace love static ShaderBase* current; static ShaderBase* standardShaders[STANDARD_MAX_ENUM]; + ShaderBase() + {} + ShaderBase(StandardShader type); virtual ~ShaderBase(); diff --git a/platform/cafe/CMakeLists.txt b/platform/cafe/CMakeLists.txt index 02e5d2806..8894fa71a 100644 --- a/platform/cafe/CMakeLists.txt +++ b/platform/cafe/CMakeLists.txt @@ -28,6 +28,7 @@ source/driver/audio/SoundChannel.cpp source/driver/display/Framebuffer.cpp source/driver/display/GX2.cpp source/driver/display/Uniform.cpp +source/driver/graphics/StreamBuffer.cpp source/driver/EventQueue.cpp source/modules/audio/Source.cpp source/modules/graphics/Graphics.cpp diff --git a/platform/hac/CMakeLists.txt b/platform/hac/CMakeLists.txt index 938d85701..4d058328a 100644 --- a/platform/hac/CMakeLists.txt +++ b/platform/hac/CMakeLists.txt @@ -34,7 +34,7 @@ source/driver/audio/MemoryPool.cpp source/driver/display/deko3d/CIntrusiveTree.cpp source/driver/display/deko3d/CMemPool.cpp source/driver/display/Framebuffer.cpp -source/driver/display/deko3d.cpp +source/driver/display/deko.cpp source/driver/EventQueue.cpp source/modules/audio/Source.cpp source/modules/graphics/Graphics.cpp diff --git a/platform/hac/include/driver/display/deko.hpp b/platform/hac/include/driver/display/deko.hpp index b293f1ee6..87dee5411 100644 --- a/platform/hac/include/driver/display/deko.hpp +++ b/platform/hac/include/driver/display/deko.hpp @@ -10,7 +10,7 @@ #include "driver/display/deko3d/CCmdVtxRing.h" #include "driver/display/deko3d/CDescriptorSet.h" -#include "modules/graphics/Shader.hpp" +#include "modules/graphics/Texture.hpp" #include "modules/graphics/vertex.hpp" /* Enforces GLSL std140/std430 alignment rules for glm types */ @@ -68,9 +68,11 @@ namespace love void setVertexWinding(Winding winding); - void prepareDraw(GraphicsBase* graphics) override; + void prepareDraw(GraphicsBase* graphics); - void useProgram(const Shader::Program& program); + void useProgram(const dk::Shader& vertex, const dk::Shader& fragment); + + void bindBuffer(BufferUsage usage, DkGpuAddr buffer, size_t size); void onModeChanged() { diff --git a/platform/hac/include/driver/display/deko3d/CCmdVtxRing.h b/platform/hac/include/driver/display/deko3d/CCmdVtxRing.h index a1a17067e..b372acf27 100644 --- a/platform/hac/include/driver/display/deko3d/CCmdVtxRing.h +++ b/platform/hac/include/driver/display/deko3d/CCmdVtxRing.h @@ -37,8 +37,7 @@ class CCmdVtxRing return m_mem; } - /* Return current buffer's size */ - const uint32_t getSize() + uint32_t getSize() const { return m_mem.getSize() / NumSlices; } @@ -47,8 +46,7 @@ class CCmdVtxRing std::pair begin() { const auto offset = m_curSlice * m_sliceSize; - return std::make_pair((void*)((char*)m_mem.getCpuAddr() + offset), - m_mem.getGpuAddr() + offset); + return std::make_pair((void*)((char*)m_mem.getCpuAddr() + offset), m_mem.getGpuAddr() + offset); } /* diff --git a/platform/hac/include/driver/graphics/StreamBuffer.hpp b/platform/hac/include/driver/graphics/StreamBuffer.hpp index 783865f9a..b3a17dffd 100644 --- a/platform/hac/include/driver/graphics/StreamBuffer.hpp +++ b/platform/hac/include/driver/graphics/StreamBuffer.hpp @@ -1,7 +1,10 @@ #pragma once -#include "driver/display/deko.hpp" #include "driver/graphics/StreamBuffer.tcc" +#include "modules/graphics/Volatile.hpp" + +#include "driver/display/deko.hpp" +#include "driver/display/deko3d/CMemPool.h" namespace love { @@ -11,32 +14,34 @@ namespace love public: StreamBuffer(BufferUsage usage, size_t size) : StreamBufferBase(usage, size) { - size_t align = (size + DK_CMDMEM_ALIGNMENT - 1) & ~(DK_CMDMEM_ALIGNMENT - 1); - - this->memory = dk::MemBlockMaker { d3d.getDevice(), align } - .setFlags(DkMemBlockFlags_GpuCached | DkMemBlockFlags_CpuUncached) - .create(); + this->sliceSize = (size + DK_CMDMEM_ALIGNMENT - 1) & ~(DK_CMDMEM_ALIGNMENT - 1); } + StreamBuffer(const StreamBuffer&) = delete; + + StreamBuffer& operator=(const StreamBuffer&) = delete; + ~StreamBuffer() - {} + { + this->memory.destroy(); + } - MapInfo StreamBuffer::map(size_t) override + MapInfo map(size_t) { MapInfo info {}; - info.data = &this->memory.getCpuAddr()[this->index]; + info.data = &((T*)this->memory.getCpuAddr())[this->index]; info.size = this->bufferSize - this->frameGPUReadOffset; return info; } - ptrdiff_t getHandle() const override + ptrdiff_t getHandle() const { - return 0; + return (ptrdiff_t)this->memory.getGpuAddr(); } private: - dk::UniqueMemBlock memory; + CMemPool::Handle memory; uint32_t sliceSize; }; } // namespace love diff --git a/platform/hac/include/modules/graphics/Graphics.hpp b/platform/hac/include/modules/graphics/Graphics.hpp index 0833febce..ebed0e21a 100644 --- a/platform/hac/include/modules/graphics/Graphics.hpp +++ b/platform/hac/include/modules/graphics/Graphics.hpp @@ -43,6 +43,10 @@ namespace love virtual FontBase* newDefaultFont(int size, const Rasterizer::Settings& settings) override; + // clang-format off + virtual TextureBase* newTexture(const TextureBase::Settings& settings, const TextureBase::Slices* data = nullptr) override; + // clang-format on + virtual bool setMode(int width, int height, int pixelWidth, int pixelHeight, bool backBufferStencil, bool backBufferDepth, int msaa) override; diff --git a/platform/hac/include/modules/graphics/Shader.hpp b/platform/hac/include/modules/graphics/Shader.hpp index a94752f00..2b5825293 100644 --- a/platform/hac/include/modules/graphics/Shader.hpp +++ b/platform/hac/include/modules/graphics/Shader.hpp @@ -1,10 +1,10 @@ #pragma once +#include "driver/display/deko3d/CMemPool.h" +#include "modules/graphics/Graphics.hpp" #include "modules/graphics/Shader.tcc" #include "modules/graphics/Volatile.hpp" -#include "driver/display/deko3d/CMemPool.h" - #include namespace love @@ -30,6 +30,8 @@ namespace love Stage fragment; } program; + Shader(); + Shader(StandardShader shader); virtual ~Shader(); diff --git a/platform/hac/include/modules/graphics/Texture.hpp b/platform/hac/include/modules/graphics/Texture.hpp new file mode 100644 index 000000000..f04c5e705 --- /dev/null +++ b/platform/hac/include/modules/graphics/Texture.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include "modules/graphics/Texture.tcc" +#include "modules/graphics/Volatile.hpp" + +#include + +namespace love +{ + class Texture final : public TextureBase, public Volatile + { + public: + Texture(GraphicsBase* graphics, const Settings& settings, const Slices* data); + + virtual ~Texture(); + + bool loadVolatile() override; + + void unloadVolatile() override; + + ptrdiff_t getHandle() const override; + + ptrdiff_t getRenderTargetHandle() const override; + + ptrdiff_t getSamplerHandle() const override; + + void setSamplerState(const SamplerState& state) override; + + void uploadByteData(const void* data, size_t size, int slice, int mipmap, const Rect& rect) override; + + void generateMipmapsInternal() override; + + void setHandleData(void* data) override + {} + + private: + void createTexture(); + + Slices slices; + + DkImage texture; + DkSampler sampler; + }; +} // namespace love diff --git a/platform/hac/romfs/shaders/transform_vsh.dksh b/platform/hac/romfs/shaders/transform_vsh.dksh index 394efc1170b7474569472813de352018d785a4c8..7e5ba60483ce37134ee6ac80950af1858b819a24 100644 GIT binary patch delta 351 zcmXw#u}T9$5QhJm-Md{aa_JNlE~fDj1UWHbyP*g84CINOFlKveT7HG4|at;andAm9Pz-UxX}Ruw7nh;j+gl?AM(G7zZ8HK(40`wu|sMR<)F zS^tm#bKy$EzesiwVkx}AN;o*PnYq`hw4I{_Ndj+dWbU)l&X~-7RqOiA1Mfe_b=>rA Q<3}*fKQ1Cnor`)Oe`ji8i2wiq literal 1024 zcmdr}Jx>Bb5S`h*V^5p2(~gZ6w04wYVxmL}6ANrlxd8D4BPy}-3KA&nZLg!XqqXBF zpq-}$&{y~M zNx_vyodNL<6fNx1+(LF($M>W2UHQ!V zjO@*Ivd=o^*`EPgKU^5jbuePxSbZeW-Xd40tS6sWtZ{!MFL#(b9+gBg8j68I?2u diff --git a/platform/hac/source/driver/EventQueue.cpp b/platform/hac/source/driver/EventQueue.cpp index 246c7b28a..df4127135 100644 --- a/platform/hac/source/driver/EventQueue.cpp +++ b/platform/hac/source/driver/EventQueue.cpp @@ -94,9 +94,9 @@ namespace love joystick->update(); - for (int input = 0; input < Joystick::GAMEPAD_BUTTON_MAX_ENUM; input++) + for (int input = 0; input < JoystickBase::GAMEPAD_BUTTON_MAX_ENUM; input++) { - std::vector inputs = { Joystick::GamepadButton(input) }; + std::vector inputs = { JoystickBase::GamepadButton(input) }; if (joystick->isDown(inputs)) this->sendGamepadButtonEvent(SUBTYPE_GAMEPADDOWN, 0, input); @@ -105,11 +105,11 @@ namespace love this->sendGamepadButtonEvent(SUBTYPE_GAMEPADUP, 0, input); } - for (int input = 0; input < Joystick::GAMEPAD_AXIS_MAX_ENUM; input++) + for (int input = 0; input < JoystickBase::GAMEPAD_AXIS_MAX_ENUM; input++) { - if (joystick->isAxisChanged(Joystick::GamepadAxis(input))) + if (joystick->isAxisChanged(JoystickBase::GamepadAxis(input))) { - float value = joystick->getAxis(Joystick::GamepadAxis(input)); + float value = joystick->getAxis(JoystickBase::GamepadAxis(input)); this->sendGamepadAxisEvent(0, input, value); } } diff --git a/platform/hac/source/driver/display/deko.cpp b/platform/hac/source/driver/display/deko.cpp index f3cdbcac2..ad7d3c78e 100644 --- a/platform/hac/source/driver/display/deko.cpp +++ b/platform/hac/source/driver/display/deko.cpp @@ -99,10 +99,10 @@ namespace love return this->framebuffers[this->framebufferSlot].getImage(); } - void deko3d::useProgram(const Shader::Program& program) + void deko3d::useProgram(const dk::Shader& vertex, const dk::Shader& fragment) { // clang-format off - this->commandBuffer.bindShaders(DkStageFlag_GraphicsMask, { &program.vertex.shader, &program.fragment.shader }); + this->commandBuffer.bindShaders(DkStageFlag_GraphicsMask, { &vertex, &fragment }); this->commandBuffer.bindUniformBuffer(DkStage_Vertex, 0, this->uniformBuffer.getGpuAddr(), this->uniformBuffer.getSize()); // clang-format off } @@ -130,6 +130,22 @@ namespace love } } + void deko3d::bindBuffer(BufferUsage usage, DkGpuAddr buffer, size_t size) + { + if (usage == BUFFERUSAGE_VERTEX) + { + this->commandBuffer.bindVtxBuffer(0, buffer, size); + return; + } + else if (usage == BUFFERUSAGE_INDEX) + { + this->commandBuffer.bindIdxBuffer(DkIdxFormat_Uint16, buffer); + } + } + + void deko3d::prepareDraw(GraphicsBase* graphics) + {} + void deko3d::present() { if (!this->swapchain) diff --git a/platform/hac/source/modules/graphics/Graphics.cpp b/platform/hac/source/modules/graphics/Graphics.cpp index 8ca4b5f9d..4a19b8832 100644 --- a/platform/hac/source/modules/graphics/Graphics.cpp +++ b/platform/hac/source/modules/graphics/Graphics.cpp @@ -30,6 +30,59 @@ namespace love } } + void Graphics::captureScreenshot(const ScreenshotInfo& info) + {} + + void Graphics::initCapabilities() + { + // clang-format off + this->capabilities.features[FEATURE_MULTI_RENDER_TARGET_FORMATS] = false; + this->capabilities.features[FEATURE_CLAMP_ZERO] = true; + this->capabilities.features[FEATURE_CLAMP_ONE] = true; + this->capabilities.features[FEATURE_BLEND_MINMAX] = true; + this->capabilities.features[FEATURE_LIGHTEN] = true; + this->capabilities.features[FEATURE_FULL_NPOT] = true; + this->capabilities.features[FEATURE_PIXEL_SHADER_HIGHP] = false; + this->capabilities.features[FEATURE_SHADER_DERIVATIVES] = false; + this->capabilities.features[FEATURE_GLSL3] = false; + this->capabilities.features[FEATURE_GLSL4] = false; + this->capabilities.features[FEATURE_INSTANCING] = false; + this->capabilities.features[FEATURE_TEXEL_BUFFER] = false; + this->capabilities.features[FEATURE_INDEX_BUFFER_32BIT] = false; + this->capabilities.features[FEATURE_COPY_BUFFER_TO_TEXTURE] = false; //< might be possible + this->capabilities.features[FEATURE_COPY_TEXTURE_TO_BUFFER] = false; //< might be possible + this->capabilities.features[FEATURE_COPY_RENDER_TARGET_TO_BUFFER] = false; //< might be possible + this->capabilities.features[FEATURE_MIPMAP_RANGE] = false; + this->capabilities.features[FEATURE_INDIRECT_DRAW] = false; + static_assert(FEATURE_MAX_ENUM == 19, "Graphics::initCapabilities must be updated when adding a new graphics feature!"); + + this->capabilities.limits[LIMIT_POINT_SIZE] = 8.0f; + this->capabilities.limits[LIMIT_TEXTURE_SIZE] = 4096; + this->capabilities.limits[LIMIT_TEXTURE_LAYERS] = 1; + this->capabilities.limits[LIMIT_VOLUME_TEXTURE_SIZE] = 4096; + this->capabilities.limits[LIMIT_CUBE_TEXTURE_SIZE] = 4096; + this->capabilities.limits[LIMIT_TEXEL_BUFFER_SIZE] = 0; + this->capabilities.limits[LIMIT_SHADER_STORAGE_BUFFER_SIZE] = 0; + this->capabilities.limits[LIMIT_THREADGROUPS_X] = 0; + this->capabilities.limits[LIMIT_THREADGROUPS_Y] = 0; + this->capabilities.limits[LIMIT_THREADGROUPS_Z] = 0; + this->capabilities.limits[LIMIT_RENDER_TARGETS] = 1; //< max simultaneous render targets + this->capabilities.limits[LIMIT_TEXTURE_MSAA] = 0; + this->capabilities.limits[LIMIT_ANISOTROPY] = 0; + static_assert(LIMIT_MAX_ENUM == 13, "Graphics::initCapabilities must be updated when adding a new system limit!"); + // clang-format on + + this->capabilities.textureTypes[TEXTURE_2D] = true; + this->capabilities.textureTypes[TEXTURE_VOLUME] = false; + this->capabilities.textureTypes[TEXTURE_CUBE] = true; + this->capabilities.textureTypes[TEXTURE_2D_ARRAY] = false; + } + + void Graphics::setActiveScreen() + { + // gx2.ensureInFrame(); + } + void Graphics::backbufferChanged(int width, int height, int pixelWidth, int pixelHeight, bool stencil, bool depth, int msaa) { @@ -284,4 +337,10 @@ namespace love auto* window = Module::getInstance(M_WINDOW); return this->active && this->created && window != nullptr && window->isOpen(); } + + void Graphics::draw(const DrawIndexedCommand& command) + {} + + void Graphics::draw(const DrawCommand& command) + {} } // namespace love diff --git a/platform/hac/source/modules/graphics/Shader.cpp b/platform/hac/source/modules/graphics/Shader.cpp index 6df025761..af3ca12f3 100644 --- a/platform/hac/source/modules/graphics/Shader.cpp +++ b/platform/hac/source/modules/graphics/Shader.cpp @@ -1,6 +1,15 @@ #include "modules/graphics/Shader.hpp" #include "driver/display/deko.hpp" +#include + +#define SHADERS_DIR "romfs:/shaders/" + +#define DEFAULT_VERTEX_SHADER (SHADERS_DIR "transform_vsh.dksh") +#define DEFAULT_FRAGMENT_SHADER (SHADERS_DIR "color_fsh.dksh") +#define DEFAULT_TEXTURE_SHADER (SHADERS_DIR "texture_fsh.dksh") +#define DEFAULT_VIDEO_SHADER (SHADERS_DIR "video_fsh.dksh") + namespace love { struct DkshHeader @@ -13,12 +22,8 @@ namespace love uint32_t num_programs; }; -#define SHADERS_DIR "romfs:/shaders/" - -#define DEFAULT_VERTEX_SHADER (SHADERS_DIR "transform_vsh.dksh") -#define DEFAULT_FRAGMENT_SHADER (SHADERS_DIR "color_fsh.dksh") -#define DEFAULT_TEXTURE_SHADER (SHADERS_DIR "texture_fsh.dksh") -#define DEFAULT_VIDEO_SHADER (SHADERS_DIR "video_fsh.dksh") + Shader::Shader() + {} Shader::Shader(StandardShader shader) { @@ -54,7 +59,7 @@ namespace love if (Shader::current != this) { Shader::current = this; - d3d.useProgram(this->program); + d3d.useProgram(this->program.vertex.shader, this->program.fragment.shader); ++shaderSwitches; } } diff --git a/platform/hac/source/modules/joystick/JoystickModule.cpp b/platform/hac/source/modules/joystick/JoystickModule.cpp index fd85f0754..dee71c124 100644 --- a/platform/hac/source/modules/joystick/JoystickModule.cpp +++ b/platform/hac/source/modules/joystick/JoystickModule.cpp @@ -1,4 +1,5 @@ #include "modules/joystick/JoystickModule.hpp" +#include "modules/joystick/Joystick.hpp" #include diff --git a/source/modules/joystick/wrap_Joystick.cpp b/source/modules/joystick/wrap_Joystick.cpp index d340d6d49..4da21f819 100644 --- a/source/modules/joystick/wrap_Joystick.cpp +++ b/source/modules/joystick/wrap_Joystick.cpp @@ -432,7 +432,7 @@ static constexpr luaL_Reg functions[] = { }; #if !defined(__WIIU__) -static constexpr luaL_Reg extFunctions[] = {}; +static constexpr std::span extFunctions = {}; #else #include "modules/joystick/kpad/Joystick.hpp"