Skip to content

Support running on Apple Silicon(M-seriese) #1336

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phy/cluster/views/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _create_visuals(self):
# Gradient of color for the traces.
if self.trace_color_0 and self.trace_color_1:
self.trace_visual.inserter.insert_frag(
'gl_FragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % (
'fragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % (
self.trace_color_0, self.trace_color_1, self.n_channels), 'end')
self.canvas.add_visual(self.trace_visual)

Expand Down
8 changes: 4 additions & 4 deletions phy/plot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ def __init__(self):
def _init_insert(self):
self.insert_vert('vec2 {{varout}} = {{varin}};', 'before_transforms', index=0)
self.insert_vert('gl_Position = vec4({{varout}}, 0., 1.);', 'after_transforms', index=0)
self.insert_vert('varying vec2 v_{{varout}};\n', 'header', index=0)
self.insert_frag('varying vec2 v_{{varout}};\n', 'header', index=0)
self.insert_vert('out vec2 v_{{varout}};\n', 'header', index=0)
self.insert_frag('in vec2 v_{{varout}};\n', 'header', index=0)

def _insert(self, shader_type, glsl, location, origin=None, index=None):
assert location in (
Expand Down Expand Up @@ -289,8 +289,8 @@ def insert_frag(self, glsl, location=None, origin=None, index=None):

def add_varying(self, vtype, name, value):
"""Add a varying variable."""
self.insert_vert('varying %s %s;' % (vtype, name), 'header')
self.insert_frag('varying %s %s;' % (vtype, name), 'header')
self.insert_vert('out %s %s;' % (vtype, name), 'header')
self.insert_frag('in %s %s;' % (vtype, name), 'header')
self.insert_vert('%s = %s;' % (name, value), 'end')

def add_gpu_transforms(self, tc):
Expand Down
4 changes: 0 additions & 4 deletions phy/plot/gloo/gl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ def enable_depth_mask():
glClearColor(0, 0, 0, 0) # noqa
glClearDepth(1.) # noqa

glEnable(GL_BLEND) # noqa
glDepthRange(0., 1.) # noqa
glDepthFunc(GL_EQUAL) # noqa
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # noqa

glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) # noqa
glEnable(GL_POINT_SPRITE) # noqa


# Patch: pythonize the glGetActiveAttrib
_glGetActiveAttrib = glGetActiveAttrib # noqa
Expand Down
12 changes: 6 additions & 6 deletions phy/plot/gloo/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Program(GLObject):

# ---------------------------------
def __init__(self, vertex=None, fragment=None, geometry=None,
count=0, version="120"):
count=0, version="410"):
"""
Initialize the program and optionnaly buffer.
"""
Expand Down Expand Up @@ -141,7 +141,7 @@ def hooks(self):

.. code:: C

attribute vec3 position;
in vec3 position;
void main () {
gl_Position = <transform>(position); # "transform" is a hook
}
Expand Down Expand Up @@ -506,8 +506,8 @@ def active_attributes(self):

.. code::

attribute vec3 normal; # Inactive
attribute vec3 position; # Active
in vec3 normal; # Inactive
in vec3 position; # Active
void main() {
gl_Position = vec4(position, 1.0);
}
Expand Down Expand Up @@ -552,8 +552,8 @@ def inactive_attributes(self):

.. code::

attribute vec3 normal; # Inactive
attribute vec3 position; # Active
in vec3 normal; # Inactive
in vec3 position; # Active
void main() {
gl_Position = vec4(position, 1.0);
}
Expand Down
13 changes: 7 additions & 6 deletions phy/plot/gloo/shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
.. code:: python

vertex = '''
attribute vec2 position;
in vec2 position;
void main (void)
{
gl_Position = vec4(0.85*position, 0.0, 1.0);
} '''
fragment = '''
out vec4 fragColor;
void main(void)
{
gl_FragColor = vec4(1.0,1.0,0.0,1.0);
fragColor = vec4(1.0,1.0,0.0,1.0);
} '''

quad = gloo.Program(vertex, fragment, count=4)
Expand Down Expand Up @@ -85,7 +86,7 @@ class Shader(GLObject):
'samplerCube': gl.GL_SAMPLER_CUBE,
}

def __init__(self, target, code, version="120"):
def __init__(self, target, code, version="410"):
"""
Initialize the shader.
"""
Expand Down Expand Up @@ -338,7 +339,7 @@ def attributes(self):
class VertexShader(Shader):
""" Vertex shader class """

