Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wip implementation for passing chunk state fo wgpu layer #5125

Draft
wants to merge 16 commits into
base: feature/wgpu-rendering-refactor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/terasology-metrics.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ tasks.withType<Test> {
// If false, the outputs are still collected and visible in the test report, but they don't spam the console.
testLogging.showStandardStreams = false
reports {
junitXml.isEnabled = true
junitXml.required.set(true)
}
jvmArgs("-Xms512m", "-Xmx1024m")

Expand Down
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ apply(from = "$rootDir/config/gradle/publish.gradle")
// Handle some logic related to where what is
configure<SourceSetContainer> {
main {
java.outputDir = buildDir.resolve("classes")
java.destinationDirectory.set(buildDir.resolve("classes"))
}
test {
java.outputDir = buildDir.resolve("testClasses")
java.destinationDirectory.set(buildDir.resolve("testClasses"))
}
}

Expand Down
29 changes: 23 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import static org.gradle.internal.logging.text.StyledTextOutput.Style

// Test for right version of Java in use for running this script
assert org.gradle.api.JavaVersion.current().isJava11Compatible()
if(!(JavaVersion.current() == JavaVersion.VERSION_11)) {
if (!(JavaVersion.current() == JavaVersion.VERSION_11)) {
def out = services.get(StyledTextOutputFactory).create("an-ouput")
out.withStyle(Style.FailureHeader).println("""
WARNING: Compiling with a JDK of not version 11. While some other Javas may be
Expand All @@ -79,6 +79,7 @@ ext {
subDirLibs = 'libs'

LwjglVersion = '3.3.1'
rustCoreVersion = '0.0.1'
}


Expand All @@ -95,7 +96,7 @@ configurations {
dependencies {
// For the "natives" configuration make it depend on the native files from LWJGL
natives platform("org.lwjgl:lwjgl-bom:$LwjglVersion")
["natives-linux","natives-windows","natives-macos"].forEach {
["natives-linux", "natives-windows", "natives-macos"].forEach {
natives "org.lwjgl:lwjgl::$it"
natives "org.lwjgl:lwjgl-assimp::$it"
natives "org.lwjgl:lwjgl-glfw::$it"
Expand All @@ -114,6 +115,11 @@ dependencies {
// Natives for JNBullet
natives group: 'org.terasology.jnbullet', name: 'JNBullet', version: '1.0.2', ext: 'zip'

// Natives for core
natives(group: 'org.terasology.rust', name: 'core-rust', version: rustCoreVersion){
transitive = true
}

}

task extractWindowsNatives(type: Copy) {
Expand Down Expand Up @@ -151,22 +157,33 @@ task extractJNLuaNatives(type: Copy) {
into("$dirNatives")
}

task extractNativeBulletNatives(type:Copy) {
task extractNativeBulletNatives(type: Copy) {
description = "Extracts the JNBullet natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('JNBullet') ? zipTree(it) : [] }
}
into("$dirNatives")
}

task extractRustCoreNatives(type:Copy) {
description = "Extracts the JNBullet natives from the downloaded zip"
from configurations.natives
from {
configurations.natives.collect { it.getName().contains('core-rust') ? zipTree(it) : [] }
}
into ("$dirNatives")
}



task extractNatives {
description = "Extracts all the native lwjgl libraries from the downloaded zip"
dependsOn extractWindowsNatives
dependsOn extractLinuxNatives
dependsOn extractMacOSXNatives
dependsOn extractJNLuaNatives
dependsOn extractNativeBulletNatives
dependsOn extractRustCoreNatives
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -195,8 +212,8 @@ clean.doLast {
allprojects {
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("org.terasology.engine:engine") because "we have sources!" with project(":engine")
substitute module("org.terasology.engine:engine-tests") because "we have sources!" with project(":engine-tests")
substitute module("org.terasology.engine:engine") using project(":engine") because "we have sources!"
substitute module("org.terasology.engine:engine-tests") using project(":engine-tests") because "we have sources!"
}
}
}
Expand All @@ -207,7 +224,7 @@ project(":modules").subprojects.forEach { proj ->
project(":modules").subprojects {
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("org.terasology.modules:${proj.name}") because "we have sources!" with project(":modules:${proj.name}")
substitute module("org.terasology.modules:${proj.name}") using project(":modules:${proj.name}") because "we have sources!"
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ println "Version for $project.name loaded as $version for group $group"

sourceSets {
// Adjust output path (changed with the Gradle 6 upgrade, this puts it back)
main.java.outputDir = new File("$buildDir/classes")
test.java.outputDir = new File("$buildDir/testClasses")
main.java.destinationDirectory = new File("$buildDir/classes")
test.java.destinationDirectory = new File("$buildDir/testClasses")
}

// Primary dependencies definition
Expand Down Expand Up @@ -88,14 +88,21 @@ dependencies {
// See terasology-metrics for other test-only internal dependencies
}

//TODO: Remove it when gestalt will can to handle ProtectionDomain without classes (Resources)
task copyResourcesToClasses(type:Copy) {
from sourceSets.main.output.resourcesDir
from tasks.named("processResources")
into sourceSets.main.output.classesDirs.first()
}

tasks.named("compileJava"){
dependsOn(copyResourcesToClasses)
}

jar { // Workaround about previous copy to classes. idk why engine-tests:jar called before :engine ...
duplicatesStrategy = "EXCLUDE"
}

test {
//TODO: Remove it when gestalt will can to handle ProtectionDomain without classes (Resources)
dependsOn copyResourcesToClasses
dependsOn rootProject.extractNatives

description("Runs all tests (slow)")
Expand All @@ -104,8 +111,6 @@ test {
}

task unitTest(type: Test) {
//TODO: Remove it when gestalt will can to handle ProtectionDomain without classes (Resources)
dependsOn copyResourcesToClasses
dependsOn rootProject.extractNatives

group "Verification"
Expand All @@ -118,8 +123,6 @@ task unitTest(type: Test) {
}

task integrationTest(type: Test) {
//TODO: Remove it when gestalt will can to handle ProtectionDomain without classes (Resources)
dependsOn copyResourcesToClasses
dependsOn rootProject.extractNatives

group "Verification"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.joml.Vector3i;
import org.joml.Vector3ic;
import org.terasology.engine.rendering.primitives.ChunkMesh;
import org.terasology.engine.rust.resource.ChunkGeometry;
import org.terasology.engine.world.block.Block;
import org.terasology.engine.world.block.BlockRegionc;
import org.terasology.engine.world.chunks.Chunk;
Expand All @@ -19,7 +20,7 @@
public class DummyChunk implements Chunk {
private final Vector3ic chunkPos;
private boolean dirty;
private ChunkMesh mesh;
private ChunkGeometry mesh;
private boolean ready;

public DummyChunk(Vector3ic position) {
Expand Down Expand Up @@ -147,7 +148,7 @@ public AABBfc getAABB() {
}

@Override
public void setMesh(ChunkMesh newMesh) {
public void setMesh(ChunkGeometry newMesh) {
this.mesh = newMesh;
}

Expand All @@ -167,7 +168,7 @@ public boolean hasMesh() {
}

@Override
public ChunkMesh getMesh() {
public ChunkGeometry getMesh() {
return mesh;
}

Expand Down
10 changes: 5 additions & 5 deletions engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id "org.jetbrains.gradle.plugin.idea-ext"
id "com.google.protobuf"
id "terasology-common"

}

// Grab all the common stuff like plugins to use, artifact repositories, code analysis config, etc
Expand Down Expand Up @@ -45,7 +46,7 @@ sourceSets {
}
java {
// Adjust output path (changed with the Gradle 6 upgrade, this puts it back)
outputDir = new File("$buildDir/classes")
destinationDirectory = new File("$buildDir/classes")
}
}
}
Expand Down Expand Up @@ -149,6 +150,7 @@ dependencies {
api group: 'org.terasology.nui', name: 'nui-reflect', version: '3.0.0'
api group: 'org.terasology.nui', name: 'nui-gestalt7', version: '3.0.0'

api group: 'org.terasology.rust', name: 'core', version: rustCoreVersion

// Wildcard dependency to catch any libs provided with the project (remote repo preferred instead)
api fileTree(dir: 'libs', include: '*.jar')
Expand Down Expand Up @@ -263,14 +265,12 @@ tasks.named("processResources", Copy) {

//TODO: Remove this when gestalt can handle ProtectionDomain without classes (Resources)
task copyResourcesToClasses(type: Copy) {
from sourceSets.main.output.resourcesDir
from processResources
into sourceSets.main.output.classesDirs.first()

dependsOn processResources
mustRunAfter compileJava
}

tasks.named("classes") {
tasks.named("compileJava") {
dependsOn(tasks.named("copyResourcesToClasses"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.terasology.engine.recording.RecordAndReplayUtils;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.engine.rendering.gltf.ByteBufferAsset;
import org.terasology.engine.rust.EngineKernel;
import org.terasology.engine.version.TerasologyVersion;
import org.terasology.engine.world.block.loader.BlockFamilyDefinition;
import org.terasology.engine.world.block.loader.BlockFamilyDefinitionData;
Expand Down Expand Up @@ -161,6 +162,7 @@ public TerasologyEngine(TimeSubsystem timeSubsystem, Collection<EngineSubsystem>
rootContext.put(CharacterStateEventPositionMap.class, characterStateEventPositionMap);
DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
rootContext.put(DirectionAndOriginPosRecorderList.class, directionAndOriginPosRecorderList);

/*
* We can't load the engine without core registry yet.
* e.g. the statically created MaterialLoader needs the CoreRegistry to get the AssetManager.
Expand Down Expand Up @@ -564,6 +566,7 @@ public void cleanup() {
*/
@Override
public void shutdown() {

shutdownRequested = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.terasology.engine.rendering.backdrop.BackdropProvider;
import org.terasology.engine.rendering.backdrop.Skysphere;
import org.terasology.engine.rendering.cameras.Camera;
import org.terasology.engine.rendering.world.DeferredRenderer;
import org.terasology.engine.rendering.world.WorldRenderer;
import org.terasology.engine.utilities.random.FastRandom;
import org.terasology.engine.world.BlockEntityRegistry;
Expand Down Expand Up @@ -159,8 +160,7 @@ public boolean step() {
BackdropProvider backdropProvider = skysphere;
context.put(BackdropProvider.class, backdropProvider);

RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
WorldRenderer worldRenderer = new DeferredRenderer(context);
context.put(WorldRenderer.class, worldRenderer);

// TODO: These shouldn't be done here, nor so strongly tied to the world renderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ public LwjglDisplayDevice(Context context) {

@Override
public boolean hasFocus() {
return GLFW.GLFW_TRUE == GLFW.glfwGetWindowAttrib(GLFW.glfwGetCurrentContext(), GLFW.GLFW_FOCUSED);
return GLFW.GLFW_TRUE == GLFW.glfwGetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_FOCUSED);
}

@Override
public boolean isCloseRequested() {
return GLFW.glfwWindowShouldClose(GLFW.glfwGetCurrentContext());
return GLFW.glfwWindowShouldClose(LwjglGraphics.primaryWindow);
}

@Override
public boolean isFullscreen() {
return MemoryUtil.NULL != GLFW.glfwGetWindowMonitor(GLFW.glfwGetCurrentContext());
return MemoryUtil.NULL != GLFW.glfwGetWindowMonitor(LwjglGraphics.primaryWindow);
}

@Override
Expand All @@ -79,7 +79,7 @@ public void setDisplayModeSetting(DisplayModeSetting displayModeSetting) {
}

public void setDisplayModeSetting(DisplayModeSetting displayModeSetting, boolean resize) {
long window = GLFW.glfwGetCurrentContext();
// long window = GLFW.glfwGetCurrentContext();
switch (displayModeSetting) {
case FULLSCREEN:
updateFullScreenDisplay();
Expand All @@ -88,21 +88,21 @@ public void setDisplayModeSetting(DisplayModeSetting displayModeSetting, boolean
break;
case WINDOWED_FULLSCREEN:
GLFWVidMode vidMode = desktopResolution.get();
GLFW.glfwSetWindowMonitor(window,
GLFW.glfwSetWindowMonitor(LwjglGraphics.primaryWindow,
MemoryUtil.NULL,
0,
0,
vidMode.width(),
vidMode.height(),
GLFW.GLFW_DONT_CARE);
GLFW.glfwSetWindowAttrib(window, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
GLFW.glfwSetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
config.setDisplayModeSetting(displayModeSetting);
config.setWindowedFullscreen(true);
break;
case WINDOWED:
GLFW.glfwSetWindowAttrib(window, GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowAttrib(window, GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowMonitor(window,
GLFW.glfwSetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
GLFW.glfwSetWindowMonitor(LwjglGraphics.primaryWindow,
MemoryUtil.NULL,
config.getWindowPosX(),
config.getWindowPosY(),
Expand Down Expand Up @@ -150,7 +150,7 @@ private void updateWindow() {
if (isWindowDirty) {
int[] windowWidth = new int[1];
int[] windowHeight = new int[1];
GLFW.glfwGetWindowSize(GLFW.glfwGetCurrentContext(), windowWidth, windowHeight);
GLFW.glfwGetWindowSize(LwjglGraphics.primaryWindow, windowWidth, windowHeight);
this.windowWidth = windowWidth[0];
this.windowHeight = windowHeight[0];
isWindowDirty = false;
Expand Down Expand Up @@ -178,18 +178,18 @@ public boolean isHeadless() {

@Override
public void prepareToRender() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

@Override
public DisplayDeviceInfo getInfo() {
LwjglGraphicsUtil.updateDisplayDeviceInfo(displayDeviceInfo);
// LwjglGraphicsUtil.updateDisplayDeviceInfo(displayDeviceInfo);
return displayDeviceInfo;
}

public void update() {
processMessages();
GLFW.glfwSwapBuffers(GLFW.glfwGetCurrentContext());
// GLFW.glfwSwapBuffers(GLFW.glfwGetCurrentContext());
isWindowDirty = true;

}
Expand All @@ -199,10 +199,10 @@ private void updateViewport() {
}

protected void updateViewport(int width, int height) {
glViewport(0, 0, width, height);
// glViewport(0, 0, width, height);

//If the screen is minimized, resolution change is stopped to avoid the width and height of FBO being set to 0.
boolean isMinimized = GLFW.glfwGetWindowAttrib(GLFW.glfwGetCurrentContext(), GLFW.GLFW_ICONIFIED) == GLFW.GLFW_TRUE;
boolean isMinimized = GLFW.glfwGetWindowAttrib(LwjglGraphics.primaryWindow, GLFW.GLFW_ICONIFIED) == GLFW.GLFW_TRUE;
int i = isMinimized ? 0 : 1;
propertyChangeSupport.firePropertyChange(DISPLAY_RESOLUTION_CHANGE, i, 1);
}
Expand All @@ -217,9 +217,8 @@ private GLFWVidMode getFullScreenDisplayMode() {
}

private void updateFullScreenDisplay() {
long window = GLFW.glfwGetCurrentContext();
GLFWVidMode vidMode = getFullScreenDisplayMode();
GLFW.glfwSetWindowMonitor(window,
GLFW.glfwSetWindowMonitor(LwjglGraphics.primaryWindow,
GLFW.glfwGetPrimaryMonitor(),
0,
0,
Expand Down
Loading
Loading