VulkanConst .java

com.mojang.renderpearl.backend.vulkan.VulkanConst (class): members: formatAspectMask, textureUsageToVk, bufferUsageToVk, toVk. imports: BlendOp, CompareOp.

com.mojang.renderpearl.backend.vulkanclass273 linesclient5.9 KB

API Surface (14)

int textureUsageToVk(final @GpuTexture.Usage int usage, final GpuFormat format)
int bufferUsageToVk(final @GpuBuffer.Usage int usage)
int formatAspectMask(final GpuFormat format)
int toVk(final AddressMode addressMode)
int toVk(final FilterMode filter)
int toVk(final GpuFormat format)
int toVk(final BlendFactor factor)
int toVk(final BlendOp blendOp)
int toVk(final CompareOp op)
int toVk(final PolygonMode polygonMode)
int toVk(final PrimitiveTopology primitiveTopology)
int toVk(final ColorTargetState colorTargetState)
int toVk(final GpuSurface.PresentMode mode)
int toVk(final ShaderType shaderType)

Full Source

VulkanConst.java273 lines · Minecraft 26.3 · verbatim
1
package com.mojang.renderpearl.backend.vulkan;
2
3
import com.mojang.renderpearl.api.GpuFormat;
4
import com.mojang.renderpearl.api.buffers.GpuBuffer;
5
import com.mojang.renderpearl.api.device.GpuSurface;
6
import com.mojang.renderpearl.api.pipeline.BlendFactor;
7
import com.mojang.renderpearl.api.pipeline.BlendOp;
8
import com.mojang.renderpearl.api.pipeline.ColorTargetState;
9
import com.mojang.renderpearl.api.pipeline.CompareOp;
10
import com.mojang.renderpearl.api.pipeline.PolygonMode;
11
import com.mojang.renderpearl.api.pipeline.PrimitiveTopology;
12
import com.mojang.renderpearl.api.pipeline.ShaderType;
13
import com.mojang.renderpearl.api.textures.AddressMode;
14
import com.mojang.renderpearl.api.textures.FilterMode;
15
import com.mojang.renderpearl.api.textures.GpuTexture;
16
import net.fabricmc.api.EnvType;
17
import net.fabricmc.api.Environment;
18
19
@Environment(EnvType.CLIENT)
20
public final class VulkanConst {
21
	public static int textureUsageToVk(final @GpuTexture.Usage int usage, final GpuFormat format) {
22
		int vkUsage = 0;
23
		if ((usage & 8) != 0) {
24
			if (format.hasColorAspect()) {
25
				vkUsage |= 16;
26
			}
27
28
			if (format.hasDepthAspect()) {
29
				vkUsage |= 32;
30
			}
31
		}
32
33
		if ((usage & 4) != 0) {
34
			vkUsage |= 4;
35
		}
36
37
		if ((usage & 1) != 0) {
38
			vkUsage |= 2;
39
		}
40
41
		if ((usage & 2) != 0) {
42
			vkUsage |= 1;
43
		}
44
45
		return vkUsage;
46
	}
47
48
	public static int bufferUsageToVk(final @GpuBuffer.Usage int usage) {
49
		int result = 0;
50
		if ((usage & 8) != 0) {
51
			result |= 2;
52
		}
53
54
		if ((usage & 16) != 0) {
55
			result |= 1;
56
		}
57
58
		if ((usage & 32) != 0) {
59
			result |= 128;
60
		}
61
62
		if ((usage & 64) != 0) {
63
			result |= 64;
64
		}
65
66
		if ((usage & 128) != 0) {
67
			result |= 16;
68
		}
69
70
		if ((usage & 256) != 0) {
71
			result |= 4;
72
		}
73
74
		if ((usage & 512) != 0) {
75
			result |= 256;
76
		}
77
78
		return result;
79
	}
80
81
	public static int formatAspectMask(final GpuFormat format) {
82
		int aspectMask = 0;
83
		if (format.hasColorAspect()) {
84
			aspectMask |= 1;
85
		}
86
87
		if (format.hasDepthAspect()) {
88
			aspectMask |= 2;
89
		}
90
91
		if (format.hasStencilAspect()) {
92
			aspectMask |= 4;
93
		}
94
95
		return aspectMask;
96
	}
97
98
	public static int toVk(final AddressMode addressMode) {
99
		return switch (addressMode) {
100
			case REPEAT -> 0;
101
			case CLAMP_TO_EDGE -> 2;
102
		};
103
	}
104
105
	public static int toVk(final FilterMode filter) {
106
		return switch (filter) {
107
			case NEAREST -> 0;
108
			case LINEAR -> 1;
109
		};
110
	}
111
112
	public static int toVk(final GpuFormat format) {
113
		return switch (format) {
114
			case R8_UNORM -> 9;
115
			case R8_SNORM -> 10;
116
			case RG8_UNORM -> 16;
117
			case RG8_SNORM -> 17;
118
			case RGB8_UNORM -> 23;
119
			case RGB8_SNORM -> 24;
120
			case RGBA8_UNORM -> 37;
121
			case RGBA8_SNORM -> 38;
122
			case R16_UNORM -> 70;
123
			case R16_SNORM -> 71;
124
			case RG16_UNORM -> 77;
125
			case RG16_SNORM -> 78;
126
			case RGB16_UNORM -> 84;
127
			case RGB16_SNORM -> 85;
128
			case RGBA16_UNORM -> 91;
129
			case RGBA16_SNORM -> 92;
130
			case R8_UINT -> 13;
131
			case R8_SINT -> 14;
132
			case RG8_UINT -> 20;
133
			case RG8_SINT -> 21;
134
			case RGB8_UINT -> 27;
135
			case RGB8_SINT -> 28;
136
			case RGBA8_UINT -> 41;
137
			case RGBA8_SINT -> 42;
138
			case R16_UINT -> 74;
139
			case R16_SINT -> 75;
140
			case RG16_UINT -> 81;
141
			case RG16_SINT -> 82;
142
			case RGB16_UINT -> 88;
143
			case RGB16_SINT -> 89;
144
			case RGBA16_UINT -> 95;
145
			case RGBA16_SINT -> 96;
146
			case R32_UINT -> 98;
147
			case R32_SINT -> 99;
148
			case RG32_UINT -> 101;
149
			case RG32_SINT -> 102;
150
			case RGB32_UINT -> 104;
151
			case RGB32_SINT -> 105;
152
			case RGBA32_UINT -> 107;
153
			case RGBA32_SINT -> 108;
154
			case R16_FLOAT -> 76;
155
			case RG16_FLOAT -> 83;
156
			case RGB16_FLOAT -> 90;
157
			case RGBA16_FLOAT -> 97;
158
			case R32_FLOAT -> 100;
159
			case RG32_FLOAT -> 103;
160
			case RGB32_FLOAT -> 106;
161
			case RGBA32_FLOAT -> 109;
162
			case RGB10A2_UNORM -> 64;
163
			case RGB10A2_UINT -> 68;
164
			case RG11B10_FLOAT -> 122;
165
			case D32_FLOAT -> 126;
166
			case D32_FLOAT_S8_UINT -> 130;
167
			case D24_UNORM_S8_UINT -> 129;
168
			case D16_UNORM -> 124;
169
			case S8_UINT -> 127;
170
		};
171
	}
172
173
	public static int toVk(final BlendFactor factor) {
174
		return switch (factor) {
175
			case CONSTANT_ALPHA -> 12;
176
			case CONSTANT_COLOR -> 10;
177
			case ONE_MINUS_CONSTANT_ALPHA -> 13;
178
			case ONE_MINUS_CONSTANT_COLOR -> 11;
179
			case DST_ALPHA -> 8;
180
			case DST_COLOR -> 4;
181
			case ONE -> 1;
182
			case ONE_MINUS_DST_ALPHA -> 9;
183
			case ONE_MINUS_DST_COLOR -> 5;
184
			case ONE_MINUS_SRC_ALPHA -> 7;
185
			case ONE_MINUS_SRC_COLOR -> 3;
186
			case SRC_ALPHA -> 6;
187
			case SRC_ALPHA_SATURATE -> 14;
188
			case SRC_COLOR -> 2;
189
			case ZERO -> 0;
190
		};
191
	}
192
193
	public static int toVk(final BlendOp blendOp) {
194
		return switch (blendOp) {
195
			case ADD -> 0;
196
			case SUBTRACT -> 1;
197
			case REVERSE_SUBTRACT -> 2;
198
			case MIN -> 3;
199
			case MAX -> 4;
200
		};
201
	}
202
203
	public static int toVk(final CompareOp op) {
204
		return switch (op) {
205
			case ALWAYS_PASS -> 7;
206
			case LESS_THAN -> 1;
207
			case LESS_THAN_OR_EQUAL -> 3;
208
			case EQUAL -> 2;
209
			case NOT_EQUAL -> 5;
210
			case GREATER_THAN_OR_EQUAL -> 6;
211
			case GREATER_THAN -> 4;
212
			case NEVER_PASS -> 0;
213
		};
214
	}
215
216
	public static int toVk(final PolygonMode polygonMode) {
217
		return switch (polygonMode) {
218
			case FILL -> 0;
219
			case WIREFRAME -> 1;
220
		};
221
	}
222
223
	public static int toVk(final PrimitiveTopology primitiveTopology) {
224
		return switch (primitiveTopology) {
225
			case LINES -> 3;
226
			case DEBUG_LINES -> 1;
227
			case DEBUG_LINE_STRIP -> 2;
228
			case POINTS -> 0;
229
			case TRIANGLES -> 3;
230
			case TRIANGLE_STRIP -> 4;
231
			case TRIANGLE_FAN -> 5;
232
			case QUADS -> 3;
233
		};
234
	}
235
236
	public static int toVk(final ColorTargetState colorTargetState) {
237
		int result = 0;
238
		if (colorTargetState.writeAlpha()) {
239
			result |= 8;
240
		}
241
242
		if (colorTargetState.writeRed()) {
243
			result |= 1;
244
		}
245
246
		if (colorTargetState.writeGreen()) {
247
			result |= 2;
248
		}
249
250
		if (colorTargetState.writeBlue()) {
251
			result |= 4;
252
		}
253
254
		return result;
255
	}
256
257
	public static int toVk(final GpuSurface.PresentMode mode) {
258
		return switch (mode) {
259
			case IMMEDIATE -> 0;
260
			case MAILBOX -> 1;
261
			case FIFO -> 2;
262
			case FIFO_RELAXED -> 3;
263
		};
264
	}
265
266
	public static int toVk(final ShaderType shaderType) {
267
		return switch (shaderType) {
268
			case VERTEX -> 1;
269
			case FRAGMENT -> 16;
270
		};
271
	}
272
}
273

Decompiled Minecraft 26.3 source of VulkanConst (com/mojang/renderpearl/backend/vulkan/VulkanConst.java) with Mojang official mappings, stored verbatim on the site.