Skip to content

Commit 837b779

Browse files
committed
e
1 parent 692ac95 commit 837b779

1 file changed

Lines changed: 34 additions & 25 deletions

File tree

src/main/java/me/cortex/voxy/client/core/gl/Capabilities.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void main() {
102102
if (this.compute&&this.isAmd) {
103103
this.hasBrokenDepthSampler = testDepthSampler();
104104
if (this.hasBrokenDepthSampler) {
105-
//throw new IllegalStateException("it bork, amd is bork");
105+
throw new IllegalStateException("it bork, amd is bork");
106106
}
107107
} else {
108108
this.hasBrokenDepthSampler = false;
@@ -115,15 +115,20 @@ public static void init() {
115115
private static boolean testDepthSampler() {
116116
String src = """
117117
#version 460 core
118-
layout(local_size_x=1) in;
118+
layout(local_size_x=16,local_size_y=16) in;
119119
120120
layout(binding = 0) uniform sampler2D depthSampler;
121121
layout(binding = 1) buffer OutData {
122122
float[] outData;
123123
};
124124
125+
layout(location = 2) uniform int dynamicSampleThing;
126+
layout(location = 3) uniform float sampleData;
127+
125128
void main() {
126-
outData[0] = texelFetch(depthSampler, ivec2(31, 31), 0).r;
129+
if (abs(texelFetch(depthSampler, ivec2(gl_GlobalInvocationID.xy), dynamicSampleThing).r-sampleData)>0.000001f) {
130+
outData[0] = 1.0;
131+
}
127132
}
128133
""";
129134
int program = GL20C.glCreateProgram();
@@ -144,40 +149,44 @@ void main() {
144149
glNamedBufferStorage(buffer, 4096, GL_DYNAMIC_STORAGE_BIT|GL_MAP_READ_BIT);
145150

146151
int tex = glCreateTextures(GL_TEXTURE_2D);
147-
glTextureStorage2D(tex, 1, GL_DEPTH24_STENCIL8, 64, 64);
152+
glTextureStorage2D(tex, 2, GL_DEPTH24_STENCIL8, 256, 256);
148153
glTextureParameteri(tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
149154
glTextureParameteri(tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
150155

151156
int fb = glCreateFramebuffers();
152-
glNamedFramebufferTexture(fb, GL_DEPTH_STENCIL_ATTACHMENT, tex, 0);
153-
154157
boolean isCorrect = true;
155-
for (int i = 0; i <= 10; i++) {
156-
float value = (float) (i/10.0);
158+
for (int lvl = 0; lvl <= 1; lvl++) {
159+
glNamedFramebufferTexture(fb, GL_DEPTH_STENCIL_ATTACHMENT, tex, lvl);
157160

158-
nglClearNamedBufferSubData(buffer, GL_R32F, 0, 4096, GL_RED, GL_FLOAT, 0);//Zero the buffer
159-
glClearNamedFramebufferfi(fb, GL_DEPTH_STENCIL, 0, value, 1);//Set the depth texture
161+
for (int i = 0; i <= 10; i++) {
162+
float value = (float) (i / 10.0);
160163

161-
glUseProgram(program);
162-
glBindTextureUnit(0, tex);
163-
GL30.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);
164+
nglClearNamedBufferSubData(buffer, GL_R32F, 0, 4096, GL_RED, GL_FLOAT, 0);//Zero the buffer
165+
glClearNamedFramebufferfi(fb, GL_DEPTH_STENCIL, 0, value, 1);//Set the depth texture
164166

165-
glDispatchCompute(1,1,1);
166-
glFinish();
167+
glUseProgram(program);
168+
glUniform1i(2, lvl);
169+
glUniform1f(3, value);
170+
glBindTextureUnit(0, tex);
171+
GL30.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffer);
167172

168-
long ptr = nglMapNamedBuffer(buffer, GL_READ_ONLY);
169-
float gottenValue = MemoryUtil.memGetFloat(ptr);
170-
glUnmapNamedBuffer(buffer);
173+
glDispatchCompute(256>>(lvl+4), 256>>(lvl+4), 1);
174+
glFinish();
171175

172-
glUseProgram(0);
173-
glBindTextureUnit(0,0);
174-
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
176+
long ptr = nglMapNamedBuffer(buffer, GL_READ_ONLY);
177+
float gottenValue = MemoryUtil.memGetFloat(ptr);
178+
glUnmapNamedBuffer(buffer);
175179

176-
boolean localCorrect = Math.abs(value - gottenValue)<0.0000001f;
177-
if (!localCorrect) {
178-
Logger.error("Depth read test failed at value: " + value);
180+
glUseProgram(0);
181+
glBindTextureUnit(0, 0);
182+
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
183+
184+
boolean localCorrect = gottenValue==0.0f;
185+
if (!localCorrect) {
186+
Logger.error("Depth read test failed at value: " + value);
187+
}
188+
isCorrect &= localCorrect;
179189
}
180-
isCorrect &= localCorrect;
181190
}
182191

183192
glDeleteFramebuffers(fb);

0 commit comments

Comments
 (0)