mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-27 15:22:40 +02:00
Implement cmd list
This commit is contained in:
parent
d6dbb59872
commit
1c88d99131
@ -258,5 +258,8 @@ void nvBufferExit(void);
|
|||||||
Result nvBufferCreate(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
Result nvBufferCreate(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
||||||
Result nvBufferCreateRw(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
Result nvBufferCreateRw(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
||||||
void nvBufferFree(NvBuffer* m);
|
void nvBufferFree(NvBuffer* m);
|
||||||
|
|
||||||
void* nvBufferGetAddr(NvBuffer* m);
|
void* nvBufferGetAddr(NvBuffer* m);
|
||||||
|
|
||||||
|
Result nvBufferMakeCpuUncached(NvBuffer* m);
|
||||||
|
Result nvBufferMakeCpuCached(NvBuffer* m);
|
||||||
|
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct NvGpu NvGpu;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
NvBuffer buffer;
|
NvBuffer buffer;
|
||||||
|
size_t num_cmds;
|
||||||
|
size_t max_cmds;
|
||||||
|
NvGpu* parent;
|
||||||
|
iova_t gpu_addr;
|
||||||
} NvCmdList;
|
} NvCmdList;
|
||||||
|
|
||||||
static inline iova_t nvcmdsGetGpuAddr() {
|
Result nvCmdListCreate(NvCmdList* c, NvGpu* parent, size_t max_cmds);
|
||||||
return 0; // TODO
|
void nvCmdListClose(NvCmdList* c);
|
||||||
}
|
|
||||||
|
|
||||||
static inline u64 nvcmdsGetListSize() {
|
iova_t nvCmdListGetGpuAddr(NvCmdList* c);
|
||||||
return 0; // TODO
|
u64 nvCmdListGetListSize(NvCmdList* c);
|
||||||
}
|
|
||||||
|
|
||||||
|
u32* nvCmdListInsert(NvCmdList* c, size_t num_cmds);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "arm/atomics.h"
|
#include "arm/atomics.h"
|
||||||
|
#include "kernel/svc.h"
|
||||||
#include "services/nv.h"
|
#include "services/nv.h"
|
||||||
#include "nvidia/ioctl.h"
|
#include "nvidia/ioctl.h"
|
||||||
#include "nvidia/buffer.h"
|
#include "nvidia/buffer.h"
|
||||||
@ -60,7 +61,8 @@ static Result _nvBufferCreate(NvBuffer* m, size_t size, u32 flags, u32 align, Nv
|
|||||||
m->fd = -1;
|
m->fd = -1;
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
rc = nvioctlNvmap_Alloc(g_nvmap_fd, m->fd, 0, flags | NvBufferFlags_Nintendo, align, kind, m->ptr);
|
rc = nvioctlNvmap_Alloc(
|
||||||
|
g_nvmap_fd, m->fd, 0, flags | NvBufferFlags_Nintendo, align, kind, m->ptr);
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
nvBufferFree(m);
|
nvBufferFree(m);
|
||||||
@ -76,6 +78,14 @@ Result nvBufferCreateRw(NvBuffer* m, size_t size, u32 align, NvBufferKind kind)
|
|||||||
return _nvBufferCreate(m, size, NvBufferFlags_Writable, align, kind);
|
return _nvBufferCreate(m, size, NvBufferFlags_Writable, align, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result nvBufferMakeCpuUncached(NvBuffer* m) {
|
||||||
|
return svcSetMemoryAttribute(m->ptr, m->size, 8, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result nvBufferMakeCpuCached(NvBuffer* m) {
|
||||||
|
return svcSetMemoryAttribute(m->ptr, m->size, 8, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void nvBufferFree(NvBuffer* m)
|
void nvBufferFree(NvBuffer* m)
|
||||||
{
|
{
|
||||||
if (!m->has_init)
|
if (!m->has_init)
|
||||||
|
49
nx/source/nvidia/gpu/cmd_list.c
Normal file
49
nx/source/nvidia/gpu/cmd_list.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <switch.h>
|
||||||
|
|
||||||
|
Result nvCmdListCreate(NvCmdList* c, NvGpu* parent, size_t max_cmds)
|
||||||
|
{
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
rc = nvBufferCreate(&c->buffer, max_cmds * 4, 0x1000, NvBufferKind_Pitch);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
nvBufferMakeCpuUncached(&c->buffer);
|
||||||
|
|
||||||
|
rc = nvAddressSpaceMapBuffer(
|
||||||
|
&parent->addr_space, &c->buffer, NvBufferKind_Pitch, &c->gpu_addr);
|
||||||
|
|
||||||
|
c->num_cmds = 0;
|
||||||
|
c->max_cmds = max_cmds;
|
||||||
|
c->parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nvCmdListClose(NvCmdList* c)
|
||||||
|
{
|
||||||
|
// TODO: nvAddressSpaceUnmapBuffer?
|
||||||
|
nvBufferMakeCpuCached(&c->buffer);
|
||||||
|
nvBufferFree(&c->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
iova_t nvCmdListGetGpuAddr(NvCmdList* c) {
|
||||||
|
return c->gpu_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 nvCmdListGetListSize(NvCmdList* c) {
|
||||||
|
return c->num_cmds * 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32* nvCmdListInsert(NvCmdList* c, size_t num_cmds)
|
||||||
|
{
|
||||||
|
// Has enough space?
|
||||||
|
if ((c->num_cmds + num_cmds) > c->max_cmds)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
u32* ptr = (u32*) nvBufferGetAddr(&c->buffer);
|
||||||
|
ptr += c->num_cmds;
|
||||||
|
|
||||||
|
c->num_cmds += num_cmds;
|
||||||
|
return ptr;
|
||||||
|
}
|
@ -20,7 +20,7 @@ Result nvGpfifoSubmit(NvGpfifo* f, NvCmdList* cmd_list, NvFence* fence_out)
|
|||||||
nvioctl_gpfifo_entry ent;
|
nvioctl_gpfifo_entry ent;
|
||||||
nvioctl_fence fence;
|
nvioctl_fence fence;
|
||||||
|
|
||||||
ent.desc = nvcmdsGetGpuAddr(cmd_list) | (nvcmdsGetListSize(cmd_list) << 42);
|
ent.desc = nvCmdListGetGpuAddr(cmd_list) | (nvCmdListGetListSize(cmd_list) << 42);
|
||||||
|
|
||||||
rc = nvioctlChannel_SubmitGpfifo(
|
rc = nvioctlChannel_SubmitGpfifo(
|
||||||
f->parent->fd, &ent, 1, 0/*flags*/, &fence);
|
f->parent->fd, &ent, 1, 0/*flags*/, &fence);
|
||||||
|
Loading…
Reference in New Issue
Block a user