SpvUtil .java

com.mojang.renderpearl.frontend.shaders.SpvUtil (class): members: getDecorationOffset, DESCRIPTOR_TYPES, spvcErrorString, baseTypeString, crashIfError.

com.mojang.renderpearl.frontend.shadersclass80 linesclient2.5 KB

API Surface (6)

void crashIfError(final int result, final String message)
void throwIfError(final int result, final String message)
String spvcErrorString(final int result)
int getDecorationOffset(final long compiler, final SpvcReflectedResource resource, final int decoration, final IntBuffer returnBuffer)
int resourceType(final UniformType uniformType)
String baseTypeString(final int baseType)

Fields & Constants (1)

DESCRIPTOR_TYPES

String literals (22)

"SPVC_ERROR_INVALID_ARGUMENT"
"SPVC_ERROR_OUT_OF_MEMORY"
"SPVC_ERROR_UNSUPPORTED_SPIRV"
"SPVC_ERROR_INVALID_SPIRV"
"unknown"
"void"
"bool"
"int8"
"uint8"
"int16"
"uint16"
"int32"
"uint32"
"int64"
"uint64"
"atomic_counter"
"struct"
"image"
"sampled_image"
"sampler"
"acceleration_structure"
"UNKNOWN_TYPE"

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SpvUtil.java80 lines · Minecraft 26.3 · verbatim
1
package com.mojang.renderpearl.frontend.shaders;
2
3
import com.mojang.renderpearl.api.pipeline.UniformType;
4
import com.mojang.renderpearl.util.ShaderCompileException;
5
import it.unimi.dsi.fastutil.ints.IntList;
6
import java.nio.IntBuffer;
7
import net.fabricmc.api.EnvType;
8
import net.fabricmc.api.Environment;
9
import org.lwjgl.util.spvc.Spvc;
10
import org.lwjgl.util.spvc.SpvcReflectedResource;
11
12
@Environment(EnvType.CLIENT)
13
public class SpvUtil {
14
	public static final IntList DESCRIPTOR_TYPES = IntList.of(1, 2, 6, 7, 10, 11);
15
16
	public static void crashIfError(final int result, final String message) {
17
		if (result != 0) {
18
			throw new IllegalStateException(message + " (" + spvcErrorString(result) + ")");
19
		}
20
	}
21
22
	public static void throwIfError(final int result, final String message) throws ShaderCompileException {
23
		if (result != 0) {
24
			throw new ShaderCompileException(message + " (" + spvcErrorString(result) + ")");
25
		}
26
	}
27
28
	public static String spvcErrorString(final int result) {
29
		return switch (result) {
30
			case -4 -> "SPVC_ERROR_INVALID_ARGUMENT";
31
			case -3 -> "SPVC_ERROR_OUT_OF_MEMORY";
32
			case -2 -> "SPVC_ERROR_UNSUPPORTED_SPIRV";
33
			case -1 -> "SPVC_ERROR_INVALID_SPIRV";
34
			default -> Integer.toString(result);
35
		};
36
	}
37
38
	public static int getDecorationOffset(final long compiler, final SpvcReflectedResource resource, final int decoration, final IntBuffer returnBuffer) throws ShaderCompileException {
39
		if (!Spvc.spvc_compiler_get_binary_offset_for_decoration(compiler, resource.id(), decoration, returnBuffer)) {
40
			throw new ShaderCompileException("Couldn't find byte offset for location decoration of " + resource.nameString());
41
		} else {
42
			return returnBuffer.get(0);
43
		}
44
	}
45
46
	public static int resourceType(final UniformType uniformType) {
47
		return switch (uniformType) {
48
			case COMBINED_IMAGE_SAMPLER -> 7;
49
			case UNIFORM_BUFFER -> 1;
50
			case TEXEL_BUFFER -> 7;
51
		};
52
	}
53
54
	public static String baseTypeString(final int baseType) {
55
		return switch (baseType) {
56
			case 0 -> "unknown";
57
			case 1 -> "void";
58
			case 2 -> "bool";
59
			case 3 -> "int8";
60
			case 4 -> "uint8";
61
			case 5 -> "int16";
62
			case 6 -> "uint16";
63
			case 7 -> "int32";
64
			case 8 -> "uint32";
65
			case 9 -> "int64";
66
			case 10 -> "uint64";
67
			case 11 -> "atomic_counter";
68
			case 12 -> "fp16";
69
			case 13 -> "fp32";
70
			case 14 -> "fp64";
71
			case 15 -> "struct";
72
			case 16 -> "image";
73
			case 17 -> "sampled_image";
74
			case 18 -> "sampler";
75
			case 19 -> "acceleration_structure";
76
			default -> "UNKNOWN_TYPE";
77
		};
78
	}
79
}
80

Decompiled Minecraft 26.3 source of SpvUtil (com/mojang/renderpearl/frontend/shaders/SpvUtil.java) with Mojang official mappings, stored verbatim on the site.