BFSHA (File Format): Difference between revisions

From Wexos's Wiki
Jump to navigationJump to search
Line 350: Line 350:
* [[Nintendo Switch Sports]]
* [[Nintendo Switch Sports]]
* Nintendo Switch System BIOS (7.0.0 – 8.1.0)
* Nintendo Switch System BIOS (7.0.0 – 8.1.0)
* [[Nintendo World Championships: NES Edition]]
* [[PAC-MAN 99]]
* [[PAC-MAN 99]]
* [[Paper Mario: The Origami King]]
* [[Paper Mario: The Origami King]]

Revision as of 20:20, 17 July 2024

Under Construction
This article is not finished. Help improve it by adding accurate information or correcting grammar and spelling.

BFSHA (Binary caFe SHader Archive) is a shader file format used on the Nintendo Switch. It is an archive of shaders, and can store multiple shaders, plus its shader variations, allowing usage of generic uber shaders. It is used for rendering BFRES files, and therefore usually stored as an external into an BFRES.

File Format

Header

Offset Type Description
0x00 Char[8] File magic. Always FSHA in ASCII, or 46 53 48 41 20 20 20 20.
0x08 UInt32 Version Number.
0x0C UInt16 Byte-order-mark. FE FF for big endian, FF FE for little endian.
0x0E Byte Alignment shift. 2 raised by this value is the alignment required by this file when loaded into memory.
0x0F Byte Target address size. Size of a pointer in bits. Never set and there remains 0.
0x10 UInt32 File name offset. Points directly to the string, and not to the length unlike all other strings.
0x14 UInt16 A flag which is only used on runtime. One bit sets wether the file is relocated.
0x16 UInt16 Offset to the first section.
0x18 UInt32 Relocation table offset.
0x1C UInt32 Size of the file in bytes.
0x20 Int64 Shader archive offset.
0x28 Int64 String table offset.
0x30 UInt32 Size of string table in bytes.
0x34 Byte[4] Padding.

String Table

The string table is a table where all strings are stored. Each string has first the length written, which is a 16-bit integer, and then the string is stored as a null-terminated string. The string length does not include the null byte, and the 16-bit string length value is always aligned by 2. The string sorting algorithm is unknown.

Offset Type Description
0x00 Char[4] Section magic. Always _STR in ASCII.
0x04 UInt32 Next section offset.
0x08 UInt32 Size of this section in bytes.
0x0C Byte[4] Reserved.
0x10 Int32 Number of strings stored in the string table. The first string is always an empty string ("") and is not included in this count.

Dictionary

A dictionary (sometimes known as DICT) is a common structure used in many Nintendo formats such as BFRES and BNTX. It is used for fast name look-up, in order to find a specific array item by its name. It starts with the following structure:

Offset Type Description
0x00 Char[4] Section magic. Always _DIC in ASCII. Note that in BFRES this magic is set to 00 00 00 00, most likely due to an export error.
0x04 Int32 Number of entries. This does not include the root entry.

After, the entries are specified. The root entry follows first, then all other entries are stored. Each entry has the following structure:

Offset Type Description
0x00 Int32 Ref bit.
0x04 UInt16[2] Child node indices. First the left node, then the right node.
0x08 Int64 Key offset, which points to the key name this entry stores.

Relocation Table

Offset Type Description
0x00 Char[4] Section magic. Always _RLT in ASCII.
0x04 UInt32 Table offset. The offset where this table starts.
0x08 Int32 Number of sections.
0x0C Byte[4] Padding.
Offset Type Description
0x00 Int64 Section pointer, set on runtime.
0x08 UInt32 Section offset.
0x0C UInt32 Section size.
0x10 UInt32 Entry ID.
0x14 UInt32 Number of entries.
Offset Type Description
0x00 UInt32 Entry offset.
0x04 UInt16 Array count.
0x06 Byte Offset count.
0x07 Byte Padding size.

Shader Archive

Offset Type Description
0x00 Int64 Shader archive name offset.
0x08 Int64 Original path offset.
0x10 Int64 Shading model array offset.
0x18 Int64 Shading model dictionary offset.
0x20 Int64 User pointer, set on runtime.
0x28 Int64 Callback pointer, set on runtime.
0x30 Int64 Work memory pointer, set on runtime.
0x38 UInt16 Number of shading models.
0x3A UInt16 Flag. xxxx xxxx ABCD ExFG.
  • A: Shader archive initialized.
  • B: Intermediate shader source is available.
  • C: Shader offline DL.
  • D: Force variation. The option is forced to be changed.
  • E: Binary shader source is available.
  • F: Binary shader source.
  • G: Has shader source.
0x3C Byte[4] Paddding.

Shading Model

