mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-26 23:23:01 +00:00
Run image atomics natively on Metal where the runtime allows (#2226)
This commit is contained in:
1 parent
5ed1c92590
commit
d056bf6fa7
23 files changed
+637
-48
No files matched your search
@@ -32,6 +32,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.opengl.Display;
|
||||
@@ -75,6 +76,9 @@ public final class FlybyRunner {
|
||||
private boolean jfr;
|
||||
private long recordingId;
|
||||
private final AtomicReference<FlybyRequest> pendingRequest = new AtomicReference<>();
|
||||
private final AtomicReference<String> pendingDimensionPlayer = new AtomicReference<>();
|
||||
private boolean dimensionRequested;
|
||||
private volatile boolean dimensionAbandoned;
|
||||
private FlybyRequest activeRequest;
|
||||
private String[] sceneCommands = NO_COMMANDS;
|
||||
private volatile boolean sceneClearRequested;
|
||||
@@ -197,6 +201,8 @@ public final class FlybyRunner {
|
||||
this.waitForTracy = false;
|
||||
this.waitForFocus = false;
|
||||
this.exitWhenDone = false;
|
||||
this.dimensionRequested = false;
|
||||
this.dimensionAbandoned = false;
|
||||
this.jfr = false;
|
||||
this.armed = false;
|
||||
this.fixedOrigin = null;
|
||||
@@ -263,6 +269,7 @@ public final class FlybyRunner {
|
||||
if (this.waitTicks++ % 100 == 0) LOGGER.info("Flyby waiting for window focus");
|
||||
return;
|
||||
}
|
||||
if (this.awaitingDimension(mc, player)) return;
|
||||
this.begin(mc, player);
|
||||
}
|
||||
case PREPARING -> {
|
||||
@@ -331,6 +338,22 @@ public final class FlybyRunner {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean awaitingDimension(Minecraft mc, EntityClientPlayerMP player) {
|
||||
final Integer dimension = SystemProperties.FLYBY_DIMENSION;
|
||||
if (!this.startedFromProperties || dimension == null || player.dimension == dimension || this.dimensionAbandoned) return false;
|
||||
if (mc.getIntegratedServer() == null || !DimensionManager.isDimensionRegistered(dimension)) {
|
||||
LOGGER.warn("Flyby: {}, staying in dimension {}", mc.getIntegratedServer() == null ? "not singleplayer" : "dimension " + dimension + " is not registered", player.dimension);
|
||||
this.dimensionAbandoned = true;
|
||||
return false;
|
||||
}
|
||||
if (!this.dimensionRequested) {
|
||||
this.dimensionRequested = true;
|
||||
LOGGER.info("Flyby: moving from dimension {} to {}", player.dimension, dimension);
|
||||
this.pendingDimensionPlayer.set(player.getCommandSenderName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void overridePauseOnLostFocus(Minecraft mc) {
|
||||
if (this.pauseOnLostFocusOverridden) return;
|
||||
this.pauseOnLostFocusSaved = mc.gameSettings.pauseOnLostFocus;
|
||||
@@ -600,11 +623,23 @@ public final class FlybyRunner {
|
||||
public void onServerTick(TickEvent.ServerTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END) return;
|
||||
final boolean clear = this.sceneClearRequested;
|
||||
if (!clear && this.pendingRequest.get() == null) return;
|
||||
if (!clear && this.pendingRequest.get() == null && this.pendingDimensionPlayer.get() == null) return;
|
||||
|
||||
final MinecraftServer server = MinecraftServer.getServer();
|
||||
if (server == null) return;
|
||||
|
||||
final String traveller = this.pendingDimensionPlayer.getAndSet(null);
|
||||
if (traveller != null) {
|
||||
this.discardWorldChanges(server);
|
||||
final EntityPlayerMP player = server.getConfigurationManager().func_152612_a(traveller);
|
||||
if (player == null) {
|
||||
LOGGER.warn("Flyby: no server player named '{}', staying in the current dimension", traveller);
|
||||
this.dimensionAbandoned = true;
|
||||
} else {
|
||||
server.getConfigurationManager().transferPlayerToDimension(player, SystemProperties.FLYBY_DIMENSION);
|
||||
}
|
||||
}
|
||||
|
||||
if (clear) {
|
||||
this.sceneClearRequested = false;
|
||||
this.clearScene(server);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.backend.BackendManager;
|
||||
import com.gtnewhorizons.angelica.glsm.GlslTransformUtils;
|
||||
import net.coderbot.iris.gl.image.ImageInformation;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.InternalTextureFormat;
|
||||
@@ -23,6 +24,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public final class RwImageStoreExtractor {
|
||||
|
||||
@@ -45,7 +47,7 @@ public final class RwImageStoreExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
public record Result(String strippedSource, String computeSource, Set<String> writtenImages, RwExtractMode mode, boolean keepsImageAtomics) {}
|
||||
public record Result(String strippedSource, String computeSource, Set<String> writtenImages, RwExtractMode mode, Set<String> atomicImages) {}
|
||||
|
||||
public record ImageDecl(String name, String glslType, String layoutFormat) {}
|
||||
|
||||
@@ -69,8 +71,30 @@ public final class RwImageStoreExtractor {
|
||||
return activeCustomImages;
|
||||
}
|
||||
|
||||
private static volatile Set<String> atomicCustomImages = Set.of();
|
||||
|
||||
public static void setActiveCustomImages(Map<String, ImageInformation> images) {
|
||||
activeCustomImages = (images == null) ? Map.of() : Map.copyOf(images);
|
||||
final TreeSet<String> atomic = new TreeSet<>();
|
||||
if (!activeCustomImages.isEmpty() && !BackendManager.RENDER_BACKEND.supportsComputeImageAtomics()) {
|
||||
for (ImageInformation image : activeCustomImages.values()) {
|
||||
if (image.isRelative()) continue;
|
||||
if (BackendManager.RENDER_BACKEND.supportsComputeImageAtomics(image.width(), image.height(), image.depth())) atomic.add(image.name());
|
||||
}
|
||||
}
|
||||
if (!atomic.equals(atomicCustomImages)) {
|
||||
atomicCustomImages = atomic;
|
||||
TransformPatcher.clearCache();
|
||||
ShaderTransformer.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean supportsAtomics(String image) {
|
||||
return atomicCustomImages.contains(image) || BackendManager.RENDER_BACKEND.supportsComputeImageAtomics();
|
||||
}
|
||||
|
||||
static String atomicCustomImagesKey() {
|
||||
return String.join(",", atomicCustomImages);
|
||||
}
|
||||
|
||||
private static final Set<String> RW_CALLS = Set.of(
|
||||
@@ -119,7 +143,7 @@ public final class RwImageStoreExtractor {
|
||||
applyComputeMutations(tc, writtenImages, declared, mode == RwExtractMode.COMPOSITE_VSH ? quadInputs : chunkAttrsUsed, mode, nonWriteonlyImages);
|
||||
final String compute = buildComputeOutput(root, mode, writtenImages, nonWriteonlyImages, declared, attrs, quadInputs, definesFtransform, null);
|
||||
|
||||
return new Result(stripped, compute, writtenImages, mode, keepsImageAtomics(root, writtenImages));
|
||||
return new Result(stripped, compute, writtenImages, mode, atomicImages(root, writtenImages));
|
||||
}
|
||||
|
||||
public static Result tryExtractVertexReplay(String source) {
|
||||
@@ -142,7 +166,7 @@ public final class RwImageStoreExtractor {
|
||||
|
||||
final String stripped = buildRasterOutputViaSourceSlicing(source, decls, exprs, writtenImages, declared, RwExtractMode.VERTEX_REPLAY);
|
||||
final List<VertexInput> inputs = collectVertexInputs(decls);
|
||||
if (inputs == null) return new Result(stripped, null, writtenImages, RwExtractMode.VERTEX_REPLAY, false);
|
||||
if (inputs == null) return new Result(stripped, null, writtenImages, RwExtractMode.VERTEX_REPLAY, Set.of());
|
||||
|
||||
final List<String> readImages = readOnlyImages(exprs, declared, writtenImages);
|
||||
final Set<String> inputNames = new LinkedHashSet<>();
|
||||
@@ -153,7 +177,7 @@ public final class RwImageStoreExtractor {
|
||||
final ReplayLayout layout = new ReplayLayout(inputs, readImages, replayHeader(inputs, writtenImages, readImages, collectSamplerNames(decls)));
|
||||
final String compute = buildComputeOutput(root, RwExtractMode.VERTEX_REPLAY, writtenImages, nonWriteonlyImages, declared, List.of(), Set.of(), false, layout);
|
||||
|
||||
return new Result(stripped, compute, writtenImages, RwExtractMode.VERTEX_REPLAY, keepsImageAtomics(root, writtenImages));
|
||||
return new Result(stripped, compute, writtenImages, RwExtractMode.VERTEX_REPLAY, atomicImages(root, writtenImages));
|
||||
}
|
||||
|
||||
private record ReplayLayout(List<VertexInput> inputs, List<String> readImages, String header) {}
|
||||
@@ -498,12 +522,15 @@ public final class RwImageStoreExtractor {
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean keepsImageAtomics(GLSLParser.Translation_unitContext computeRoot, Set<String> writtenImages) {
|
||||
private static Set<String> atomicImages(GLSLParser.Translation_unitContext computeRoot, Set<String> writtenImages) {
|
||||
final Set<String> out = new LinkedHashSet<>();
|
||||
for (var expr : GlslAstHelpers.collectAll(computeRoot, GLSLParser.Postfix_expressionContext.class)) {
|
||||
final String fname = GlslAstHelpers.extractCallName(expr);
|
||||
if (fname != null && ATOMIC_CALLS.contains(fname) && writtenImages.contains(GlslAstHelpers.firstArgIdentifier(expr))) return true;
|
||||
if (fname == null || !ATOMIC_CALLS.contains(fname)) continue;
|
||||
final String image = GlslAstHelpers.firstArgIdentifier(expr);
|
||||
if (writtenImages.contains(image)) out.add(image);
|
||||
}
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
|
||||
private static boolean isCallTopLevelStatement(GLSLParser.Postfix_expressionContext expr) {
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -237,7 +238,7 @@ public class ShaderTransformer {
|
||||
final ShaderDiskCache.Key k = ShaderDiskCache.key("iris-transform").str(patch.name());
|
||||
parameters.appendDiskKey(k);
|
||||
k.i(RenderSystem.getMaxGlslVersion()).b(RenderSystem.supportsSSBO()).b(RenderSystem.supportsImageLoadStore())
|
||||
.b(RenderSystem.isGLES()).b(BackendManager.RENDER_BACKEND.isSDLGPU()).b(BackendManager.RENDER_BACKEND.supportsComputeImageAtomics())
|
||||
.b(RenderSystem.isGLES()).b(BackendManager.RENDER_BACKEND.isSDLGPU()).b(BackendManager.RENDER_BACKEND.supportsComputeImageAtomics()).str(RwImageStoreExtractor.atomicCustomImagesKey())
|
||||
.i(maxSupportedHoistVersion);
|
||||
if (enabledRequirements == null) {
|
||||
k.i(-1);
|
||||
@@ -560,16 +561,16 @@ public class ShaderTransformer {
|
||||
artifactsOut.put(shaderType, new StageArtifact(treeHolder[0], formattedShader.length() - printedBody.length()));
|
||||
}
|
||||
}
|
||||
if (BackendManager.RENDER_BACKEND.isSDLGPU()) extractRwImageStores(result, patchType, artifactsOut, BackendManager.RENDER_BACKEND.supportsComputeImageAtomics());
|
||||
if (BackendManager.RENDER_BACKEND.isSDLGPU()) extractRwImageStores(result, patchType, artifactsOut, RwImageStoreExtractor::supportsAtomics);
|
||||
watch.stop();
|
||||
Iris.logger.info("[Load #{}] Transformed shader for {} in {}", Iris.getShaderPackLoadId(), patchType.name(), watch);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void extractRwImageStores(EnumMap<PatchShaderType, String> result, Patch patchType, EnumMap<PatchShaderType, StageArtifact> artifactsOut, boolean computeImageAtomics) {
|
||||
static void extractRwImageStores(EnumMap<PatchShaderType, String> result, Patch patchType, EnumMap<PatchShaderType, StageArtifact> artifactsOut, Predicate<String> imageAtomics) {
|
||||
if (result.containsKey(PatchShaderType.COMPUTE)) return;
|
||||
if (patchType == Patch.ATTRIBUTES) {
|
||||
extractVertexReplay(result, artifactsOut, computeImageAtomics);
|
||||
extractVertexReplay(result, artifactsOut, imageAtomics);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -589,7 +590,7 @@ public class ShaderTransformer {
|
||||
if (artifactsOut != null) artifactsOut.remove(stage);
|
||||
if (patchType != Patch.COMPOSITE && patchType != Patch.CELERITAS_TERRAIN) {
|
||||
Iris.logger.info("[RwImageStoreExtractor] Dropped image writes from {} (written={})", patchType.name(), extracted.writtenImages());
|
||||
} else if (extracted.keepsImageAtomics() && !computeImageAtomics) {
|
||||
} else if (needsUnsupportedAtomics(extracted, imageAtomics)) {
|
||||
Iris.logger.info("[RwImageStoreExtractor] Dropped image writes from {}, they need image atomics this backend cannot run (written={})", patchType.name(), extracted.writtenImages());
|
||||
} else {
|
||||
result.put(PatchShaderType.COMPUTE, extracted.computeSource());
|
||||
@@ -597,7 +598,11 @@ public class ShaderTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
private static void extractVertexReplay(EnumMap<PatchShaderType, String> result, EnumMap<PatchShaderType, StageArtifact> artifactsOut, boolean computeImageAtomics) {
|
||||
private static boolean needsUnsupportedAtomics(RwImageStoreExtractor.Result extracted, Predicate<String> imageAtomics) {
|
||||
return !extracted.atomicImages().stream().allMatch(imageAtomics);
|
||||
}
|
||||
|
||||
private static void extractVertexReplay(EnumMap<PatchShaderType, String> result, EnumMap<PatchShaderType, StageArtifact> artifactsOut, Predicate<String> imageAtomics) {
|
||||
final String fsh = result.get(PatchShaderType.FRAGMENT);
|
||||
final RwImageStoreExtractor.Result fshResult = (fsh != null) ? RwImageStoreExtractor.tryExtract(fsh, PatchShaderType.FRAGMENT, Patch.ATTRIBUTES.name()) : null;
|
||||
if (fshResult != null) {
|
||||
@@ -615,7 +620,7 @@ public class ShaderTransformer {
|
||||
Iris.logger.info("[RwImageStoreExtractor] Dropped vertex image writes from ATTRIBUTES, an input cannot be replayed (written={})", vshResult.writtenImages());
|
||||
return;
|
||||
}
|
||||
if (vshResult.keepsImageAtomics() && !computeImageAtomics) {
|
||||
if (needsUnsupportedAtomics(vshResult, imageAtomics)) {
|
||||
Iris.logger.info("[RwImageStoreExtractor] Dropped vertex image writes from ATTRIBUTES, they need image atomics this backend cannot run (written={})", vshResult.writtenImages());
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ class CompositeVertexWriteExtractionTest {
|
||||
final EnumMap<PatchShaderType, String> result = new EnumMap<>(transformed);
|
||||
result.remove(PatchShaderType.COMPUTE);
|
||||
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, null, true);
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, null, image -> true);
|
||||
|
||||
final String compute = result.get(PatchShaderType.COMPUTE);
|
||||
assertEquals(RwImageStoreExtractor.RwExtractMode.COMPOSITE_VSH, RwImageStoreExtractor.parseSentinel(compute));
|
||||
@@ -77,7 +77,7 @@ class CompositeVertexWriteExtractionTest {
|
||||
result.remove(PatchShaderType.COMPUTE);
|
||||
|
||||
// The CompSwap's result is used, so it stays a real atomic, which native Metal cannot bind
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, null, false);
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, null, image -> false);
|
||||
|
||||
assertFalse(result.containsKey(PatchShaderType.COMPUTE));
|
||||
assertFalse(result.get(PatchShaderType.VERTEX).contains("imageAtomic"), result.get(PatchShaderType.VERTEX));
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.backend.BackendManager;
|
||||
import com.gtnewhorizons.angelica.glsm.backend.RenderBackend;
|
||||
import com.gtnewhorizons.angelica.glsm.testutil.Reflect;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.InternalTextureFormat;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.PixelFormat;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.PixelType;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureType;
|
||||
import net.coderbot.iris.gl.image.ImageInformation;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.AdditionalAnswers.delegatesTo;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class CustomImageAtomicsTest {
|
||||
|
||||
private RenderBackend original;
|
||||
private RenderBackend backend;
|
||||
|
||||
@BeforeEach
|
||||
void installBackend() {
|
||||
original = BackendManager.RENDER_BACKEND;
|
||||
backend = mock(RenderBackend.class, delegatesTo(original));
|
||||
doAnswer(call -> call.<Integer>getArgument(0) == 40 && call.<Integer>getArgument(1) == 10 && call.<Integer>getArgument(2) == 1).when(backend).supportsComputeImageAtomics(anyInt(), anyInt(), anyInt());
|
||||
Reflect.setStaticFinal(BackendManager.class, "RENDER_BACKEND", RenderBackend.class, backend);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void restoreBackend() {
|
||||
Reflect.setStaticFinal(BackendManager.class, "RENDER_BACKEND", RenderBackend.class, original);
|
||||
RwImageStoreExtractor.setActiveCustomImages(null);
|
||||
}
|
||||
|
||||
private static ImageInformation image(String name, int width, int height, boolean relative) {
|
||||
return new ImageInformation(name, name + "_sampler", TextureType.TEXTURE_2D, PixelFormat.RED_INTEGER, InternalTextureFormat.R32I, PixelType.INT, width, height, 1, false, relative, relative ? 1.0f : 0.0f, relative ? 1.0f : 0.0f);
|
||||
}
|
||||
|
||||
private static Map<String, ImageInformation> images() {
|
||||
return Map.of("small_img", image("small_img", 40, 10, false), "large_img", image("large_img", 64, 64, false), "screen_img", image("screen_img", 40, 10, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyImagesTheBackendAcceptsBySizeKeepAtomics() {
|
||||
doReturn(false).when(backend).supportsComputeImageAtomics();
|
||||
RwImageStoreExtractor.setActiveCustomImages(images());
|
||||
|
||||
assertTrue(RwImageStoreExtractor.supportsAtomics("small_img"));
|
||||
assertFalse(RwImageStoreExtractor.supportsAtomics("large_img"));
|
||||
assertFalse(RwImageStoreExtractor.supportsAtomics("screen_img"));
|
||||
assertFalse(RwImageStoreExtractor.supportsAtomics("colortex0"));
|
||||
assertEquals("small_img", RwImageStoreExtractor.atomicCustomImagesKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void backendWithImageAtomicsEverywhereNeedsNoPerImageList() {
|
||||
doReturn(true).when(backend).supportsComputeImageAtomics();
|
||||
RwImageStoreExtractor.setActiveCustomImages(images());
|
||||
|
||||
assertTrue(RwImageStoreExtractor.supportsAtomics("small_img"));
|
||||
assertTrue(RwImageStoreExtractor.supportsAtomics("large_img"));
|
||||
assertTrue(RwImageStoreExtractor.supportsAtomics("screen_img"));
|
||||
assertTrue(RwImageStoreExtractor.supportsAtomics("colortex0"));
|
||||
assertEquals("", RwImageStoreExtractor.atomicCustomImagesKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearingTheImagesClearsTheList() {
|
||||
doReturn(false).when(backend).supportsComputeImageAtomics();
|
||||
RwImageStoreExtractor.setActiveCustomImages(images());
|
||||
RwImageStoreExtractor.setActiveCustomImages(null);
|
||||
|
||||
assertFalse(RwImageStoreExtractor.supportsAtomics("small_img"));
|
||||
assertEquals("", RwImageStoreExtractor.atomicCustomImagesKey());
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ class ShaderTransformerTest {
|
||||
|
||||
final EnumMap<PatchShaderType, String> result = new EnumMap<>(out);
|
||||
final String fragmentBefore = result.get(PatchShaderType.FRAGMENT);
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, artifacts, true);
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, artifacts, image -> true);
|
||||
|
||||
assertNotNull(result.get(PatchShaderType.COMPUTE), "fixture must actually exercise the extraction");
|
||||
assertFalse(fragmentBefore.equals(result.get(PatchShaderType.FRAGMENT)), "fixture must actually rewrite the fragment stage");
|
||||
@@ -263,7 +263,7 @@ class ShaderTransformerTest {
|
||||
assertNotNull(out);
|
||||
|
||||
final EnumMap<PatchShaderType, String> result = new EnumMap<>(out);
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, artifacts, true);
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.COMPOSITE, artifacts, image -> true);
|
||||
|
||||
assertFalse(artifacts.isEmpty(), "fixture must leave at least one artifact to check");
|
||||
for (Map.Entry<PatchShaderType, ShaderTransformer.StageArtifact> e : artifacts.entrySet()) {
|
||||
|
||||
@@ -237,7 +237,7 @@ class VertexReplayExtractionTest {
|
||||
void atomicReplayIsDroppedWithoutBackendSupport() {
|
||||
final EnumMap<PatchShaderType, String> atomic = new EnumMap<>(PatchShaderType.class);
|
||||
atomic.put(PatchShaderType.VERTEX, TransformPatcher.patchAttributes(CRYSTAL_VERTEX, null, FRAGMENT, TEX_LM).get(PatchShaderType.VERTEX));
|
||||
ShaderTransformer.extractRwImageStores(atomic, Patch.ATTRIBUTES, null, false);
|
||||
ShaderTransformer.extractRwImageStores(atomic, Patch.ATTRIBUTES, null, image -> false);
|
||||
assertFalse(atomic.containsKey(PatchShaderType.COMPUTE));
|
||||
assertFalse(atomic.get(PatchShaderType.VERTEX).contains("imageAtomic"), atomic.get(PatchShaderType.VERTEX));
|
||||
|
||||
@@ -251,10 +251,25 @@ class VertexReplayExtractionTest {
|
||||
gl_Position = iris_Vertex;
|
||||
}
|
||||
""");
|
||||
ShaderTransformer.extractRwImageStores(plain, Patch.ATTRIBUTES, null, false);
|
||||
ShaderTransformer.extractRwImageStores(plain, Patch.ATTRIBUTES, null, image -> false);
|
||||
assertTrue(plain.containsKey(PatchShaderType.COMPUTE), "plain stores need no atomics, so the replay stays");
|
||||
}
|
||||
|
||||
@Test
|
||||
void atomicReplayFollowsTheImageItWrites() {
|
||||
final String vertex = TransformPatcher.patchAttributes(CRYSTAL_VERTEX, null, FRAGMENT, TEX_LM).get(PatchShaderType.VERTEX);
|
||||
|
||||
final EnumMap<PatchShaderType, String> supported = new EnumMap<>(PatchShaderType.class);
|
||||
supported.put(PatchShaderType.VERTEX, vertex);
|
||||
ShaderTransformer.extractRwImageStores(supported, Patch.ATTRIBUTES, null, "endcrystal_img"::equals);
|
||||
assertTrue(supported.containsKey(PatchShaderType.COMPUTE));
|
||||
|
||||
final EnumMap<PatchShaderType, String> unsupported = new EnumMap<>(PatchShaderType.class);
|
||||
unsupported.put(PatchShaderType.VERTEX, vertex);
|
||||
ShaderTransformer.extractRwImageStores(unsupported, Patch.ATTRIBUTES, null, "voxel_img"::equals);
|
||||
assertFalse(unsupported.containsKey(PatchShaderType.COMPUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matrixInputIsNotReplayed() {
|
||||
final RwImageStoreExtractor.Result result = RwImageStoreExtractor.tryExtractVertexReplay("""
|
||||
@@ -293,7 +308,7 @@ class VertexReplayExtractionTest {
|
||||
}
|
||||
""");
|
||||
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.ATTRIBUTES, null, true);
|
||||
ShaderTransformer.extractRwImageStores(result, Patch.ATTRIBUTES, null, image -> true);
|
||||
|
||||
assertNotNull(result.get(PatchShaderType.COMPUTE));
|
||||
assertFalse(result.get(PatchShaderType.VERTEX).contains("imageStore"));
|
||||
|
||||
Reference in new issue
Block a user