summaryrefslogtreecommitdiff
path: root/graphics/asymptote/base
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-03-09 03:01:03 +0000
committerNorbert Preining <norbert@preining.info>2022-03-09 03:01:03 +0000
commitb23d702a4a177c6d047cd03020e5a0fb7effd88a (patch)
tree60f860c1b86caf0fa6637b79a3490f642b57c761 /graphics/asymptote/base
parentb1f3f2681b2bf35570ad11f65270777f38c55f7e (diff)
CTAN sync 202203090301
Diffstat (limited to 'graphics/asymptote/base')
-rw-r--r--graphics/asymptote/base/rational.asy41
-rw-r--r--graphics/asymptote/base/shaders/blend.glsl121
-rw-r--r--graphics/asymptote/base/shaders/count.glsl6
-rw-r--r--graphics/asymptote/base/shaders/fragment.glsl54
-rw-r--r--graphics/asymptote/base/shaders/offset.glsl11
-rw-r--r--graphics/asymptote/base/shaders/partialsum.glsl37
-rw-r--r--graphics/asymptote/base/shaders/presum.glsl37
-rw-r--r--graphics/asymptote/base/shaders/sum1.glsl38
-rw-r--r--graphics/asymptote/base/shaders/sum2.glsl24
-rw-r--r--graphics/asymptote/base/shaders/sum3.glsl28
-rw-r--r--graphics/asymptote/base/shaders/zero.glsl (renamed from graphics/asymptote/base/shaders/count0.glsl)0
-rw-r--r--graphics/asymptote/base/three_surface.asy2
-rw-r--r--graphics/asymptote/base/v3dheadertypes.asy2
-rw-r--r--graphics/asymptote/base/v3dtypes.asy2
14 files changed, 239 insertions, 164 deletions
diff --git a/graphics/asymptote/base/rational.asy b/graphics/asymptote/base/rational.asy
index aac3d5be9b..068376fece 100644
--- a/graphics/asymptote/base/rational.asy
+++ b/graphics/asymptote/base/rational.asy
@@ -1,5 +1,7 @@
// Asymptote module implementing rational arithmetic.
+int maxDenominator=100000; // Maximum denominator for approximating reals
+
int gcd(int m, int n)
{
if(m < n) {
@@ -41,22 +43,52 @@ struct rational {
}
}
-rational operator cast(int p) {
+rational operator cast(int p)
+{
return rational(p,false);
}
-rational[] operator cast(int[] a) {
+rational[] operator cast(int[] a)
+{
return sequence(new rational(int i) {return a[i];},a.length);
}
-rational[][] operator cast(int[][] a) {
+rational[][] operator cast(int[][] a)
+{
return sequence(new rational[](int i) {return a[i];},a.length);
}
-real operator ecast(rational r) {
+real operator ecast(rational r)
+{
return r.p/r.q;
}
+rational operator ecast(real x)
+{
+ int sign=x >= 0.0 ? 1 : -1;
+ x=abs(x);
+ int a=floor(x); int b=1;
+ int c=a+1; int d=1;
+
+ while(true) {
+ int e=a+c;
+ int f=b+d;
+ if(f > maxDenominator) break;
+ if(e/f == x)
+ return rational(sign*e,f);
+ else {
+ if(e/f < x) {
+ a=e;
+ b=f;
+ } else {
+ c=e;
+ d=f;
+ }
+ }
+ }
+ return abs(a/b-x) < abs(c/d-x) ? rational(sign*a,b) : rational(sign*c,d);
+}
+
rational operator -(rational r)
{
return rational(-r.p,r.q,false);
@@ -272,4 +304,3 @@ rational[][] r=a;
write(r);
*/
-
diff --git a/graphics/asymptote/base/shaders/blend.glsl b/graphics/asymptote/base/shaders/blend.glsl
index 629cc2dda5..76dfe94ad3 100644
--- a/graphics/asymptote/base/shaders/blend.glsl
+++ b/graphics/asymptote/base/shaders/blend.glsl
@@ -1,36 +1,49 @@
-layout(binding=0, std430) buffer sumBuffer {
- uint sum[];
+layout(binding=0, std430) buffer offsetBuffer {
+ uint offset[];
};
-layout(binding=1, std430) buffer offsetBuffer {
- uint offset[];
+layout(binding=1, std430) buffer maxBuffer {
+ uint maxSize;
+};
+
+#ifdef GPUINDEXING
+uniform uint offset2;
+uniform uint m1;
+uniform uint r;
+
+layout(binding=2, std430) buffer localSumBuffer {
+ uint localSum[];
};
+layout(binding=3, std430) buffer globalSumBuffer {
+ uint globalSum[];
+};
+#else
layout(binding=2, std430) buffer countBuffer {
uint count[];
};
+#endif
-layout(binding=3, std430) buffer fragmentBuffer {
+layout(binding=4, std430) buffer fragmentBuffer {
vec4 fragment[];
};
-layout(binding=4, std430) buffer depthBuffer {
+layout(binding=5, std430) buffer depthBuffer {
float depth[];
};
-layout(binding=5, std430) buffer opaqueBuffer {
+layout(binding=6, std430) buffer opaqueBuffer {
vec4 opaqueColor[];
};
-layout(binding=6, std430) buffer opaqueDepthBuffer {
+layout(binding=7, std430) buffer opaqueDepthBuffer {
float opaqueDepth[];
};
out vec4 outColor;
uniform uint width;
-uniform uint M;
-uniform uint r;
+uniform uint pixels;
uniform vec4 background;
vec4 blend(vec4 outColor, vec4 color)
@@ -41,91 +54,95 @@ vec4 blend(vec4 outColor, vec4 color)
void main()
{
uint headIndex=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
+#ifdef GPUINDEXING
+ uint size=offset[headIndex];
+#else
uint size=count[headIndex];
+#endif
float OpaqueDepth=opaqueDepth[headIndex];
if(size == 0u) {
#ifdef GPUINDEXING
- offset[headIndex]=0u;
+ offset[pixels+headIndex]=0u;
#endif
opaqueDepth[headIndex]=0.0;
discard;
}
- uint listIndex=
+ outColor=OpaqueDepth != 0.0 ? opaqueColor[headIndex] : background;
+
#ifdef GPUINDEXING
- sum[headIndex < r*(M+1u) ? headIndex/(M+1u) : (headIndex-r)/M]+
+ uint p=headIndex < r*(m1+1u) ? headIndex/(m1+1u) : (headIndex-r)/m1;
+ uint listIndex=localSum[p]+localSum[offset2+p/m2]+globalSum[p/(m2*m2)]+
+ offset[pixels+headIndex];
+#else
+ uint listIndex=offset[headIndex]-size;
#endif
- offset[headIndex];
- const uint maxSize=16u;
-
- // Sort the fragments with respect to descending depth
- if(size < maxSize) {
- vec4 sortedColor[maxSize];
- float sortedDepth[maxSize];
- uint k=0u;
-
- if(OpaqueDepth != 0.0)
- while(k < size && depth[listIndex+k] >= OpaqueDepth)
- ++k;
+ uint k=0u;
+ if(OpaqueDepth != 0.0)
+ while(k < size && depth[listIndex+k] >= OpaqueDepth)
+ ++k;
- uint i=0u;
+ // Sort the fragments with respect to descending depth
+ if(size-k <= ARRAYSIZE) {
if(k < size) {
- sortedColor[0]=fragment[listIndex+k];
- sortedDepth[0]=depth[listIndex+k];
+ uint Index[ARRAYSIZE];
+ float Depth[ARRAYSIZE];
+ Index[0]=k;
+ Depth[0]=depth[listIndex+k];
++k;
- i=1u;
+ uint i=1u;
while(true) {
if(OpaqueDepth != 0.0)
while(k < size && depth[listIndex+k] >= OpaqueDepth)
++k;
if(k == size) break;
- float D=depth[listIndex+k];
+ float d=depth[listIndex+k];
uint j=i;
- float d;
- while(j > 0u && D > sortedDepth[j-1u]) {
- sortedColor[j]=sortedColor[j-1u];
- sortedDepth[j]=sortedDepth[j-1u];
+ while(j > 0u && d > Depth[j-1u]) {
+ Index[j]=Index[j-1u];
+ Depth[j]=Depth[j-1u];
--j;
}
- sortedColor[j]=fragment[listIndex+k];
- sortedDepth[j]=D;
+ Index[j]=k++;
+ Depth[j]=d;
++i;
- ++k;
}
+ for(uint j=0u; j < i; ++j)
+ outColor=blend(outColor,fragment[listIndex+Index[j]]);
}
- outColor=OpaqueDepth != 0.0 ? opaqueColor[headIndex] : background;
- for(uint j=0u; j < i; ++j)
- outColor=blend(outColor,sortedColor[j]);
} else {
- uint k=0u;
- if(OpaqueDepth != 0.0)
- while(k < size && depth[listIndex+k] >= OpaqueDepth)
- ++k;
+ atomicMax(maxSize,size);
for(uint i=k+1u; i < size; i++) {
vec4 temp=fragment[listIndex+i];
- float D=depth[listIndex+i];
+ float d=depth[listIndex+i];
uint j=i;
- while(j > 0u && D > depth[listIndex+j-1u]) {
+ while(j > 0u && d > depth[listIndex+j-1u]) {
fragment[listIndex+j]=fragment[listIndex+j-1u];
depth[listIndex+j]=depth[listIndex+j-1u];
--j;
}
fragment[listIndex+j]=temp;
- depth[listIndex+j]=D;
+ depth[listIndex+j]=d;
}
- outColor=OpaqueDepth != 0.0 ? opaqueColor[headIndex] : background;
uint stop=listIndex+size;
- for(uint i=listIndex+k; i < stop; i++) {
- if(OpaqueDepth == 0.0 || depth[i] < OpaqueDepth)
+ if(OpaqueDepth == 0.0)
+ for(uint i=listIndex+k; i < stop; i++)
outColor=blend(outColor,fragment[i]);
- }
+ else
+ for(uint i=listIndex+k; i < stop; i++) {
+ if(depth[i] < OpaqueDepth)
+ outColor=blend(outColor,fragment[i]);
+ }
}
- count[headIndex]=0u;
+
opaqueDepth[headIndex]=0.0;
#ifdef GPUINDEXING
offset[headIndex]=0u;
+ offset[pixels+headIndex]=0u;
+#else
+ count[headIndex]=0u;
#endif
}
diff --git a/graphics/asymptote/base/shaders/count.glsl b/graphics/asymptote/base/shaders/count.glsl
index dae4e51f1b..c942771498 100644
--- a/graphics/asymptote/base/shaders/count.glsl
+++ b/graphics/asymptote/base/shaders/count.glsl
@@ -1,6 +1,12 @@
+#ifdef GPUINDEXING
+layout(binding=0, std430) buffer offsetBuffer {
+ uint count[];
+};
+#else
layout(binding=2, std430) buffer countBuffer {
uint count[];
};
+#endif
uniform uint width;
diff --git a/graphics/asymptote/base/shaders/fragment.glsl b/graphics/asymptote/base/shaders/fragment.glsl
index 5f60a56efd..e8d4be86cf 100644
--- a/graphics/asymptote/base/shaders/fragment.glsl
+++ b/graphics/asymptote/base/shaders/fragment.glsl
@@ -30,37 +30,50 @@ float Roughness;
#ifdef HAVE_SSBO
-layout(binding=0, std430) buffer sumBuffer {
- uint sum[];
+layout(binding=0, std430) buffer offsetBuffer {
+ uint offset[];
};
-layout(binding=1, std430) buffer offsetBuffer {
- uint offset[];
+#ifdef GPUINDEXING
+
+#if defined(TRANSPARENT) || (!defined(HAVE_INTERLOCK) && !defined(OPAQUE))
+uniform uint offset2;
+uniform uint m1;
+uniform uint r;
+#endif
+
+layout(binding=2, std430) buffer localSumBuffer {
+ uint localSum[];
};
+layout(binding=3, std430) buffer globalSumBuffer {
+ uint globalSum[];
+};
+#else
layout(binding=2, std430) buffer countBuffer {
uint count[];
};
+#endif
-layout(binding=3, std430) buffer fragmentBuffer {
+layout(binding=4, std430) buffer fragmentBuffer {
vec4 fragment[];
};
-layout(binding=4, std430) buffer depthBuffer {
+layout(binding=5, std430) buffer depthBuffer {
float depth[];
};
-layout(binding=5, std430) buffer opaqueBuffer {
+layout(binding=6, std430) buffer opaqueBuffer {
vec4 opaqueColor[];
};
-layout(binding=6, std430) buffer opaqueDepthBuffer {
+layout(binding=7, std430) buffer opaqueDepthBuffer {
float opaqueDepth[];
};
uniform uint width;
-uniform uint M;
-uniform uint r;
+uniform uint pixels;
+
#endif
#ifdef NORMAL
@@ -261,11 +274,13 @@ void main()
#ifdef HAVE_SSBO
uint headIndex=uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x);
#if defined(TRANSPARENT) || (!defined(HAVE_INTERLOCK) && !defined(OPAQUE))
- uint listIndex=
#ifdef GPUINDEXING
- sum[headIndex < r*(M+1u) ? headIndex/(M+1u) : (headIndex-r)/M]+
+ uint p=headIndex < r*(m1+1u) ? headIndex/(m1+1u) : (headIndex-r)/m1;
+ uint listIndex=localSum[p]+localSum[offset2+p/m2]+globalSum[p/(m2*m2)]+
+ atomicAdd(offset[pixels+headIndex],-1u)-1u;
+#else
+ uint listIndex=offset[headIndex]-atomicAdd(count[headIndex],1u)-1u;
#endif
- offset[headIndex]+atomicAdd(count[headIndex],1u);
fragment[listIndex]=outColor;
depth[listIndex]=gl_FragCoord.z;
#ifndef WIREFRAME
@@ -274,12 +289,13 @@ void main()
#else
#ifndef OPAQUE
#ifdef HAVE_INTERLOCK
-beginInvocationInterlockARB();
-if(opaqueDepth[headIndex] == 0.0 || gl_FragCoord.z < opaqueDepth[headIndex]) {
- opaqueDepth[headIndex]=gl_FragCoord.z;
- opaqueColor[headIndex]=outColor;
-}
-endInvocationInterlockARB();
+ beginInvocationInterlockARB();
+ if(opaqueDepth[headIndex] == 0.0 || gl_FragCoord.z < opaqueDepth[headIndex])
+ {
+ opaqueDepth[headIndex]=gl_FragCoord.z;
+ opaqueColor[headIndex]=outColor;
+ }
+ endInvocationInterlockARB();
#endif
#endif
#endif
diff --git a/graphics/asymptote/base/shaders/offset.glsl b/graphics/asymptote/base/shaders/offset.glsl
deleted file mode 100644
index 5fe24e7558..0000000000
--- a/graphics/asymptote/base/shaders/offset.glsl
+++ /dev/null
@@ -1,11 +0,0 @@
-layout(binding=1, std430) buffer offsetBuffer {
- uint offset[];
-};
-
-uniform uint width;
-
-void main()
-{
- atomicAdd(offset[uint(gl_FragCoord.y)*width+uint(gl_FragCoord.x)+1u],1u);
- discard;
-}
diff --git a/graphics/asymptote/base/shaders/partialsum.glsl b/graphics/asymptote/base/shaders/partialsum.glsl
deleted file mode 100644
index d00195bb3a..0000000000
--- a/graphics/asymptote/base/shaders/partialsum.glsl
+++ /dev/null
@@ -1,37 +0,0 @@
-layout(local_size_x=PROCESSORS) in;
-
-uniform uint elements;
-
-layout(binding=0, std430) buffer sumBuffer
-{
- uint sum[];
-};
-
-shared uint sharedData[PROCESSORS];
-
-void main(void)
-{
- uint id=gl_LocalInvocationID.x;
- sharedData[id]=sum[id+1u];
-
- barrier();
-
- uint index=id << 1u;
- sharedData[index+1u] += sharedData[index];
- barrier();
- for(uint step=1u; step < STEPSM1; step++) {
- uint mask=(1u << step)-1u;
- uint index=((id >> step) << (step+1u))+mask;
- uint windex=index+(id&mask)+1u;
- sharedData[windex] += sharedData[index];
- barrier();
- }
- uint mask=(1u << STEPSM1)-1u;
- index=((id >> STEPSM1) << (STEPSM1+1u))+mask;
- uint windex=index+(id&mask)+1u;
- if(windex < PROCESSORS)
- sharedData[windex] += sharedData[index];
- barrier();
-
- sum[id+1u]=sharedData[id];
-}
diff --git a/graphics/asymptote/base/shaders/presum.glsl b/graphics/asymptote/base/shaders/presum.glsl
deleted file mode 100644
index 5b0a8df89e..0000000000
--- a/graphics/asymptote/base/shaders/presum.glsl
+++ /dev/null
@@ -1,37 +0,0 @@
-layout(local_size_x=1) in;
-
-uniform uint elements;
-
-layout(binding=0, std430) buffer sumBuffer
-{
- uint sum[];
-};
-
-layout(binding=1, std430) buffer offsetBuffer
-{
- uint offset[];
-};
-
-void main(void)
-{
- uint id=gl_GlobalInvocationID.x;
-
- uint m=elements/gl_NumWorkGroups.x;
- uint r=elements-m*gl_NumWorkGroups.x;
- uint row,stop;
- if(id < r) {
- row=m*id+id;
- stop=row+m+1u;
- } else {
- row=m*id+r;
- stop=row+m;
- }
-
- uint Sum=offset[row];
- for(uint i=row+1u; i < stop; ++i) {
- Sum += offset[i];
- offset[i]=Sum;
- }
-
- sum[id+1u]=Sum;
-}
diff --git a/graphics/asymptote/base/shaders/sum1.glsl b/graphics/asymptote/base/shaders/sum1.glsl
new file mode 100644
index 0000000000..2cb9ed23aa
--- /dev/null
+++ b/graphics/asymptote/base/shaders/sum1.glsl
@@ -0,0 +1,38 @@
+layout(local_size_x=LOCAL_SIZE_X) in;
+
+uniform uint elements;
+
+layout(binding=0, std430) buffer offsetBuffer
+{
+ uint offset[];
+};
+
+layout(binding=2, std430) buffer localSumBuffer
+{
+ uint localSum[];
+};
+
+void main(void)
+{
+ uint id=gl_GlobalInvocationID.x;
+
+ uint m=elements/(gl_WorkGroupSize.x*gl_NumWorkGroups.x);
+ uint r=elements-m*gl_WorkGroupSize.x*gl_NumWorkGroups.x;
+ uint row,stop;
+ if(id < r) {
+ row=m*id+id;
+ stop=row+m+1u;
+ } else {
+ row=m*id+r;
+ stop=row+m;
+ }
+
+ uint Sum=offset[row];
+ offset[elements+row]=Sum;
+ for(uint i=row+1u; i < stop; ++i) {
+ Sum += offset[i];
+ offset[elements+i]=Sum;
+ }
+
+ localSum[id+1u]=Sum;
+}
diff --git a/graphics/asymptote/base/shaders/sum2.glsl b/graphics/asymptote/base/shaders/sum2.glsl
new file mode 100644
index 0000000000..1ab03513eb
--- /dev/null
+++ b/graphics/asymptote/base/shaders/sum2.glsl
@@ -0,0 +1,24 @@
+layout(local_size_x=LOCAL_SIZE_X) in;
+
+uniform uint offset2;
+
+layout(binding=2, std430) buffer localSumBuffer
+{
+ uint localSum[];
+};
+
+void main(void)
+{
+ uint id=gl_GlobalInvocationID.x;
+
+ uint row=LOCAL_SIZE_X*id;
+ uint stop=row+LOCAL_SIZE_X;
+
+ uint Sum=localSum[row];
+ for(uint i=row+1u; i < stop; ++i) {
+ Sum += localSum[i];
+ localSum[i]=Sum;
+ }
+
+ localSum[offset2+id+1u]=Sum;
+}
diff --git a/graphics/asymptote/base/shaders/sum3.glsl b/graphics/asymptote/base/shaders/sum3.glsl
new file mode 100644
index 0000000000..85f55ff2a6
--- /dev/null
+++ b/graphics/asymptote/base/shaders/sum3.glsl
@@ -0,0 +1,28 @@
+layout(local_size_x=LOCAL_SIZE_X) in;
+
+uniform uint offset2;
+
+layout(binding=2, std430) buffer localSumBuffer
+{
+ uint localSum[];
+};
+
+layout(binding=3, std430) buffer globalSumBuffer {
+ uint globalSum[];
+};
+
+void main(void)
+{
+ uint id=gl_GlobalInvocationID.x;
+
+ uint row=offset2+LOCAL_SIZE_X*id;
+ uint stop=row+LOCAL_SIZE_X;
+
+ uint Sum=localSum[row];
+ for(uint i=row+1u; i < stop; ++i) {
+ Sum += localSum[i];
+ localSum[i]=Sum;
+ }
+
+ globalSum[id+1u]=Sum;
+}
diff --git a/graphics/asymptote/base/shaders/count0.glsl b/graphics/asymptote/base/shaders/zero.glsl
index 9bcb6d222e..9bcb6d222e 100644
--- a/graphics/asymptote/base/shaders/count0.glsl
+++ b/graphics/asymptote/base/shaders/zero.glsl
diff --git a/graphics/asymptote/base/three_surface.asy b/graphics/asymptote/base/three_surface.asy
index d0d79de464..95f41a6181 100644
--- a/graphics/asymptote/base/three_surface.asy
+++ b/graphics/asymptote/base/three_surface.asy
@@ -1512,7 +1512,7 @@ void tensorshade(transform t=identity(), frame f, patch s,
} else p=s.colors(m,light);
path g=t*project(s.external(),P,1);
pair[] internal=t*project(s.internal(),P);
- pen fillrule=m.diffuse();
+ pen fillrule=fillrule(fillrule(m.diffuse()));
if(inside(g,internal[0],fillrule) && inside(g,internal[1],fillrule) &&
inside(g,internal[2],fillrule) && inside(g,internal[3],fillrule)) {
if(p[0] == p[1] && p[1] == p[2] && p[2] == p[3])
diff --git a/graphics/asymptote/base/v3dheadertypes.asy b/graphics/asymptote/base/v3dheadertypes.asy
index fd4afe8165..dba3c18d0b 100644
--- a/graphics/asymptote/base/v3dheadertypes.asy
+++ b/graphics/asymptote/base/v3dheadertypes.asy
@@ -1,6 +1,6 @@
// Enum class for v3dheadertypes
// AUTO-GENERATED from v3dheadertypes.csv
-// Generated at 2022-02-04 23:53:49.222250
+// Generated at 2022-03-07 12:05:14.285216
struct v3dheadertypes
{
diff --git a/graphics/asymptote/base/v3dtypes.asy b/graphics/asymptote/base/v3dtypes.asy
index 52515a14ba..6de6b31c5c 100644
--- a/graphics/asymptote/base/v3dtypes.asy
+++ b/graphics/asymptote/base/v3dtypes.asy
@@ -1,6 +1,6 @@
// Enum class for v3dtypes
// AUTO-GENERATED from v3dtypes.csv
-// Generated at 2022-02-04 23:53:49.158592
+// Generated at 2022-03-07 12:05:14.274334
struct v3dtypes
{