Offset Type Description
0x00 Int64 Shading model name offset.
0x08 Int64 Static shader option array offset.
0x10 Int64 Static shader option dictionary offset.
0x18 Int64 Dynamic shader option array offset.
0x20 Int64 Dynamic shader option dictionary offset.
0x28 Int64 Attribute variable array offset.
0x30 Int64 Attribute variable dictionary offset.
0x38 Int64 Sampler variable array offset.
0x40 Int64 Sampler variable dictionary offset.
0x48 Int64 Uniform block variable array offset.
0x50 Int64 Uniform block variable dictionary offset.
0x58 Int64 Uniform variable array offset.
0x60 Int64 Shader program array offset.
0x68 Int64 Key table offset. Points to an array of UInt32s. The count is the same as the number of shader programs.
0x70 Int64 Owning shader archive offset.
0x78 Int64 Shader info offset.
0x80 Int64 BNSH offset.
0x88 Int64 Mutex type offset, set on runtime.
0x90 Int64 User pointer, set on runtime.
0x98 Int64 Call back parameter pointer, set on runtime.
0xA0 Int32 Number of uniform variables.
0xA4 Int32 Default program index.
0xA8 UInt16 Number of static shader options.
0xAA UInt16 Number of dynamic shader options.
0xAC UInt16 Number of shader programs.
0xAE UInt16 Max geometry shader ring buffer output. Maximum number of vertex data output from the geometry shader to the ring buffer.
0xB0 Byte Static key length.
0xB1 Byte Dynamic key length.
0xB2 Byte Number of attribute variables.
0xB3 Byte Number of sampler variables.
0xB4 Byte Number of uniform block variables.
0xB5 Byte Max vertex shader ring buffer output. Maximum number of vertex data output from the vertex shader to the ring buffer.
0xB6 Byte[4] System block indices. Specifies block indices for material, shape, skeleton and shader options.
0xBA Byte[6] Padding.

Shader Option

Offset Type Description
0x00 Int64 Name offset. Points to the name of this shader option.
0x08 Int64 Choice dictionary offset.
0x10 Int64 Choice value array offset. Points to an array of UInt32s.
0x18 Byte Number of choices.
0x19 Byte Default index.
0x1A UInt16 Branch offset. Offset into the uniform block variable.
0x1C Byte Flag. xxxx xxAB.
  • A: Branch.
  • B: Static.
0x1D Byte Key offset. 0 for static option, static key length for dynamic option.
0x1E Byte Index.
0x1F Byte Shift.
0x20 Int32 Mask.
0x24 Byte[4] Padding.

Attribute Variable

Offset Type Description
0x00 Byte Shading model index.
0x01 Byte Shader location.

Sampler Variable

Offset Type Description
0x00 Int64 Alt name offset.
0x08 Byte Index. Index into the shader.
0x09 Byte[7] Padding.

Uniform Block Variable

Offset Type Description
0x00 Int64 Uniform variable array offset.
0x08 Int64 Uniform variable dictionary offset.
0x10 Int64 Default value offset. Only exists for type material.
0x18 Byte Shading model index.
0x19 Byte Type.
ID Name
0x00 None
0x01 Material
0x02 Shape
0x03 Skeleton
0x04 Shader option
0x1A UInt16 Size of this uniform block in bytes.
0x1C UInt16 Number of uniform variables.
0x1E Byte[2] Padding.

Uniform Variable

Offset Type Description
0x00 Int64 Conversion function name offest.
0x08 Int32 Index into the shader.
0x0C UInt16 Data offset, relative to the start of the owning uniform block variable.
0x0E Byte Owning uniform block variable index.
0x0F Byte Padding.

Shader Program

Offset Type Description
0x00 Int64 Sampler table offset. Points to an array of Int32s.
0x08 Int64 Uniform block table. Points to an array of Int32s.
0x10 Int64 Shader variation offset.
0x18 Int64 Owning shading model offset.
0x20 UInt32 Attribute active flag.
0x24 UInt16 Flag. xxxx xxxx xxx'A BCDE.
  • A: Intermediate language.
  • B: Source.
  • C: Binary.
  • D: Initialized.
  • E: Update required.
0x26 UInt16 Number of samplers.
0x28 UInt16 Number of uniform blocks.
0x2A Byte[6] Padding.
Shader Variation

Shader Info

Offset Type Description
0x00 Int64 Sampler table offset.
0x08 Int64 Uniform block table offset.
0x10 Int64 Streamout offset.
0x18 UInt32 Number of streamouts.
0x1C Byte[4] Padding.

Version List

Version Found in
3.0.1
5.0.0
  • Nintendo Switch System BIOS (2.1.0 – 2.3.0)
7.0.0
7.0.2
  • Nintendo Switch System BIOS (6.0.0 – 6.2.0)
7.0.3
8.0.0
9.0.0

Tools

The following tools can handle BFSHA files:

  • (none)