Skip to content

Instantly share code, notes, and snippets.

@averne
averne / nvdec_deko3d.c
Last active August 28, 2023 08:50
NVDEC/deko3d interop
// Sample code (untested) for interop between NVDEC and deko3d
// * This only maps the luma plane, as an R8 texture (thus assuming 8-bit data),
// for 10+ bit you would need R16
// * For the chroma plane, the memblock can be shared with the luma plane,
// but you would need a new layout using R8G8 (R16G16 for 10+ bit),
// to adjust the width and height for subsampling,
// and to use (frame->data[1] - frame->data[0]) as offset into the memblock
// * Note that hardware decoding backbuffers are issued (and reused) from a pool,
// thus for efficient use you can cache images/buffer mappings.
// The map handle (ff_tx1_map_get_handle(map)) can be used a key for this.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <switch.h>
#include <deko3d.h>
int main(int argc, char **argv) {
consoleInit(NULL);
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
@averne
averne / dksh.py
Created January 16, 2022 11:49
Parser for deko3d shader files
#!/usr/bin/env python3
# See https://github.com/devkitPro/deko3d/blob/master/source/dksh.h
import os, sys
import ctypes, enum
class DkProgramType(enum.Enum):
Vertex = 0
Fragment = 1
@averne
averne / main.c
Last active November 30, 2021 20:38
#include <switch.h>
void __libnx_initheap(void) { }
void __appInit(void) { }
void __appExit(void) { }
#define DISP_IO_BASE 0x54200000
#define DISP_IO_SIZE (8 * 0x1000)
#define DC_CMD_INT_ENABLE 0xe4
.PHONY: all
CFLAGS := -O2 -g -std=gnu11 -flto
CXXFLAGS := -O2 -g -std=gnu++2a -flto
CC := gcc-10
CXX := g++-10
TARGETS := bench-stbi bench-tj bench-nj bench-tvmr bench-nvjpg
@averne
averne / patching.md
Created August 19, 2020 11:05
Patching nxmtp

Patching nxmtp to receive input on 9.0.0+

On firmwares 9.0.0+, the HID shared memory won't update values for the controller libnx uses, unless it is explicitely specified as supported. The fix is as simple as changing the bitflag passed to nn::hid::SetSupportedNpadStyleSet, from 0x1f to 0x6000001f (see here).

Aarch64 doesn't allow loading immediate values of size bigger than 16-bit unsigned, so we need to split the loading into two instructions:

becomes:

#!/bin/python2
import os, sys
import re
import lib.nxo64 as nxo64
def main(pattern, filename):
f = nxo64.load_nxo(open(filename, 'rb'))
f.binfile.seek(0)
@averne
averne / fs.hpp
Last active February 27, 2020 16:29
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <switch.h>
#include "error.hpp"
#include "utils.hpp"
@averne
averne / main.c
Created February 11, 2020 17:21
Listing dir contents with raw fs calls
#include <stdio.h>
#include <switch.h>
int main(int argc, char **argv) {
consoleInit(NULL);
FsFileSystem sd_fs;
Result rc = fsOpenSdCardFileSystem(&sd_fs);
if (R_FAILED(rc))
printf("Failed to open sd filesystem: %#x", rc);
@averne
averne / .zshenv
Last active June 17, 2020 16:59
Zsh dotfiles
# .zshenv
export ZDOTDIR=~/.config/zsh
export DEVKITPRO=/opt/devkitpro
export DEVKITARM=${DEVKITPRO}/devkitARM
export DEVKITPPC=${DEVKITPRO}/devkitPPC
export PATH=${DEVKITPRO}/tools/bin:$PATH