Skip to content

Commit

Permalink
switch texture work
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Nov 8, 2024
1 parent 00733f1 commit f06000d
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 72 deletions.
18 changes: 12 additions & 6 deletions platform/hac/include/driver/display/deko.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ namespace love
}
}

dk::Device& getDevice()
dk::Device getDevice()
{
return this->device;
}

dk::Queue& getQueue(QueueType type)
dk::Queue getQueue(QueueType type)
{
switch (type)
{
Expand All @@ -121,8 +121,14 @@ namespace love

void ensureInFrame();

void setVertexAttributes(bool isTexture);

void bindTextureToUnit(TextureBase* texture, int unit);

void bindTextureToUnit(DkResHandle texture, int unit);

void drawIndexed(DkPrimitive primitive, uint32_t indexCount, uint32_t indexOffset,
uint32_t instanceCount, bool isTexture);
uint32_t instanceCount);

void draw(DkPrimitive primitive, uint32_t vertexCount, uint32_t firstVertex);

Expand Down Expand Up @@ -227,8 +233,7 @@ namespace love
static constexpr int RENDERTARGET_USE_FLAGS =
DkImageFlags_UsageRender | DkImageFlags_UsagePresent | DkImageFlags_HwCompression;

static constexpr int COMMAND_SIZE = 0x100000;
static constexpr int VERTEX_COMMAND_SIZE = 0x100000;
static constexpr int COMMAND_SIZE = 0x100000;

void createFramebuffers();

Expand All @@ -243,12 +248,13 @@ namespace love
dk::DepthStencilState depthStencil;

dk::Image* boundFramebuffer;
bool descriptorsDirty;
} context;

struct Transform
{
glm::mat4 projection;
glm::mat4 modelView;
glm::mat4 projection;
} transform;

static constexpr auto TRANSFORM_SIZE = sizeof(Transform);
Expand Down
2 changes: 1 addition & 1 deletion platform/hac/include/driver/graphics/Attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace love
};
// clang-format on

