diff --git a/examples/adapter_info.py b/examples/adapter_info.py index aea44f1..75e4dbf 100644 --- a/examples/adapter_info.py +++ b/examples/adapter_info.py @@ -18,6 +18,7 @@ def main(): for f in features: print(f.name) + t0 = time.time() main() dt = time.time() - t0 diff --git a/examples/glfw_window.py b/examples/glfw_window.py index 12b1ba7..c870245 100644 --- a/examples/glfw_window.py +++ b/examples/glfw_window.py @@ -30,9 +30,9 @@ def is_wayland(): def get_linux_window(window): if is_wayland(): - return int(glfw.get_wayland_window(window)) + return glfw.get_wayland_window(window) else: - return int(glfw.get_x11_window(window)) + return glfw.get_x11_window(window) def get_linux_display(): @@ -50,7 +50,7 @@ def get_linux_display(): def get_handles(window): - for (prefix, maker) in WINDOW_GETTERS: + for prefix, maker in WINDOW_GETTERS: if sys.platform.lower().startswith(prefix): win_getter, display_getter = maker() return (win_getter(window), display_getter()) @@ -61,7 +61,9 @@ class GLFWWindow: def __init__(self, w: int, h: int, title="xgpu"): self.width = w self.height = h - glfw.init() + if is_wayland(): + glfw.init_hint(glfw.PLATFORM, glfw.PLATFORM_WAYLAND) + print("GLFW init:", glfw.init()) glfw.window_hint(glfw.CLIENT_API, glfw.NO_API) glfw.window_hint(glfw.RESIZABLE, True) # see https://github.com/FlorianRhiem/pyGLFW/issues/42 @@ -70,6 +72,8 @@ def __init__(self, w: int, h: int, title="xgpu"): glfw.window_hint(glfw.FOCUSED, False) # prevent Wayland focus error self.window = glfw.create_window(w, h, title, None, None) (self.window_handle, self.display_id) = get_handles(self.window) + print("window:", self.window_handle) + print("display:", self.display_id) self._surface = None self._surf_config = None @@ -77,7 +81,7 @@ def poll(self) -> bool: glfw.poll_events() return bool(not glfw.window_should_close(self.window)) - def configure_surface(self, device: Device): + def configure_surface(self, device: Device, format=xgpu.TextureFormat.BGRA8Unorm): print("Configuring surface?") if self._surface is None: return @@ -85,12 +89,12 @@ def configure_surface(self, device: Device): self._surf_config = xgpu.surfaceConfiguration( device=device, usage=xgpu.TextureUsageFlags([xgpu.TextureUsage.RenderAttachment]), - viewFormats=[xgpu.TextureFormat.RGBA8Unorm], - format=xgpu.TextureFormat.RGBA8Unorm, + viewFormats=[format], + format=format, alphaMode=xgpu.CompositeAlphaMode.Auto, width=self.width, height=self.height, - presentMode=xgpu.PresentMode.Fifo + presentMode=xgpu.PresentMode.Fifo, ) self._surf_config.width = self.width self._surf_config.height = self.height @@ -102,6 +106,7 @@ def get_surface(self, instance: Instance) -> Surface: if self._surface is not None: return self._surface desc = self.get_surface_descriptor() + print("Got surface descriptor?") self._surface = instance.createSurfaceFromDesc(desc) print("Got surface?") return self._surface @@ -113,13 +118,15 @@ def get_surface_descriptor(self) -> SurfaceDescriptor: hwnd=cast_any_to_void(self.window_handle), ) elif sys.platform.startswith("linux"): # no-cover - if is_wayland: + if is_wayland(): + print("WAYLAND???") # todo: wayland seems to be broken right now inner = xgpu.surfaceDescriptorFromWaylandSurface( display=cast_any_to_void(self.display_id), surface=cast_any_to_void(self.window_handle), ) else: + print("XLIB????") inner = xgpu.surfaceDescriptorFromXlibWindow( display=cast_any_to_void(self.display_id), window=self.window_handle ) diff --git a/examples/triangle_offscreen.py b/examples/triangle_offscreen.py index cb977af..e70184e 100644 --- a/examples/triangle_offscreen.py +++ b/examples/triangle_offscreen.py @@ -48,6 +48,7 @@ } """ + def main(power_preference=xg.PowerPreference.HighPerformance): t0 = time.time() (adapter, _) = get_adapter(instance=None, power=power_preference) @@ -67,9 +68,7 @@ def _main(device: xg.Device): HEIGHT = 1024 shader = device.createShaderModule( - nextInChain=xg.ChainedStruct( - [xg.shaderModuleWGSLDescriptor(code=shader_source)] - ), + nextInChain=xg.ChainedStruct([xg.shaderModuleWGSLDescriptor(code=shader_source)]), hints=[], ) @@ -88,9 +87,7 @@ def _main(device: xg.Device): topology=xg.PrimitiveTopology.TriangleList, stripIndexFormat=xg.IndexFormat.Undefined, ) - vertex = xg.vertexState( - module=shader, entryPoint="vs_main", constants=[], buffers=[] - ) + vertex = xg.vertexState(module=shader, entryPoint="vs_main", constants=[], buffers=[]) color_target = xg.colorTargetState( format=xg.TextureFormat.RGBA8Unorm, writeMask=xg.ColorWriteMaskFlags([xg.ColorWriteMask.All]), diff --git a/examples/triangle_windowed.py b/examples/triangle_windowed.py index ae72ea6..c02da2f 100644 --- a/examples/triangle_windowed.py +++ b/examples/triangle_windowed.py @@ -46,6 +46,7 @@ } """ + def main(): WIDTH = 1024 HEIGHT = 1024 @@ -57,12 +58,14 @@ def main(): (adapter, _) = get_adapter(instance, xg.PowerPreference.HighPerformance, surface) device = get_device(adapter) - window.configure_surface(device) + window_tex_format = xg.TextureFormat.BGRA8Unorm + # surface.getPreferredFormat(adapter) + print("Window tex format:", window_tex_format.name) + + window.configure_surface(device, window_tex_format) shader = device.createShaderModule( - nextInChain=xg.ChainedStruct( - [xg.shaderModuleWGSLDescriptor(code=shader_source)] - ), + nextInChain=xg.ChainedStruct([xg.shaderModuleWGSLDescriptor(code=shader_source)]), hints=[], ) @@ -80,11 +83,9 @@ def main(): frontFace=xg.FrontFace.CCW, cullMode=xg.CullMode._None, ) - vertex = xg.vertexState( - module=shader, entryPoint="vs_main", constants=[], buffers=[] - ) + vertex = xg.vertexState(module=shader, entryPoint="vs_main", constants=[], buffers=[]) color_target = xg.colorTargetState( - format=xg.TextureFormat.RGBA8Unorm, + format=window_tex_format, blend=xg.blendState(color=REPLACE, alpha=REPLACE), writeMask=xg.ColorWriteMask.All, ) @@ -111,10 +112,10 @@ def main(): print("Tex status?", surf_tex.status.name) color_view = surf_tex.texture.createView( - format = xg.TextureFormat.RGBA8Unorm, + format=xg.TextureFormat.Undefined, dimension=xg.TextureViewDimension._2D, mipLevelCount=1, - arrayLayerCount=1 + arrayLayerCount=1, ) color_attachment = xg.renderPassColorAttachment(