This commit is contained in:
mcrcortex
2025-12-23 15:31:20 +10:00
parent 692ac95549
commit 837b779aa9

View File

@@ -102,7 +102,7 @@ public class Capabilities {
if (this.compute&&this.isAmd) { if (this.compute&&this.isAmd) {
this.hasBrokenDepthSampler = testDepthSampler(); this.hasBrokenDepthSampler = testDepthSampler();
if (this.hasBrokenDepthSampler) { if (this.hasBrokenDepthSampler) {
//throw new IllegalStateException("it bork, amd is bork"); throw new IllegalStateException("it bork, amd is bork");
} }
} else { } else {
this.hasBrokenDepthSampler = false; this.hasBrokenDepthSampler = false;
@@ -115,15 +115,20 @@ public class Capabilities {
private static boolean testDepthSampler() { private static boolean testDepthSampler() {
String src = """ String src = """
#version 460 core #version 460 core
layout(local_size_x=1) in; layout(local_size_x=16,local_size_y=16) in;
layout(binding = 0) uniform sampler2D depthSampler; layout(binding = 0) uniform sampler2D depthSampler;
layout(binding = 1) buffer OutData { layout(binding = 1) buffer OutData {
float[] outData; float[] outData;
}; };
layout(location = 2) uniform int dynamicSampleThing;
layout(location = 3) uniform float sampleData;
void main() { void main() {
outData[0] = texelFetch(depthSampler, ivec2(31, 31), 0).r; if (abs(texelFetch(depthSampler, ivec2(gl_GlobalInvocationID.xy), dynamicSampleThing).r-sampleData)>0.000001f) {
outData[0] = 1.0;
}
} }
"""; """;
int program = GL20C.glCreateProgram(); int program = GL20C.glCreateProgram();
@@ -144,40 +149,44 @@ public class Capabilities {
glNamedBufferStorage(buffer, 4096, GL_DYNAMIC_STORAGE_BIT|GL_MAP_READ_BIT); glNamedBufferStorage(buffer, 4096, GL_DYNAMIC_STORAGE_BIT|GL_MAP_READ_BIT);
int tex = glCreateTextures(GL_TEXTURE_2D); int tex = glCreateTextures(GL_TEXTURE_2D);
glTextureStorage2D(tex, 1, GL_DEPTH24_STENCIL8, 64, 64); glTextureStorage2D(tex, 2, GL_DEPTH24_STENCIL8, 256, 256);
glTextureParameteri(tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTextureParameteri(tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTextureParameteri(tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTextureParameteri(tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
int fb = glCreateFramebuffers(); int fb = glCreateFramebuffers();
glNamedFramebufferTexture(fb, GL_DEPTH_STENCIL_ATTACHMENT, tex, 0);
boolean isCorrect = true; boolean isCorrect = true;
for (int i = 0; i <= 10; i++) { for (int lvl = 0; lvl <= 1; lvl++) {
float value = (float) (i/10.0); glNamedFramebufferTexture(fb, GL_DEPTH_STENCIL_ATTACHMENT, tex, lvl);
nglClearNamedBufferSubData(buffer, GL_R32F, 0, 4096, GL_RED, GL_FLOAT, 0);//Zero the buffer for (int i = 0; i <= 10; i++) {
glClearNamedFramebufferfi(fb, GL_DEPTH_STENCIL, 0, value, 1);//Set the depth texture float value = (float) (i / 10.0);
glUseProgram(program); nglClearNamedBufferSubData(buffer, GL_R32F, 0, 4096, GL_RED, GL_FLOAT, 0);//Zero the buffer
glBindTextureUnit(0, tex); glClearNamedFramebufferfi(fb, GL_DEPTH_STENCIL, 0, value, 1);//Set the depth texture
GL30.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);
glDispatchCompute(1,1,1); glUseProgram(program);
glFinish(); glUniform1i(2, lvl);
glUniform1f(3, value);
glBindTextureUnit(0, tex);
GL30.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);
long ptr = nglMapNamedBuffer(buffer, GL_READ_ONLY); glDispatchCompute(256>>(lvl+4), 256>>(lvl+4), 1);
float gottenValue = MemoryUtil.memGetFloat(ptr); glFinish();
glUnmapNamedBuffer(buffer);
glUseProgram(0); long ptr = nglMapNamedBuffer(buffer, GL_READ_ONLY);
glBindTextureUnit(0,0); float gottenValue = MemoryUtil.memGetFloat(ptr);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); glUnmapNamedBuffer(buffer);
boolean localCorrect = Math.abs(value - gottenValue)<0.0000001f; glUseProgram(0);
if (!localCorrect) { glBindTextureUnit(0, 0);
Logger.error("Depth read test failed at value: " + value); glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
boolean localCorrect = gottenValue==0.0f;
if (!localCorrect) {
Logger.error("Depth read test failed at value: " + value);
}
isCorrect &= localCorrect;
} }
isCorrect &= localCorrect;
} }
glDeleteFramebuffers(fb); glDeleteFramebuffers(fb);