static void getAttributes(const bool isTexture, Attributes& out)
static void getAttributes(bool isTexture, Attributes& out)
{
if (!isTexture)
{
Expand Down
2 changes: 1 addition & 1 deletion platform/hac/include/driver/graphics/BitAlloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace love
return index;
}

void reset(uint32_t handle)
void deallocate(uint32_t handle)
{
auto index = 0;

Expand Down
41 changes: 21 additions & 20 deletions platform/hac/source/driver/EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace love
{
EventQueue::EventQueue() : EventQueueBase<EventQueue>()
{
for (int index = 0; index < 0x08; index++)
{
auto player = HidNpadIdType(HidNpadIdType_No1 + index);
hidAcquireNpadStyleSetUpdateEventHandle(player, &this->padStyleUpdates[index], true);
}
// for (int index = 0; index < 0x08; index++)
// {
// auto player = HidNpadIdType(HidNpadIdType_No1 + index);
// hidAcquireNpadStyleSetUpdateEventHandle(player, &this->padStyleUpdates[index], true);
// }
}

EventQueue::~EventQueue()
{
for (int index = 0; index < 0x08; index++)
eventClose(&this->padStyleUpdates[index]);
// for (int index = 0; index < 0x08; index++)
// eventClose(&this->padStyleUpdates[index]);
}

static void checkFocus()
Expand Down Expand Up @@ -74,16 +74,16 @@ namespace love

int current = JOYSTICK_MODULE()->getJoystickCount();

for (int index = 0; index < 0x08; index++)
{
if (R_SUCCEEDED(eventWait(&this->padStyleUpdates[index], 0)))
{
int newCount = JOYSTICK_MODULE()->getJoystickCount();
// for (int index = 0; index < 0x08; index++)
// {
// if (R_SUCCEEDED(eventWait(&this->padStyleUpdates[index], 0)))
// {
// int newCount = JOYSTICK_MODULE()->getJoystickCount();

if (newCount != current)
this->sendJoystickStatus(newCount > current, index);
}
}
// if (newCount != current)
// this->sendJoystickStatus(newCount > current, index);
// }
// }

for (int index = 0; index < current; index++)
{
Expand All @@ -92,25 +92,26 @@ namespace love
if (joystick == nullptr)
continue;

const auto id = joystick->getID();
joystick->update();

for (int input = 0; input < JoystickBase::GAMEPAD_BUTTON_MAX_ENUM; input++)
{
std::vector<JoystickBase::GamepadButton> inputs = { JoystickBase::GamepadButton(input) };

if (joystick->isDown(inputs))
this->sendGamepadButtonEvent(SUBTYPE_GAMEPADDOWN, 0, input);
this->sendGamepadButtonEvent(SUBTYPE_GAMEPADDOWN, id, input);

if (joystick->isUp(inputs))
this->sendGamepadButtonEvent(SUBTYPE_GAMEPADUP, 0, input);
this->sendGamepadButtonEvent(SUBTYPE_GAMEPADUP, id, input);
}

for (int input = 0; input < JoystickBase::GAMEPAD_AXIS_MAX_ENUM; input++)
{
if (joystick->isAxisChanged(JoystickBase::GamepadAxis(input)))
{
float value = joystick->getAxis(JoystickBase::GamepadAxis(input));
this->sendGamepadAxisEvent(0, input, value);
this->sendGamepadAxisEvent(id, input, value);
}
}

Expand All @@ -120,7 +121,7 @@ namespace love
continue;

auto data = joystick->getSensorData(Sensor::SensorType(input));
this->sendGamepadSensorEvent(0, input, data);
this->sendGamepadSensorEvent(id, input, data);
}
}
}
Expand Down
65 changes: 49 additions & 16 deletions platform/hac/source/driver/display/deko.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "driver/display/deko.hpp"
#include "driver/graphics/Attributes.hpp"

#include "modules/graphics/Texture.hpp"

namespace love
{
deko3d::deko3d() :
Expand All @@ -12,8 +14,8 @@ namespace love
images(CMemPool(this->device, GPU_USE_FLAGS, GPU_POOL_SIZE)),
data(CMemPool(this->device, CPU_USE_FLAGS, CPU_POOL_SIZE)),
code(CMemPool(this->device, SHADER_USE_FLAGS, SHADER_POOL_SIZE)),
framebufferSlot(-1),
context {}
context {},
framebufferSlot(-1)
{}

void deko3d::initialize()
Expand All @@ -37,6 +39,12 @@ namespace love

this->context.color.setBlendEnable(0, true);

this->imageSet.allocate(this->data);
this->imageSet.bindForImages(this->commandBuffer);

this->samplerSet.allocate(this->data);
this->samplerSet.bindForSamplers(this->commandBuffer);

this->initialized = true;
}

Expand Down Expand Up @@ -80,6 +88,7 @@ namespace love
this->commandBuffer.clear();
this->swapchain.destroy();

this->context.boundFramebuffer = nullptr;
for (auto& framebuffer : this->framebuffers)
framebuffer.destroy();

Expand All @@ -90,6 +99,9 @@ namespace love
{
if (!this->inFrame)
{
if (!this->swapchain)
return;

if (this->framebufferSlot < 0)
this->framebufferSlot = this->mainQueue.acquireImage(this->swapchain);

Expand Down Expand Up @@ -132,12 +144,14 @@ namespace love
{
if (registering)
{
const auto handle = this->textureHandles.allocate();
const auto index = this->textureHandles.allocate();
const auto handle = dkMakeTextureHandle(index, index);
texture->setHandleData(handle);

return;
}

this->textureHandles.reset((DkResHandle)texture->getHandle());
this->textureHandles.deallocate((uint32_t)texture->getHandle());
}

void deko3d::bindFramebuffer(dk::Image& framebuffer)
Expand Down Expand Up @@ -170,25 +184,42 @@ namespace love
this->commandBuffer.bindIdxBuffer(DkIdxFormat_Uint16, buffer);
}

void deko3d::drawIndexed(DkPrimitive primitive, uint32_t indexCount, uint32_t indexOffset, uint32_t instanceCount, bool isTexture)
void deko3d::setVertexAttributes(bool isTexture)
{
vertex::Attributes attributes {};
vertex::getAttributes(isTexture, attributes);

this->commandBuffer.bindVtxAttribState(attributes.attributeState);
this->commandBuffer.bindVtxBufferState(attributes.bufferState);
}

this->commandBuffer.drawIndexed(primitive, indexCount, instanceCount, indexOffset, 0, 0);
void deko3d::bindTextureToUnit(TextureBase* texture, int unit)
{
if (!texture)
return;

const auto handle = (DkResHandle)texture->getHandle();
this->bindTextureToUnit(handle, unit);
}

void deko3d::draw(DkPrimitive primitive, uint32_t vertexCount, uint32_t firstVertex)
void deko3d::bindTextureToUnit(DkResHandle texture, int unit)
{
vertex::Attributes attributes {};
vertex::getAttributes(false, attributes);
if (this->context.descriptorsDirty)
{
this->commandBuffer.barrier(DkBarrier_Primitives, DkInvalidateFlags_Descriptors);
this->context.descriptorsDirty = false;
}

this->commandBuffer.bindVtxAttribState(attributes.attributeState);
this->commandBuffer.bindVtxBufferState(attributes.bufferState);
this->commandBuffer.bindTextures(DkStage_Fragment, 0, { texture });
}

void deko3d::drawIndexed(DkPrimitive primitive, uint32_t indexCount, uint32_t indexOffset, uint32_t instanceCount)
{
this->commandBuffer.drawIndexed(primitive, indexCount, instanceCount, indexOffset, 0, 0);
}

void deko3d::draw(DkPrimitive primitive, uint32_t vertexCount, uint32_t firstVertex)
{
this->commandBuffer.draw(primitive, vertexCount, 1, firstVertex, 0);
}

Expand Down Expand Up @@ -299,6 +330,9 @@ namespace love
void deko3d::setSamplerState(TextureBase* texture, const SamplerState&state)
{
auto* sampler = (dk::Sampler*)texture->getSamplerHandle();
auto descriptor = ((Texture*)texture)->getDescriptorHandle();
auto samplerDescriptor = ((Texture*)texture)->getSamplerDescriptorHandle();

auto index = -1;

if (!this->textureHandles.find((uint32_t)texture->getHandle(), index))
Expand Down Expand Up @@ -328,13 +362,12 @@ namespace love

sampler->setWrapMode(wrapU, wrapV, wrapW);

// const auto descriptor = ((Texture*)texture)->getDescriptorHandle();
// this->imageSet.update(this->commandBuffer, index, descriptor);
this->imageSet.update(this->commandBuffer, index, descriptor);

// auto samplerDescriptor = ((Texture*)texture)->getSamplerDescriptorHandle();
// samplerDescriptor.initialize(*sampler);
samplerDescriptor.initialize(*sampler);

// this->samplerSet.update(this->commandBuffer, index, samplerDescriptor);
this->samplerSet.update(this->commandBuffer, index, samplerDescriptor);
this->context.descriptorsDirty = true;
}

static DkScissor dkScissorFromRect(const Rect& rect)
Expand Down
9 changes: 7 additions & 2 deletions platform/hac/source/modules/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,22 +404,27 @@ namespace love
void Graphics::draw(const DrawIndexedCommand& command)
{
d3d.prepareDraw(this);
d3d.setVertexAttributes(command.texture != nullptr);
d3d.bindTextureToUnit(command.texture, 0);
d3d.setCullMode(command.cullMode);

DkPrimitive primitive;
deko3d::getConstant(command.primitiveType, primitive);

const auto indexCount = command.indexCount;
const auto offset = command.indexBufferOffset;
const auto instanceCount = command.instanceCount;
const auto isTexture = command.texture != nullptr;

d3d.drawIndexed(primitive, indexCount, offset, instanceCount, isTexture);
d3d.drawIndexed(primitive, indexCount, offset, instanceCount);
++drawCalls;
}

void Graphics::draw(const DrawCommand& command)
{
d3d.prepareDraw(this);
d3d.setVertexAttributes(command.texture != nullptr);
d3d.bindTextureToUnit(command.texture, 0);
d3d.setCullMode(command.cullMode);

DkPrimitive primitive;
deko3d::getConstant(command.primitiveType, primitive);
Expand Down
Loading

0 comments on commit f06000d

Please sign in to comment.