def __init__(self, code=None, version="120"):
def __init__(self, code=None, version="410"):
Shader.__init__(self, gl.GL_VERTEX_SHADER, code, version)

@property
Expand All @@ -354,7 +355,7 @@ def __repr__(self):
class FragmentShader(Shader):
""" Fragment shader class """

def __init__(self, code=None, version="120"):
def __init__(self, code=None, version="410"):
Shader.__init__(self, gl.GL_FRAGMENT_SHADER, code, version)

@property
Expand Down Expand Up @@ -387,7 +388,7 @@ class GeometryShader(Shader):
"""

def __init__(self, code=None,
vertices_out=None, input_type=None, output_type=None, version="120"):
vertices_out=None, input_type=None, output_type=None, version="410"):
Shader.__init__(self, gl.GL_GEOMETRY_SHADER_EXT, code, version)

self._vertices_out = vertices_out
Expand Down
7 changes: 2 additions & 5 deletions phy/plot/gloo/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

...
fragment = '''
uniform sampler2D texture;
uniform sampler2D tex;
varying vec2 v_texcoord;
void main()
{
gl_FragColor = texture2D(texture, v_texcoord);
gl_FragColor = texture(texture, v_texcoord);
} '''

...
Expand Down Expand Up @@ -394,7 +394,6 @@ def _setup(self):
""" Setup texture on GPU """

Texture._setup(self)
gl.glEnable(gl.GL_TEXTURE_CUBE_MAP)
gl.glBindTexture(self.target, self._handle)
targets = [gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
Expand All @@ -411,7 +410,6 @@ def _update(self):
log.log(5, "GPU: Updating texture cube")

if self.need_update:
gl.glEnable(gl.GL_TEXTURE_CUBE_MAP)
gl.glBindTexture(self.target, self.handle)

targets = [gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
Expand Down Expand Up @@ -455,7 +453,6 @@ def _activate(self):
""" Activate texture on GPU """

log.log(5, "GPU: Activate texture cube")
gl.glEnable(gl.GL_TEXTURE_CUBE_MAP)
gl.glBindTexture(self.target, self._handle)
if self._need_setup:
self._setup()
Expand Down
2 changes: 1 addition & 1 deletion phy/plot/gloo/uniforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def code(self, prefix="u_"):
count, shift = _dtype[name], 0
while count:
if store == 0:
body += "\n _uniform = texture2D(u_uniforms, vec2(float(i++)/size_x,ty));\n"
body += "\n _uniform = texture(u_uniforms, vec2(float(i++)/size_x,ty));\n"
store = 4
if store == 4:
a = "xyzw"
Expand Down
40 changes: 31 additions & 9 deletions phy/plot/gloo/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@
.. code::

vertex = '''
attribute vec3 position;
in vec3 position;
void main (void)
{
gl_Position = vec4(position, 1.0);
} '''
fragment = '''
uniform vec4 color;
out vec4 fragColor;
void main(void)
{
gl_FragColor = color;
fragColor = color;
} '''
program = gloo.Program(vertex, fragment, count=4)
# program["position"] type is Attribute
Expand Down Expand Up @@ -363,14 +364,35 @@ def set_data(self, data):
self._generic = False

def _activate(self):
"""Activate the attribute ensuring proper GL state."""
if not self._active:
return

if isinstance(self.data, (VertexBuffer, VertexArray)):
self.data.activate()
size, gtype, dtype = gl_typeinfo[self._gtype]
stride = self.data.stride
offset = ctypes.c_void_p(self.data.offset)
gl.glEnableVertexAttribArray(self.handle)
gl.glVertexAttribPointer(
self.handle, size, gtype, gl.GL_FALSE, stride, offset)
# Early validation
if self.handle < 0:
log.debug("Skipping activation of attribute %s (invalid handle)", self.name)
return

try:
# 1. First bind the buffer
self.data.activate()

# 2. Get the attribute information
size, gtype, dtype = gl_typeinfo[self._gtype]
stride = self.data.stride
offset = ctypes.c_void_p(self.data.offset)

# 3. Set pointer before enabling
gl.glVertexAttribPointer(
self.handle, size, gtype, gl.GL_FALSE, stride, offset)

# 4. Enable the attribute array
gl.glEnableVertexAttribArray(self.handle)

except Exception as e:
log.error("Error activating attribute %s: %s", self.name, str(e))
raise

def _deactivate(self):
if isinstance(self.data, VertexBuffer):
Expand Down
6 changes: 4 additions & 2 deletions phy/plot/glsl/histogram.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
varying vec4 v_color;
out vec4 FragColor;

in vec4 v_color;

void main() {
gl_FragColor = v_color;
FragColor = v_color;
}
10 changes: 5 additions & 5 deletions phy/plot/glsl/histogram.vert
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "utils.glsl"

attribute vec2 a_position;
attribute float a_hist_index; // 0..n_hists-1
in vec2 a_position;
in float a_hist_index; // 0..n_hists-1

uniform sampler2D u_color;
uniform float n_hists;

varying vec4 v_color;
varying float v_hist_index;
out vec4 v_color;
out float v_hist_index;

void main() {
gl_Position = transform(a_position);

v_color = fetch_texture(a_hist_index, u_color, n_hists);
v_color = texture(u_color, vec2(a_hist_index / n_hists, 0.0));
v_hist_index = a_hist_index;
}
6 changes: 4 additions & 2 deletions phy/plot/glsl/image.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
uniform sampler2D u_tex;
varying vec2 v_tex_coords;
in vec2 v_tex_coords;

out vec4 FragColor;

void main() {
gl_FragColor = texture2D(u_tex, v_tex_coords);
FragColor = texture(u_tex, v_tex_coords);
}
6 changes: 3 additions & 3 deletions phy/plot/glsl/image.vert
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
attribute vec2 a_position;
attribute vec2 a_tex_coords;
in vec2 a_position;
in vec2 a_tex_coords;

varying vec2 v_tex_coords;
out vec2 v_tex_coords;

void main() {
gl_Position = transform(a_position);
Expand Down
6 changes: 4 additions & 2 deletions phy/plot/glsl/line.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
varying vec4 v_color;
out vec4 FragColor;

in vec4 v_color;

void main() {
gl_FragColor = v_color;
FragColor = v_color;
}
7 changes: 4 additions & 3 deletions phy/plot/glsl/line.vert
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
attribute vec2 a_position;
attribute vec4 a_color;
varying vec4 v_color;
in vec2 a_position;
in vec4 a_color;

out vec4 v_color;

void main() {
gl_Position = transform(a_position);
Expand Down
35 changes: 18 additions & 17 deletions phy/plot/glsl/line_agg_geom.frag
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
in vec2 v_texcoord;
in float v_length;
in vec2 v_caps;
in vec2 v_bevel_distance;

out vec4 FragColor;

uniform vec4 color;
uniform float antialias;
uniform float linewidth;
uniform float miter_limit;

vec4 stroke(float distance, float linewidth, float antialias, vec4 color)
{
vec4 frag_color;
Expand Down Expand Up @@ -41,30 +53,19 @@ vec4 cap(int type, float dx, float dy, float linewidth, float antialias, vec4 co
return stroke(d, linewidth, antialias, color);
}


uniform vec4 color;
uniform float antialias;
uniform float linewidth;
uniform float miter_limit;

varying float v_length;
varying vec2 v_caps;
varying vec2 v_texcoord;
varying vec2 v_bevel_distance;

void main()
{

float distance = v_texcoord.y;

if (v_caps.x < 0.0)
{
gl_FragColor = cap(1, v_texcoord.x, v_texcoord.y, linewidth, antialias, color);
FragColor = cap(1, v_texcoord.x, v_texcoord.y, linewidth, antialias, color);
return;
}
if (v_caps.y > v_length)
{
gl_FragColor = cap(1, v_texcoord.x-v_length, v_texcoord.y, linewidth, antialias, color);
FragColor = cap(1, v_texcoord.x - v_length, v_texcoord.y, linewidth, antialias, color);
return;
}

Expand All @@ -73,16 +74,16 @@ void main()
// else if(v_texcoord.x > v_length) { distance = length(v_texcoord - vec2(v_length, 0.0)); }

// Miter limit
float t = (miter_limit-1.0)*(linewidth/2.0) + antialias;
float t = (miter_limit - 1.0) * (linewidth / 2.0) + antialias;

if( (v_texcoord.x < 0.0) && (v_bevel_distance.x > (abs(distance) + t)) )
if ((v_texcoord.x < 0.0) && (v_bevel_distance.x > (abs(distance) + t)))
{
distance = v_bevel_distance.x - t;
}
else if( (v_texcoord.x > v_length) && (v_bevel_distance.y > (abs(distance) + t)) )
else if ((v_texcoord.x > v_length) && (v_bevel_distance.y > (abs(distance) + t)))
{
distance = v_bevel_distance.y - t;
}
gl_FragColor = stroke(distance, linewidth, antialias, color);

FragColor = stroke(distance, linewidth, antialias, color);
}
Loading