Skip to content

Commit

Permalink
get switch rendering started-ish
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Nov 4, 2024
1 parent 443af2d commit 1aba604
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 40 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions include/driver/display/Renderer.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <array>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions include/driver/graphics/StreamBuffer.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/Object.hpp"

#include "modules/graphics/Resource.hpp"
#include "modules/graphics/vertex.hpp"

#include <type_traits>
Expand Down
3 changes: 3 additions & 0 deletions include/modules/graphics/Shader.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace love
static ShaderBase* current;
static ShaderBase* standardShaders[STANDARD_MAX_ENUM];

ShaderBase()
{}

ShaderBase(StandardShader type);

virtual ~ShaderBase();
Expand Down
1 change: 1 addition & 0 deletions platform/cafe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion platform/hac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions platform/hac/include/driver/display/deko.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 2 additions & 4 deletions platform/hac/include/driver/display/deko3d/CCmdVtxRing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -47,8 +46,7 @@ class CCmdVtxRing
std::pair<void*, DkGpuAddr> 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);
}

/*
Expand Down
29 changes: 17 additions & 12 deletions platform/hac/include/driver/graphics/StreamBuffer.hpp
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -11,32 +14,34 @@ namespace love
public:
StreamBuffer(BufferUsage usage, size_t size) : StreamBufferBase<T>(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<T> StreamBuffer::map(size_t) override
MapInfo<T> map(size_t)
{
MapInfo<T> 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
4 changes: 4 additions & 0 deletions platform/hac/include/modules/graphics/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions platform/hac/include/modules/graphics/Shader.hpp
Original file line number Diff line number Diff line change
@@ -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 <deko3d.hpp>

namespace love
Expand All @@ -30,6 +30,8 @@ namespace love
Stage fragment;
} program;

Shader();

Shader(StandardShader shader);

virtual ~Shader();
Expand Down
44 changes: 44 additions & 0 deletions platform/hac/include/modules/graphics/Texture.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include "modules/graphics/Texture.tcc"
#include "modules/graphics/Volatile.hpp"

#include <deko3d.hpp>

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
Binary file modified platform/hac/romfs/shaders/transform_vsh.dksh
Binary file not shown.
10 changes: 5 additions & 5 deletions platform/hac/source/driver/EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Joystick::GamepadButton> inputs = { Joystick::GamepadButton(input) };
std::vector<JoystickBase::GamepadButton> inputs = { JoystickBase::GamepadButton(input) };

if (joystick->isDown(inputs))
this->sendGamepadButtonEvent(SUBTYPE_GAMEPADDOWN, 0, input);
Expand All @@ -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);
}
}
Expand Down
20 changes: 18 additions & 2 deletions platform/hac/source/driver/display/deko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
59 changes: 59 additions & 0 deletions platform/hac/source/modules/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -284,4 +337,10 @@ namespace love
auto* window = Module::getInstance<Window>(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
Loading

0 comments on commit 1aba604

Please sign in to comment.