mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-20 20:32:14 +00:00
Custom images, textures, SSBO, and ShaderPack/ShaderProperties backports
This commit is contained in:
1 parent
6d60477b93
commit
bb52476d27
54 files changed
+2210
-494
No files matched your search
@@ -4,10 +4,12 @@ import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.GlResource;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.coderbot.iris.shaderpack.FilledIndirectPointer;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3i;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL42;
|
||||
import org.lwjgl.opengl.GL43;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
@@ -18,8 +20,8 @@ public final class ComputeProgram extends GlResource {
|
||||
private final ProgramImages images;
|
||||
private Vector3i absoluteWorkGroups;
|
||||
private Vector2f relativeWorkGroups;
|
||||
// private int[] localSize;
|
||||
private final IntBuffer localSizeBuffer;
|
||||
private FilledIndirectPointer indirectPointer;
|
||||
private final IntBuffer localSizeBuffer;
|
||||
private float cachedWidth;
|
||||
private float cachedHeight;
|
||||
private Vector3i cachedWorkGroups;
|
||||
@@ -34,19 +36,21 @@ public final class ComputeProgram extends GlResource {
|
||||
this.images = images;
|
||||
}
|
||||
|
||||
public void setWorkGroupInfo(Vector2f relativeWorkGroups, Vector3i absoluteWorkGroups) {
|
||||
public void setWorkGroupInfo(Vector2f relativeWorkGroups, Vector3i absoluteWorkGroups, FilledIndirectPointer indirectPointer) {
|
||||
this.relativeWorkGroups = relativeWorkGroups;
|
||||
this.absoluteWorkGroups = absoluteWorkGroups;
|
||||
this.indirectPointer = indirectPointer;
|
||||
}
|
||||
|
||||
public Vector3i getWorkGroups(float width, float height) {
|
||||
if (indirectPointer != null) return null;
|
||||
|
||||
if (cachedWidth != width || cachedHeight != height || cachedWorkGroups == null) {
|
||||
this.cachedWidth = width;
|
||||
this.cachedHeight = height;
|
||||
if (this.absoluteWorkGroups != null) {
|
||||
this.cachedWorkGroups = this.absoluteWorkGroups;
|
||||
} else if (relativeWorkGroups != null) {
|
||||
// TODO: This is my best guess at what Optifine does. Can this be confirmed?
|
||||
// Do not use actual localSize here, apparently that's not what we want.
|
||||
this.cachedWorkGroups = new Vector3i((int) Math.ceil(Math.ceil((width * relativeWorkGroups.x)) / localSizeBuffer.get(0)), (int) Math.ceil(Math.ceil((height * relativeWorkGroups.y)) / localSizeBuffer.get(1)), 1);
|
||||
} else {
|
||||
@@ -67,10 +71,15 @@ public final class ComputeProgram extends GlResource {
|
||||
|
||||
public void dispatch(float width, float height) {
|
||||
if (!Iris.getPipelineManager().getPipeline().map(WorldRenderingPipeline::allowConcurrentCompute).orElse(false)) {
|
||||
RenderSystem.memoryBarrier(40);
|
||||
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL43.GL_SHADER_STORAGE_BARRIER_BIT);
|
||||
}
|
||||
|
||||
RenderSystem.dispatchCompute(getWorkGroups(width, height));
|
||||
if (indirectPointer != null) {
|
||||
RenderSystem.bindBuffer(GL43.GL_DISPATCH_INDIRECT_BUFFER, indirectPointer.buffer());
|
||||
RenderSystem.dispatchComputeIndirect(indirectPointer.offset());
|
||||
} else {
|
||||
RenderSystem.dispatchCompute(getWorkGroups(width, height));
|
||||
}
|
||||
}
|
||||
|
||||
public static void unbind() {
|
||||
|
||||
@@ -3,12 +3,14 @@ package net.coderbot.iris.gl.program;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.image.ImageHolder;
|
||||
import net.coderbot.iris.gl.sampler.GlSampler;
|
||||
import net.coderbot.iris.gl.sampler.SamplerHolder;
|
||||
import net.coderbot.iris.gl.shader.GlShader;
|
||||
import net.coderbot.iris.gl.shader.ProgramCreator;
|
||||
import net.coderbot.iris.gl.shader.ShaderType;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import net.coderbot.iris.gl.texture.InternalTextureFormat;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
@@ -106,17 +108,18 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDefaultSampler(IntSupplier sampler, String... names) {
|
||||
return samplers.addDefaultSampler(sampler, names);
|
||||
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
|
||||
return samplers.addDefaultSampler(type, texture, notifier, sampler, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDynamicSampler(IntSupplier sampler, String... names) {
|
||||
return samplers.addDynamicSampler(sampler, names);
|
||||
public boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names) {
|
||||
return samplers.addDynamicSampler(type, texture, sampler, names);
|
||||
}
|
||||
|
||||
public boolean addDynamicSampler(IntSupplier sampler, ValueUpdateNotifier notifier, String... names) {
|
||||
return samplers.addDynamicSampler(sampler, notifier, names);
|
||||
@Override
|
||||
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
|
||||
return samplers.addDynamicSampler(type, texture, notifier, sampler, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,10 +5,13 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.gl.sampler.GlSampler;
|
||||
import net.coderbot.iris.gl.sampler.SamplerBinding;
|
||||
import net.coderbot.iris.gl.sampler.SamplerHolder;
|
||||
import net.coderbot.iris.gl.sampler.SamplerLimits;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import net.coderbot.iris.gl.texture.TextureAccess;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.shaderpack.PackRenderTargetDirectives;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
@@ -73,11 +76,11 @@ public class ProgramSamplers {
|
||||
return new Builder(program, reservedTextureUnits);
|
||||
}
|
||||
|
||||
public static CustomTextureSamplerInterceptor customTextureSamplerInterceptor(SamplerHolder samplerHolder, Object2ObjectMap<String, IntSupplier> customTextureIds) {
|
||||
public static CustomTextureSamplerInterceptor customTextureSamplerInterceptor(SamplerHolder samplerHolder, Object2ObjectMap<String, TextureAccess> customTextureIds) {
|
||||
return customTextureSamplerInterceptor(samplerHolder, customTextureIds, ImmutableSet.of());
|
||||
}
|
||||
|
||||
public static CustomTextureSamplerInterceptor customTextureSamplerInterceptor(SamplerHolder samplerHolder, Object2ObjectMap<String, IntSupplier> customTextureIds, ImmutableSet<Integer> flippedAtLeastOnceSnapshot) {
|
||||
public static CustomTextureSamplerInterceptor customTextureSamplerInterceptor(SamplerHolder samplerHolder, Object2ObjectMap<String, TextureAccess> customTextureIds, ImmutableSet<Integer> flippedAtLeastOnceSnapshot) {
|
||||
return new CustomTextureSamplerInterceptor(samplerHolder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
}
|
||||
|
||||
@@ -145,35 +148,31 @@ public class ProgramSamplers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDefaultSampler(IntSupplier sampler, String... names) {
|
||||
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
|
||||
if (nextUnit != 0) {
|
||||
// TODO: Relax this restriction!
|
||||
throw new IllegalStateException("Texture unit 0 is already used.");
|
||||
}
|
||||
|
||||
return addDynamicSampler(sampler, true, null, names);
|
||||
if (notifier != null) {
|
||||
notifiersToReset.add(notifier);
|
||||
}
|
||||
|
||||
return addDynamicSampler(type, texture, sampler, true, notifier, names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a sampler
|
||||
* @return false if this sampler is not active, true if at least one of the names referred to an active sampler
|
||||
*/
|
||||
@Override
|
||||
public boolean addDynamicSampler(IntSupplier sampler, String... names) {
|
||||
return addDynamicSampler(sampler, false, null, names);
|
||||
public boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names) {
|
||||
return addDynamicSampler(type, texture, sampler, false, null, names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a sampler
|
||||
* @return false if this sampler is not active, true if at least one of the names referred to an active sampler
|
||||
*/
|
||||
@Override
|
||||
public boolean addDynamicSampler(IntSupplier sampler, ValueUpdateNotifier notifier, String... names) {
|
||||
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
|
||||
notifiersToReset.add(notifier);
|
||||
return addDynamicSampler(sampler, false, notifier, names);
|
||||
return addDynamicSampler(type, texture, sampler, false, notifier, names);
|
||||
}
|
||||
|
||||
private boolean addDynamicSampler(IntSupplier sampler, boolean used, ValueUpdateNotifier notifier, String... names) {
|
||||
private boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, boolean used, ValueUpdateNotifier notifier, String... names) {
|
||||
for (String name : names) {
|
||||
int location = RenderSystem.getUniformLocation(program, name);
|
||||
|
||||
@@ -187,8 +186,6 @@ public class ProgramSamplers {
|
||||
throw new IllegalStateException("No more available texture units while activating sampler " + name);
|
||||
}
|
||||
|
||||
//System.out.println("Binding dynamic sampler " + name + " to texture unit " + nextUnit);
|
||||
|
||||
// Set up this sampler uniform to use this particular texture unit.
|
||||
calls.add(new GlUniform1iCall(location, nextUnit));
|
||||
|
||||
@@ -200,7 +197,7 @@ public class ProgramSamplers {
|
||||
return false;
|
||||
}
|
||||
|
||||
samplers.add(new SamplerBinding(nextUnit, sampler, notifier));
|
||||
samplers.add(new SamplerBinding(type, nextUnit, texture, sampler, notifier));
|
||||
|
||||
remainingUnits -= 1;
|
||||
nextUnit += 1;
|
||||
@@ -209,8 +206,6 @@ public class ProgramSamplers {
|
||||
nextUnit += 1;
|
||||
}
|
||||
|
||||
//System.out.println("The next unit is " + nextUnit + ", there are " + remainingUnits + " units remaining.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -221,10 +216,10 @@ public class ProgramSamplers {
|
||||
|
||||
public static final class CustomTextureSamplerInterceptor implements SamplerHolder {
|
||||
private final SamplerHolder samplerHolder;
|
||||
private final Object2ObjectMap<String, IntSupplier> customTextureIds;
|
||||
private final Object2ObjectMap<String, TextureAccess> customTextureIds;
|
||||
private final ImmutableSet<String> deactivatedOverrides;
|
||||
|
||||
private CustomTextureSamplerInterceptor(SamplerHolder samplerHolder, Object2ObjectMap<String, IntSupplier> customTextureIds, ImmutableSet<Integer> flippedAtLeastOnceSnapshot) {
|
||||
private CustomTextureSamplerInterceptor(SamplerHolder samplerHolder, Object2ObjectMap<String, TextureAccess> customTextureIds, ImmutableSet<Integer> flippedAtLeastOnceSnapshot) {
|
||||
this.samplerHolder = samplerHolder;
|
||||
this.customTextureIds = customTextureIds;
|
||||
|
||||
@@ -244,7 +239,7 @@ public class ProgramSamplers {
|
||||
private IntSupplier getOverride(IntSupplier existing, String... names) {
|
||||
for (String name : names) {
|
||||
if (customTextureIds.containsKey(name) && !deactivatedOverrides.contains(name)) {
|
||||
return customTextureIds.get(name);
|
||||
return customTextureIds.get(name).getTextureId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,24 +267,21 @@ public class ProgramSamplers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDefaultSampler(IntSupplier sampler, String... names) {
|
||||
sampler = getOverride(sampler, names);
|
||||
|
||||
return samplerHolder.addDefaultSampler(sampler, names);
|
||||
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
|
||||
texture = getOverride(texture, names);
|
||||
return samplerHolder.addDefaultSampler(type, texture, notifier, sampler, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDynamicSampler(IntSupplier sampler, String... names) {
|
||||
sampler = getOverride(sampler, names);
|
||||
|
||||
return samplerHolder.addDynamicSampler(sampler, names);
|
||||
public boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names) {
|
||||
texture = getOverride(texture, names);
|
||||
return samplerHolder.addDynamicSampler(type, texture, sampler, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDynamicSampler(IntSupplier sampler, ValueUpdateNotifier notifier, String... names) {
|
||||
sampler = getOverride(sampler, names);
|
||||
|
||||
return samplerHolder.addDynamicSampler(sampler, notifier, names);
|
||||
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
|
||||
texture = getOverride(texture, names);
|
||||
return samplerHolder.addDynamicSampler(type, texture, notifier, sampler, names);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user