-
Notifications
You must be signed in to change notification settings - Fork 421
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
False zero alignment error for BDA GPU-AV #9531
Comments
Full shader, for information: #version 460
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require
#extension GL_EXT_buffer_reference2 : require
#define DRAW_INDIRECT_MAX_ENTITIES_SIZE 81936
layout(local_size_x = 8, local_size_y = 8) in;
struct FrustumCullingInfo {
vec4 planes[6];
uint64_t address;
};
struct ObjectInfo {
vec3 position;
mat4 rotation;
vec3 scale;
vec3 aabbMin;
vec3 aabbMax;
};
layout(set = 0, binding = 0) restrict readonly buffer FrustumCulling {
uint count;
FrustumCullingInfo info[];
} frustumCulling;
layout(set = 0, binding = 1) restrict readonly buffer Objects {
ObjectInfo info[];
} objects;
struct DrawIndirect {
uint indexCount;
uint instanceCount;
uint firstIndex;
int vertexOffset;
uint firstInstance;
};
layout(set = 0, binding = 2) restrict readonly buffer InDrawIndirect {
uint drawCount;
DrawIndirect commands[];
} inDrawIndirect;
struct PerDrawInfo {
uint objectID;
};
layout(set = 0, binding = 3) restrict readonly buffer InPerDraw {
PerDrawInfo info[];
} inPerDraw;
layout(buffer_reference) buffer DrawIndirectBuffer {
uint drawCount;
DrawIndirect commands[];
};
layout(buffer_reference) buffer PerDrawBuffer {
PerDrawInfo info[];
};
bool intersect(FrustumCullingInfo frustumCullingInfo, vec3 aabbMin, vec3 aabbMax) {
const vec3 mmm = vec3(aabbMin.x, aabbMin.y, aabbMin.z);
const vec3 Mmm = vec3(aabbMax.x, aabbMin.y, aabbMin.z);
const vec3 mMm = vec3(aabbMin.x, aabbMax.y, aabbMin.z);
const vec3 MMm = vec3(aabbMax.x, aabbMax.y, aabbMin.z);
const vec3 mmM = vec3(aabbMin.x, aabbMin.y, aabbMax.z);
const vec3 MmM = vec3(aabbMax.x, aabbMin.y, aabbMax.z);
const vec3 mMM = vec3(aabbMin.x, aabbMax.y, aabbMax.z);
const vec3 MMM = vec3(aabbMax.x, aabbMax.y, aabbMax.z);
for (uint i = 0; i < 6; i++) {
if (((dot(frustumCullingInfo.planes[i].xyz, mmm) + frustumCullingInfo.planes[i].w) <= 0.0f)
&& ((dot(frustumCullingInfo.planes[i].xyz, Mmm) + frustumCullingInfo.planes[i].w) <= 0.0f)
&& ((dot(frustumCullingInfo.planes[i].xyz, mMm) + frustumCullingInfo.planes[i].w) <= 0.0f)
&& ((dot(frustumCullingInfo.planes[i].xyz, MMm) + frustumCullingInfo.planes[i].w) <= 0.0f)
&& ((dot(frustumCullingInfo.planes[i].xyz, mmM) + frustumCullingInfo.planes[i].w) <= 0.0f)
&& ((dot(frustumCullingInfo.planes[i].xyz, MmM) + frustumCullingInfo.planes[i].w) <= 0.0f)
&& ((dot(frustumCullingInfo.planes[i].xyz, mMM) + frustumCullingInfo.planes[i].w) <= 0.0f)
&& ((dot(frustumCullingInfo.planes[i].xyz, MMM) + frustumCullingInfo.planes[i].w) <= 0.0f)) {
return false;
}
}
return true;
}
void main() {
uint objectIndex = gl_GlobalInvocationID.x;
if (objectIndex >= inDrawIndirect.drawCount) {
return;
}
uint frustumIndex = gl_GlobalInvocationID.y;
if (frustumIndex >= frustumCulling.count) {
return;
}
FrustumCullingInfo frustumCullingInfo = frustumCulling.info[frustumIndex];
vec3 aabbMin = objects.info[objectIndex].aabbMin;
vec3 aabbMax = objects.info[objectIndex].aabbMax;
vec3 newAABBMin = objects.info[objectIndex].position;
vec3 newAABBMax = objects.info[objectIndex].position;
float a;
float b;
for (uint i = 0; i < 3; i++) {
for (uint j = 0; j < 3; j++) {
a = objects.info[objectIndex].rotation[j][i] * aabbMin[j] * abs(objects.info[objectIndex].scale[j]);
b = objects.info[objectIndex].rotation[j][i] * aabbMax[j] * abs(objects.info[objectIndex].scale[j]);
newAABBMin[i] += (a < b) ? a : b;
newAABBMax[i] += (a < b) ? b : a;
}
}
aabbMin = newAABBMin;
aabbMax = newAABBMax;
if (intersect(frustumCullingInfo, aabbMin, aabbMax)) {
uint drawIndex = atomicAdd(DrawIndirectBuffer(frustumCullingInfo.address).drawCount, 1);
DrawIndirectBuffer(frustumCullingInfo.address).commands[drawIndex] = inDrawIndirect.commands[objectIndex];
PerDrawBuffer(frustumCullingInfo.address + DRAW_INDIRECT_MAX_ENTITIES_SIZE).info[drawIndex] = inPerDraw.info[objectIndex];
}
} |
And full validation message:
I don't know if it's related but the Global Invocation ID is always 8 (which is the local_size_x) for this message. |
Taking a look at this right now, one thing strange about the message is
where there is clearly no line 126 in the source
|
Awww, wow, found the issue https://godbolt.org/z/c447Koa45 There is a |
It is the right one, line 126 is either Compiled using glslang. |
So got confirmation that It can't do
|
@ntsh-oni heads up, GPU-AV now won't report a false positive, but glslang has a bug (KhronosGroup/glslang#3893) and a future SDK (the one after 1.4.309) will report it as invalid SPIR-V |
Alright! So, the original glsl code has an alignment issue then? |
yes, you can see a trimmed down version here https://godbolt.org/z/r35M64enW that |
generates
which is bogus
The text was updated successfully, but these errors were encountered: