Skip to content

Commit

Permalink
added fix for missing defines
Browse files Browse the repository at this point in the history
  • Loading branch information
codex128 committed Jun 27, 2024
1 parent 60cc523 commit d10bfc6
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private void execute() {
continue;
}
long start = System.currentTimeMillis();
System.out.println(p+" started at "+start+"ms");
if (index == FrameGraph.RENDER_THREAD) {
if (context.isProfilerAvailable()) {
context.getProfiler().fgStep(FgStep.Execute, p.getProfilerName());
Expand All @@ -99,19 +98,10 @@ private void execute() {
}
if (frameGraph.isAsync()) {
// wait until all input resources are available for use before executing
long startMillis = System.currentTimeMillis();
while (!p.allInputsAvailable(context)) {
if (interrupted) {
return;
}
if (System.currentTimeMillis()-startMillis >= threadTimeoutMillis) {
throw new TimeoutException("Execution thread "+index+" timed out on pass "+p);
}
}
p.waitForInputs();
}
p.executeRender(context);
long end = System.currentTimeMillis();
System.out.println(p+" ended at "+end+" and took "+(end-start)+"ms");
if (index == FrameGraph.RENDER_THREAD) {
context.popRenderSettings();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import com.jme3.renderer.framegraph.definitions.ResourceDef;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

/**
* Represents an existing or future resource used for rendering.
Expand All @@ -51,7 +53,7 @@ public class RenderResource <T> {
private int refs = 0;
private boolean survivesRefCull = false;
private boolean undefined = false;
private boolean written = false;
private final AtomicBoolean released = new AtomicBoolean(false);

/**
*
Expand All @@ -76,20 +78,13 @@ public void reference(PassIndex index) {
lifetime.extendTo(index);
refs++;
}
/**
*
* @return
*/
public boolean isAvailable() {
return (!lifetime.isAsync() || !written) && !isVirtual();
}
/**
* Releases this resource from one user.
*
* @return true if this resource is used after the release
*/
public boolean release() {
written = false;
released.compareAndExchange(false, true);
return --refs >= 0;
}

Expand Down Expand Up @@ -150,6 +145,14 @@ public void setUndefined() {
}
undefined = true;
}
/**
* Returns true if this resource always survives cull by reference.
*
* @param survivesRefCull
*/
public void setSurvivesRefCull(boolean survivesRefCull) {
this.survivesRefCull = survivesRefCull;
}

/**
* Gets this resource's producer.
Expand Down Expand Up @@ -215,14 +218,6 @@ public int getIndex() {
public int getNumReferences() {
return refs;
}
/**
* Returns true if this resource always survives cull by reference.
*
* @param survivesRefCull
*/
public void setSurvivesRefCull(boolean survivesRefCull) {
this.survivesRefCull = survivesRefCull;
}

/**
* Returns true if this resource is virtual.
Expand Down Expand Up @@ -279,6 +274,13 @@ public boolean isUndefined() {
public boolean isSurvivesRefCull() {
return survivesRefCull;
}
/**
*
* @return
*/
public boolean isAvailable() {
return released.get();
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import com.jme3.renderer.framegraph.definitions.ResourceDef;
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Texture;
import com.jme3.util.SafeArrayList;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.concurrent.locks.Lock;

/**
* Manages render resource declarations, references, and releases for a framegraph.
Expand Down Expand Up @@ -331,18 +331,20 @@ public boolean isVirtual(ResourceTicket ticket, boolean optional) {
}

/**
* Returns true if the resource at the ticket is available for use.
* Forces the current thread to wait until the resource at the ticket is
* available.
* <p>
* This is used for asynchronous situations.
* A resource becomes available after being released by the declaring pass.
*
* @param ticket
* @return
*/
public boolean isAvailable(ResourceTicket ticket) {
public void wait(ResourceTicket ticket) {
if (ResourceTicket.validate(ticket)) {
return locate(ticket).isAvailable();
RenderResource res = locate(ticket);
while (!res.isAvailable()) {
Thread.onSpinWait();
}
}
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class DeferredPass extends RenderPass implements TechniqueDefLogic {
private final Texture2D[] tileTextures = new Texture2D[2];
private final ColorRGBA ambientColor = new ColorRGBA();
private List<LightProbe> probeList;
private TechniqueDef active;

public DeferredPass() {}
public DeferredPass(boolean tiled) {
Expand Down Expand Up @@ -134,9 +135,9 @@ protected void initialize(FrameGraph frameGraph) {
material = new Material(assetManager, "Common/MatDefs/ShadingCommon/DeferredShading.j3md");
if (defs == null) {
defs = new Defines();
for (TechniqueDef t : material.getMaterialDef().getTechniqueDefs("DeferredPass")) {
defs.config(t);
}
// for (TechniqueDef t : material.getMaterialDef().getTechniqueDefs("DeferredPass")) {
// defs.config(t);
// }
}
}
@Override
Expand All @@ -163,12 +164,14 @@ protected void execute(FGRenderContext context) {
}
material.selectTechnique("DeferredPass", context.getRenderManager());
material.getActiveTechnique().getDef().setLogic(this);
active = material.getActiveTechnique().getDef();
if (active.getDefineNames().length == 0) {
defs.config(active);
}
acquireArrayOrElse("LightTextures", lightTextures, null);
if (lightTextures[0] == null) {
System.out.println("use light buffers");
context.getScreen().render(context.getRenderManager(), material, resources.acquire(lights));
} else {
System.out.println("use light textures");
for (int i = 1; i <= lightTextures.length; i++) {
material.setTexture("LightTex"+i, lightTextures[i-1]);
}
Expand All @@ -188,9 +191,7 @@ protected void cleanup(FrameGraph frameGraph) {}
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
// if the technique def somehow wasn't configured, configure it
if (defines.size() == 0) {
defs.config(material.getActiveTechnique().getDef());
}
System.out.println("using "+(active == material.getActiveTechnique().getDef()));
if (lightTextures[0] == null) {
ColorRGBA amb = resources.acquireOrElse(ambient, null);
if (amb == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,6 @@ public void prepareRender(FGRenderContext context) {
prepare(context);
// set the flag for checking if resources are available
}
/**
*
* @param context
* @return
*/
public boolean allInputsAvailable(FGRenderContext context) {
for (ResourceTicket t : inputs) {
if (!resources.isAvailable(t)) {
return false;
}
}
return true;
}
/**
* Executes the pass.
*
Expand Down Expand Up @@ -299,6 +286,19 @@ protected void referenceOptional(ResourceTicket... tickets) {
}
}

/**
* Forces this thread to wait until all inputs are available for this pass.
*
* @param context
* @return
*/
public boolean waitForInputs() {
for (ResourceTicket t : inputs) {
resources.wait(t);
}
return true;
}

/**
* Acquires a set of resources from a ticket group and stores them in
* the array.
Expand Down
10 changes: 8 additions & 2 deletions jme3-core/src/main/java/com/jme3/shader/DefineList.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public final class DefineList {

private final BitSet isSet;
private final int[] values;
private int[] values;

public DefineList(int numValues) {
if (numValues < 0) {
Expand All @@ -60,7 +60,13 @@ private DefineList(DefineList original) {
}

private void rangeCheck(int id) {
assert 0 <= id && id < values.length;
//assert 0 <= id && id < values.length;
assert id >= 0 : "Define id cannot be less than zero.";
if (id > values.length) {
int[] temp = new int[id+1];
System.arraycopy(values, 0, temp, 0, values.length);
values = temp;
}
}

public boolean isSet(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import com.jme3.util.blockparser.Statement;
import com.jme3.util.clone.Cloner;
import jme3tools.shader.Preprocessor;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static void main(String[] args) {
AppSettings settings = new AppSettings(true);
settings.setWidth(768);
settings.setHeight(768);
settings.setVSync(false);
settings.setFrameRate(-1);
app.setSettings(settings);
app.start();
}
Expand Down Expand Up @@ -83,7 +85,7 @@ public void simpleInitApp() {
};

InstancedNode instancedNode = new InstancedNode("sp");
for (int i = 0;i < 2000;i++) {
for(int i = 0;i < 2000;i++){
PointLight pl = new PointLight();
pl.setColor(colors[i % colors.length]);
pl.setPosition(new Vector3f(FastMath.nextRandomFloat(-5.0f, 5.0f), 0.1f, FastMath.nextRandomFloat(-5.0f, 5.0f)));
Expand Down

0 comments on commit d10bfc6

Please sign in to comment.