Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Compute-Shader: InterlockedAdd: buggy?

$
0
0
Hi, can anybody tell me why the first code is not working in my ComputeShader, and the second does? This piece of code procdues broken meshes: [numthreads(8,8,8)] void MarchingCubes2(uint3 threadId : SV_DispatchThreadID) { ... for (int i = 0; triTable[cubeIndex] != -1; i += 3) { // Seems not to work: ??? Why??? InterlockedAdd(_cnt[0].trianglecount, 1, idxTriangle1); InterlockedAdd(_cnt[0].trianglecount, 1, idxTriangle2); InterlockedAdd(_cnt[0].trianglecount, 1, idxTriangle3); InterlockedAdd(_cnt[0].vertexcount, 1, idxVertex1); InterlockedAdd(_cnt[0].vertexcount, 1, idxVertex2); InterlockedAdd(_cnt[0].vertexcount, 1, idxVertex3); vertexRW[idxVertex1] = vertlist[triTable[cubeIndex]]; normalRW[idxVertex1] = normalize(CalculateGradient(vertexRW[idxVertex1])); UV[idxVertex1] = uvmap[voxeltype][0]; vertexRW[idxVertex2] = vertlist[triTable[cubeIndex][i+1]]; normalRW[idxVertex2] = normalize(CalculateGradient(vertexRW[idxVertex2])); UV[idxVertex2] = uvmap[voxeltype][0]; vertexRW[idxVertex3] = vertlist[triTable[cubeIndex][i+2]]; normalRW[idxVertex3] = normalize(CalculateGradient(vertexRW[idxVertex3])); UV[idxVertex3] = uvmap[voxeltype][0]; triangleRW[idxTriangle1] = idxVertex1; triangleRW[idxTriangle2] = idxVertex2; triangleRW[idxTriangle3] = idxVertex3; ... } .. When I change the coding to this here, everythings is fine: ... [numthreads(8,8,8)] void MarchingCubes2(uint3 threadId : SV_DispatchThreadID) { ... for (int i = 0; triTable[cubeIndex] != -1; i += 3) { //WTF ???? // Seems to work: InterlockedAdd(_cnt[0].trianglecount, 3, idxTriangle1); InterlockedAdd(_cnt[0].vertexcount, 3, idxVertex1); idxTriangle2 = idxTriangle1 + 1; idxTriangle3 = idxTriangle2 + 1; idxVertex2 = idxVertex1 + 1; idxVertex3 = idxVertex2 + 1; vertexRW[idxVertex1] = vertlist[triTable[cubeIndex]]; normalRW[idxVertex1] = normalize(CalculateGradient(vertexRW[idxVertex1])); UV[idxVertex1] = uvmap[voxeltype][0]; vertexRW[idxVertex2] = vertlist[triTable[cubeIndex][i+1]]; normalRW[idxVertex2] = normalize(CalculateGradient(vertexRW[idxVertex2])); UV[idxVertex2] = uvmap[voxeltype][0]; vertexRW[idxVertex3] = vertlist[triTable[cubeIndex][i+2]]; normalRW[idxVertex3] = normalize(CalculateGradient(vertexRW[idxVertex3])); UV[idxVertex3] = uvmap[voxeltype][0]; triangleRW[idxTriangle1] = idxVertex1; triangleRW[idxTriangle2] = idxVertex2; triangleRW[idxTriangle3] = idxVertex3; ... } .. But whats the difference? They should be the same??? MCshaderCode.txt meshOutputTextNotWorking.txt meshOutputTextWorking.txt

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>