1.0.0 • Published 5 years ago

bnsh-decoder v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

bnsh-decoder

A decoder for Nintendo Switch BNSH shaders, based on Yuzu's SPIR-V assembler. The decoder emits SPIR-V compatible with WebGPU, Vulkan and D3D12 (through spirv-cross).

In order to extract information such as driver jump tables for bindless textures, reflection data or resource layouts from a BNSH, you can use this Kaitai format specification.

Also note that at the moment for each texture slot, an individual sampler slot is associated since WebGPU doesn't support combined image samplers.

Run BNSH shaders on desktop:

Games like LGPE use bindless textures in mostly every shader.

In order to run these shaders on desktop hardware, you have to resolve the driver jump table which associates the material textures with their relative textures by their sampler names:

function getConstantBufferBindingIndices(slt) {
  let size = slt.length;
  let out = new Uint8Array(size);
  for (let ii = 0; ii < size; ++ii) out[slt[ii]] = ii;
  return out;
};

let strIndexBuffer = new Uint8Array(2 ** 5);
function getSamplerBindingIndices(str, slt, smp) {
  let size = str.length;
  let out = new Uint8Array(size);
  for (let ii = 0; ii < size; ++ii) strIndexBuffer[slt[ii]] = str[ii];
  for (let ii = 0; ii < size; ++ii) out[ii] = strIndexBuffer[smp[ii]];
  return out;
};

Compile for desktop:

This tool was meant to be compiled with Emscripten, however only very little changes in the cmake are required to run this tool on desktop.

Further notes:

The header of the binary shader section is described here