mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-10-26 14:24:30 +00:00
Fix SDL compile failure when an image atomic's result is used (#2218)
This commit is contained in:
1 parent
b49d37d827
commit
3389b952d0
2 files changed
+34
No files matched your search
@@ -227,6 +227,11 @@ public final class RwImageStoreExtractor {
|
||||
final String firstArg = GlslAstHelpers.firstArgIdentifier(expr);
|
||||
if (!writtenImages.contains(firstArg)) continue;
|
||||
if (RW_CALLS.contains(fname)) {
|
||||
final ImageDecl d = declared.get(firstArg);
|
||||
if (d != null && !isCallTopLevelStatement(expr)) {
|
||||
edits.add(replaceOf(expr, scalarZeroFor(d.glslType())));
|
||||
continue;
|
||||
}
|
||||
final var stmt = GlslAstHelpers.enclosingOfType(expr, GLSLParser.StatementContext.class);
|
||||
if (stmt != null) edits.add(replaceOf(stmt, ";"));
|
||||
} else if ("imageLoad".equals(fname)) {
|
||||
@@ -378,6 +383,14 @@ public final class RwImageStoreExtractor {
|
||||
return "float";
|
||||
}
|
||||
|
||||
private static String scalarZeroFor(String glslType) {
|
||||
return switch (scalarFor(glslType)) {
|
||||
case "int" -> "0";
|
||||
case "uint" -> "0u";
|
||||
default -> "0.0";
|
||||
};
|
||||
}
|
||||
|
||||
private static String componentVecFor(String glslType) {
|
||||
if (glslType.startsWith("iimage")) return "ivec4";
|
||||
if (glslType.startsWith("uimage")) return "uvec4";
|
||||
|
||||
@@ -50,6 +50,27 @@ class RwImageStoreExtractorTest {
|
||||
"void main() { gl_Position = iris_Vertex; }",
|
||||
"");
|
||||
|
||||
private static final String ATOMIC_RESULT_VSH = String.join("\n",
|
||||
"#version 460 core",
|
||||
"layout(r32i) uniform iimage2D counter_img;",
|
||||
"void main() {",
|
||||
" int previous = imageAtomicCompSwap(counter_img, ivec2(0), 0, -1);",
|
||||
" if (previous == 0) {",
|
||||
" imageAtomicAdd(counter_img, ivec2(1), 1);",
|
||||
" }",
|
||||
" gl_Position = vec4(0.0);",
|
||||
"}",
|
||||
"");
|
||||
|
||||
@Test void raster_keepsVariablesInitializedFromAtomics() {
|
||||
final var result = RwImageStoreExtractor.tryExtract(ATOMIC_RESULT_VSH, PatchShaderType.VERTEX, "prepare");
|
||||
assertNotNull(result);
|
||||
final String stripped = norm(result.strippedSource());
|
||||
assertTrue(stripped.contains("int previous = 0;"), stripped);
|
||||
assertTrue(stripped.contains("if (previous == 0)"), stripped);
|
||||
assertFalse(stripped.contains("imageAtomic"), stripped);
|
||||
}
|
||||
|
||||
@Test void detection_returnsNullWhenNoImageStore() {
|
||||
assertNull(RwImageStoreExtractor.tryExtract(NO_IMAGESTORE_VSH, PatchShaderType.VERTEX, "shadow"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user