Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:compiles and runs again but seems broken
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f41568d116a6beb9b7b2c92b0fe415c0906ca11c2c12c097e4dfd510c17b7313
User & Date: mlatu 2023-06-05 20:50:48
Context
2023-06-08
16:58
glfwWindowShouldClose returns boolean i guess and i simply had to wrap it check-in: 401cf073b4 user: mlatu tags: trunk
2023-06-05
20:50
compiles and runs again but seems broken check-in: f41568d116 user: mlatu tags: trunk
2023-06-04
13:25
added header files check-in: 3a6cc1dd56 user: mlatu tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Name change from glfw3webgpu/glfw3webgpu.c to glfw3webgpu/glfw3webgpu.cpp.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "glfw3webgpu.h"

#include <webgpu/webgpu.h>

#define WGPU_TARGET_MACOS 1
#define WGPU_TARGET_LINUX_X11 2
#define WGPU_TARGET_WINDOWS 3
#define WGPU_TARGET_LINUX_WAYLAND 4







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "glfw3webgpu.hpp"

#include <webgpu/webgpu.h>

#define WGPU_TARGET_MACOS 1
#define WGPU_TARGET_LINUX_X11 2
#define WGPU_TARGET_WINDOWS 3
#define WGPU_TARGET_LINUX_WAYLAND 4
68
69
70
71
72
73
74













75
76
77
78
79
80
81
82
83
84
85
86
87

88
89

90
91
92
93
94













95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115













116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137











138



139
140
141
142
143
144
145
146
147
148
149
150
151
152

153

154
155
156
157
158
159
#if WGPU_TARGET == WGPU_TARGET_MACOS
    {
        id metal_layer = NULL;
        NSWindow* ns_window = glfwGetCocoaWindow(window);
        [ns_window.contentView setWantsLayer : YES] ;
        metal_layer = [CAMetalLayer layer];
        [ns_window.contentView setLayer : metal_layer] ;













        return wgpuInstanceCreateSurface(
            instance,
            &(WGPUSurfaceDescriptor){
            .label = NULL,
                .nextInChain =
                (const WGPUChainedStruct*)&(
                    WGPUSurfaceDescriptorFromMetalLayer) {
                .chain =
                    (WGPUChainedStruct){
                        .next = NULL,
                        .sType = WGPUSType_SurfaceDescriptorFromMetalLayer,
                },
                .layer = metal_layer,

            },
        });

    }
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
    {
        Display* x11_display = glfwGetX11Display();
        Window x11_window = glfwGetX11Window(window);













        return wgpuInstanceCreateSurface(
            instance,
            &(WGPUSurfaceDescriptor){
            .label = NULL,
                .nextInChain =
                (const WGPUChainedStruct*)&(
                    WGPUSurfaceDescriptorFromXlibWindow) {
                .chain =
                    (WGPUChainedStruct){
                        .next = NULL,
                        .sType = WGPUSType_SurfaceDescriptorFromXlibWindow,
                },
                .display = x11_display,
                .window = x11_window,
            },
        });

    }
#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND
    {
        struct wl_display* wayland_display = glfwGetWaylandDisplay();
        struct wl_surface* wayland_surface = glfwGetWaylandWindow(window);













        return wgpuInstanceCreateSurface(
            instance,
            &(WGPUSurfaceDescriptor){
            .label = NULL,
                .nextInChain =
                (const WGPUChainedStruct*)&(
                    WGPUSurfaceDescriptorFromWaylandSurface) {
                .chain =
                    (WGPUChainedStruct){
                        .next = NULL,
                        .sType =
                            WGPUSType_SurfaceDescriptorFromWaylandSurface,
},
.display = wayland_display,
.surface = wayland_surface,
                },
        });

  }
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
    {
        HWND hwnd = glfwGetWin32Window(window);
        HINSTANCE hinstance = GetModuleHandle(NULL);











        return wgpuInstanceCreateSurface(



            instance,
            &(WGPUSurfaceDescriptor){
            .label = NULL,
                .nextInChain =
                (const WGPUChainedStruct*)&(
                    WGPUSurfaceDescriptorFromWindowsHWND) {
                .chain =
                    (WGPUChainedStruct){
                        .next = NULL,
                        .sType = WGPUSType_SurfaceDescriptorFromWindowsHWND,
            },
            .hinstance = hinstance,
            .hwnd = hwnd,
        },

    });

  }
#else
#error "Unsupported WGPU_TARGET"
#endif
}








>
>
>
>
>
>
>
>
>
>
>
>
>













>


>





>
>
>
>
>
>
>
>
>
>
>
>
>
















>





>
>
>
>
>
>
>
>
>
>
>
>
>










<
|
|
|
|
|
|
>





>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
|
|
|
|
<
|
|
|
|

|
|

>
|
>






68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#if WGPU_TARGET == WGPU_TARGET_MACOS
    {
        id metal_layer = NULL;
        NSWindow* ns_window = glfwGetCocoaWindow(window);
        [ns_window.contentView setWantsLayer : YES] ;
        metal_layer = [CAMetalLayer layer];
        [ns_window.contentView setLayer : metal_layer] ;
        
        WGPUSurfaceDescriptorFromMetalLayer nativeChainedStruct;
        WGPUChainedStruct generalChainedStruct;
        generalChainedStruct.next = NULL;
        generalChainedStruct.sType = WGPUSType_SurfaceDescriptorFromMetalLayer;
        nativeChainedStruct.chain = generalChainedStruct;
        nativeChainedStruct.layer = metal_layer;
        ///////////////////////////////////////
        WGPUSurfaceDescriptor desc;
        desc.label = NULL;
        desc.nextInChain = (const WGPUChainedStruct*)&nativeChainedStruct;
        return wgpuInstanceCreateSurface(instance, &desc);
/*
        return wgpuInstanceCreateSurface(
            instance,
            &(WGPUSurfaceDescriptor){
            .label = NULL,
                .nextInChain =
                (const WGPUChainedStruct*)&(
                    WGPUSurfaceDescriptorFromMetalLayer) {
                .chain =
                    (WGPUChainedStruct){
                        .next = NULL,
                        .sType = WGPUSType_SurfaceDescriptorFromMetalLayer,
                },
                .layer = metal_layer,
                /////////////////////
            },
        });
        */
    }
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
    {
        Display* x11_display = glfwGetX11Display();
        Window x11_window = glfwGetX11Window(window);
        
        WGPUSurfaceDescriptorFromXlibWindow nativeChainedStruct;
        WGPUChainedStruct generalChainedStruct;
        generalChainedStruct.next = NULL;
        generalChainedStruct.sType = WGPUSType_SurfaceDescriptorFromXlibWindow;
        nativeChainedStruct.chain = generalChainedStruct;
        nativeChainedStruct.display = x11_display;
        nativeChainedStruct.window = x11_window;
        WGPUSurfaceDescriptor desc;
        desc.label = NULL;
        desc.nextInChain = (const WGPUChainedStruct*)&nativeChainedStruct;
        return wgpuInstanceCreateSurface(instance, &desc);
/*
        return wgpuInstanceCreateSurface(
            instance,
            &(WGPUSurfaceDescriptor){
            .label = NULL,
                .nextInChain =
                (const WGPUChainedStruct*)&(
                    WGPUSurfaceDescriptorFromXlibWindow) {
                .chain =
                    (WGPUChainedStruct){
                        .next = NULL,
                        .sType = WGPUSType_SurfaceDescriptorFromXlibWindow,
                },
                .display = x11_display,
                .window = x11_window,
            },
        });
        */
    }
#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND
    {
        struct wl_display* wayland_display = glfwGetWaylandDisplay();
        struct wl_surface* wayland_surface = glfwGetWaylandWindow(window);
        
        WGPUSurfaceDescriptorFromWaylandSurface nativeChainedStruct;
        WGPUChainedStruct generalChainedStruct;
        generalChainedStruct.next = NULL;
        generalChainedStruct.sType = WGPUSType_SurfaceDescriptorFromWaylandSurface;
        nativeChainedStruct.chain = generalChainedStruct;
        nativeChainedStruct.display = wayland_display;
        nativeChainedStruct.surface = wayland_surface;
        WGPUSurfaceDescriptor desc;
        desc.label = NULL;
        desc.nextInChain = (const WGPUChainedStruct*)&nativeChainedStruct;
        return wgpuInstanceCreateSurface(instance, &desc);
/*
        return wgpuInstanceCreateSurface(
            instance,
            &(WGPUSurfaceDescriptor){
            .label = NULL,
                .nextInChain =
                (const WGPUChainedStruct*)&(
                    WGPUSurfaceDescriptorFromWaylandSurface) {
                .chain =
                    (WGPUChainedStruct){
                        .next = NULL,

                        .sType = WGPUSType_SurfaceDescriptorFromWaylandSurface,
              },
              .display = wayland_display,
              .surface = wayland_surface,
            },
    });
    */
  }
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
    {
        HWND hwnd = glfwGetWin32Window(window);
        HINSTANCE hinstance = GetModuleHandle(NULL);
        
        WGPUSurfaceDescriptorFromWindowsHWND nativeChainedStruct;
        WGPUChainedStruct generalChainedStruct;
        generalChainedStruct.next = NULL;
        generalChainedStruct.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND;
        nativeChainedStruct.chain = generalChainedStruct;
        nativeChainedStruct.hinstance = hinstance;
        nativeChainedStruct.hwnd = hwnd;
        WGPUSurfaceDescriptor desc;
        desc.label = NULL;
        desc.nextInChain = (const WGPUChainedStruct*)&nativeChainedStruct;
        return wgpuInstanceCreateSurface(instance, &desc);
/*
return
  wgpuInstanceCreateSurface(
    instance,
    &(WGPUSurfaceDescriptor) {
      .label = NULL,
      .nextInChain =
        (const WGPUChainedStruct*)&(WGPUSurfaceDescriptorFromWindowsHWND) {

          .chain =
            (WGPUChainedStruct) {
              .next = NULL,
              .sType = WGPUSType_SurfaceDescriptorFromWindowsHWND,
            },
          .hinstance = hinstance,
          .hwnd = hwnd,
        },
      }
      );*/
    
  }
#else
#error "Unsupported WGPU_TARGET"
#endif
}

Name change from glfw3webgpu/glfw3webgpu.h to glfw3webgpu/glfw3webgpu.hpp.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef _glfw3_webgpu_h_
#define _glfw3_webgpu_h_

#include <webgpu/webgpu.h>
#include <GLFW/glfw3.h>

#ifdef __cplusplus
extern "C" {
#endif

/**







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef _glfw3_webgpu_h_
#define _glfw3_webgpu_h_

#include <webgpu/webgpu.hpp>
#include <GLFW/glfw3.h>

#ifdef __cplusplus
extern "C" {
#endif

/**

Changes to jake.bat.

8
9
10
11
12
13
14

15
16

echo gen
call jpm run gen

echo build
call jpm build


echo test
call jpm test







>


8
9
10
11
12
13
14
15
16
17

echo gen
call jpm run gen

echo build
call jpm build

set RUST_BACKTRACE=full
echo test
call jpm test

Changes to project.janet.

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
 :cppflags [;default-cflags
          ;cflags]
 
 :defines os-defines

 :source ["src/glfw.gen.cpp"
          "glfw3webgpu/glfw3webgpu.c"]
 :headers ["src/glfw.aux.hpp"
           "glfw3webgpu/glfw3webgpu.h"
           "glfw/include/GLFW/glfw3.h"
           "webgpu-release/include/webgpu/webgpu-release.h"
           "WebGPU-distribution-wgpu/include/webgpu/webgpu.h"
           "WebGPU-distribution-wgpu/include/webgpu/wgpu.h"]
 
 :lflags [;default-lflags
          ;lflags])







|

|







98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
 :cppflags [;default-cflags
          ;cflags]
 
 :defines os-defines

 :source ["src/glfw.gen.cpp"
          "glfw3webgpu/glfw3webgpu.cpp"]
 :headers ["src/glfw.aux.hpp"
           "glfw3webgpu/glfw3webgpu.hpp"
           "glfw/include/GLFW/glfw3.h"
           "webgpu-release/include/webgpu/webgpu-release.h"
           "WebGPU-distribution-wgpu/include/webgpu/webgpu.h"
           "WebGPU-distribution-wgpu/include/webgpu/wgpu.h"]
 
 :lflags [;default-lflags
          ;lflags])

Changes to src/glfw.aux.hpp.

1
2
3
4
5
6
7
8
9
10
11
12
#include <janet.h>
#include <GLFW/glfw3.h>
#include <webgpu/webgpu.h>
#include <webgpu/webgpu-release.h>
#include <glfw3webgpu.h>

template <typename T>
T unwrap_wgpu(Janet wgpuHandle) {
  return (T)(janet_unwrap_u64(wgpuHandle));
}

template <typename T>




|







1
2
3
4
5
6
7
8
9
10
11
12
#include <janet.h>
#include <GLFW/glfw3.h>
#include <webgpu/webgpu.h>
#include <webgpu/webgpu-release.h>
#include <glfw3webgpu.hpp>

template <typename T>
T unwrap_wgpu(Janet wgpuHandle) {
  return (T)(janet_unwrap_u64(wgpuHandle));
}

template <typename T>

Changes to src/glfw.janet.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#  (c/include <webgpu/webgpu.h>)
#  see define in project.janet
#  (c/include <webgpu/webgpu-release.h>)
  
  (c/include "\"glfw.aux.hpp\"")
  #######################################
  
  (macex1 '(c/cfunction init
    :static
    ```Initializes the GLFW context,
    run once to setup the library.

    returns false on failure
    see: https://www.glfw.org/docs/latest/intro_guide.html#error_handling```
    [] -> :int
      (return (glfwInit))))
  ##################

  (macex1 '(c/cfunction terminate
    :static
    ```Terminates the GLFW context,
    run once to shutdown the context.
    If you need GLFW afterwards, call init again to start it back up.

    If init failed, this does not have to be called.








|










|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#  (c/include <webgpu/webgpu.h>)
#  see define in project.janet
#  (c/include <webgpu/webgpu-release.h>)
  
  (c/include "\"glfw.aux.hpp\"")
  #######################################
  
  (macex1 '(c/cfunction initialize-context
    :static
    ```Initializes the GLFW context,
    run once to setup the library.

    returns false on failure
    see: https://www.glfw.org/docs/latest/intro_guide.html#error_handling```
    [] -> :int
      (return (glfwInit))))
  ##################

  (macex1 '(c/cfunction terminate-context
    :static
    ```Terminates the GLFW context,
    run once to shutdown the context.
    If you need GLFW afterwards, call init again to start it back up.

    If init failed, this does not have to be called.

99
100
101
102
103
104
105

106












107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  
  (macex1 '(c/cfunction poll-events
    :static
    "polls for events"
    [] -> :Janet
      (glfwPollEvents)
      (return (janet_wrap_nil))))

  #######################################













  (macex1 '(c/cfunction wgpu-get-instance
    :static
    "returns a new wgpu instance which needs to be released via wgpu-release-instance"
    [] -> :Janet
      (def (desc WGPUInstanceDescriptor))
      (set desc.nextInChain NULL)
      (return (wrap_wgpu<WGPUInstance> (wgpuCreateInstance &desc)))))
   ###################

  (macex1 '(c/cfunction wgpu-release-instance
    :static
    "releases or drops the instance"
    [instance:Janet] -> :Janet
      (wgpuInstanceRelease (unwrap_wgpu<WGPUInstance> instance))
      (return (janet_wrap_nil))))
  ########################################
  
  (macex1 '(c/cfunction wgpu-get-surface
    :static
    "uses a WGPUInstance and GLFWwindow to create a WGPUSurface which needs to be released via wgpu-release-surface"
    [instance:Janet window:pointer] -> :Janet
      (return
        (wrap_wgpu<WGPUSurface>
          (glfwGetWGPUSurface
            (unwrap_wgpu<WGPUInstance> instance)
            (cast GLFWwindow* window))))))
  ###################

  (macex1 '(c/cfunction wgpu-release-surface
    :static
    "releases or drops the surface"
    [surface:Janet] -> :Janet
      (wgpuSurfaceRelease (unwrap_wgpu<WGPUSurface> surface))
      (return (janet_wrap_nil))))







>

>
>
>
>
>
>
>
>
>
>
>
>

|















<
<
<
<
<
<
<
<
<
<
<







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136











137
138
139
140
141
142
143
  
  (macex1 '(c/cfunction poll-events
    :static
    "polls for events"
    [] -> :Janet
      (glfwPollEvents)
      (return (janet_wrap_nil))))

  #######################################
  (macex1 '(c/cfunction get-wgpu-surface
    :static
    "uses a WGPUInstance and GLFWwindow to create a WGPUSurface which needs to be released via wgpu-release-surface"
    [instance:Janet window:pointer] -> :Janet
      (return
        (wrap_wgpu<WGPUSurface>
          (glfwGetWGPUSurface
            (unwrap_wgpu<WGPUInstance> instance)
            (cast GLFWwindow* window))))))
  ###################
  # WGPU ahead
  #######################################

  (macex1 '(c/cfunction wgpu-create-instance
    :static
    "returns a new wgpu instance which needs to be released via wgpu-release-instance"
    [] -> :Janet
      (def (desc WGPUInstanceDescriptor))
      (set desc.nextInChain NULL)
      (return (wrap_wgpu<WGPUInstance> (wgpuCreateInstance &desc)))))
   ###################

  (macex1 '(c/cfunction wgpu-release-instance
    :static
    "releases or drops the instance"
    [instance:Janet] -> :Janet
      (wgpuInstanceRelease (unwrap_wgpu<WGPUInstance> instance))
      (return (janet_wrap_nil))))
  ########################################












  (macex1 '(c/cfunction wgpu-release-surface
    :static
    "releases or drops the surface"
    [surface:Janet] -> :Janet
      (wgpuSurfaceRelease (unwrap_wgpu<WGPUSurface> surface))
      (return (janet_wrap_nil))))
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
    ""
    [swapChain:Janet] -> :Janet
      (wgpuSwapChainPresent
        (unwrap_wgpu<WGPUSwapChain> swapChain))
      (return (janet_wrap_nil))))

#textureview
  (macex1 '(c/cfunction wgpu-swapchain-create-next-textureview
    :static
    ""
    [swapChain:Janet] -> :Janet
      (return
        (wrap_wgpu<WGPUTextureView>
          (wgpuSwapChainGetCurrentTextureView
            (unwrap_wgpu<WGPUSwapChain>
              swapChain))))))

  (macex1 '(c/cfunction wgpu-release-textureview
    :static
    ""
    [textureview:Janet] -> :Janet
      (wgpuTextureViewRelease
        (unwrap_wgpu<WGPUTextureView> textureview))
      (return (janet_wrap_nil))))

(macex1 '(c/cfunction wgpu-create-example-renderpass
    :static
    ""
    [encoder:Janet nextTexture:Janet clear_color:table] -> :Janet
      #renderPassColorAttachment
      (def (renderPassColorAttachment WGPURenderPassColorAttachment))
      # The attachment is tied to the view returned by the swapchain, so that
      # the render pass draws directly on screen.







|

















|







303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
    ""
    [swapChain:Janet] -> :Janet
      (wgpuSwapChainPresent
        (unwrap_wgpu<WGPUSwapChain> swapChain))
      (return (janet_wrap_nil))))

#textureview
  (macex1 '(c/cfunction wgpu-swapchain-get-current-textureview
    :static
    ""
    [swapChain:Janet] -> :Janet
      (return
        (wrap_wgpu<WGPUTextureView>
          (wgpuSwapChainGetCurrentTextureView
            (unwrap_wgpu<WGPUSwapChain>
              swapChain))))))

  (macex1 '(c/cfunction wgpu-release-textureview
    :static
    ""
    [textureview:Janet] -> :Janet
      (wgpuTextureViewRelease
        (unwrap_wgpu<WGPUTextureView> textureview))
      (return (janet_wrap_nil))))

(macex1 '(c/cfunction wgpu-get-example-renderpass
    :static
    ""
    [encoder:Janet nextTexture:Janet clear_color:table] -> :Janet
      #renderPassColorAttachment
      (def (renderPassColorAttachment WGPURenderPassColorAttachment))
      # The attachment is tied to the view returned by the swapchain, so that
      # the render pass draws directly on screen.
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
28-05-2023
https://eliemichel.github.io/LearnWebGPU/getting-started/the-command-queue.html
@993:
As of now, the wgpuQueueOnSubmittedWorkDone is not implemented by our wgpu-native backend. Using it will result in a null pointer exception so do not copy the above code block.
```
  )

  (macex1 '(c/cfunction wgpu-surface-create-preferred-format
    :static
    ""
    [surface:Janet adapter:Janet] -> :Janet
      (return
        (wrap_wgpu<WGPUTextureFormat>
          (wgpuSurfaceGetPreferredFormat
            (unwrap_wgpu<WGPUSurface> surface)







|







446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
28-05-2023
https://eliemichel.github.io/LearnWebGPU/getting-started/the-command-queue.html
@993:
As of now, the wgpuQueueOnSubmittedWorkDone is not implemented by our wgpu-native backend. Using it will result in a null pointer exception so do not copy the above code block.
```
  )

  (macex1 '(c/cfunction wgpu-surface-get-preferred-format
    :static
    ""
    [surface:Janet adapter:Janet] -> :Janet
      (return
        (wrap_wgpu<WGPUTextureFormat>
          (wgpuSurfaceGetPreferredFormat
            (unwrap_wgpu<WGPUSurface> surface)

Changes to test/test0.janet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
(use ../build/wjpu)
(import spork/test :as test)

(init)

(def GLFW_CLIENT_API 0x00022001)
(def GLFW_NO_API 0)

(hint-next-window GLFW_CLIENT_API GLFW_NO_API)

(def window (create-window 200 200 "welcome window"))
(unless window
  (terminate)
  (error "could not create window"))

(def winstance (wgpu-get-instance))
(wgpu-release-instance winstance)

(def wgpu-instance (wgpu-create-instance))
(unless wgpu-instance
  (destroy-window window)
  (terminate)
  (error "could not create instance"))

(def wgpu-surface (wgpu-create-surface wgpu-instance window))
(unless wgpu-surface
  (wgpu-destroy-instance wgpu-instance)
  (destroy-window window)
  (terminate)
  (error "could not create surface"))

(def wgpu-adapter (wgpu-create-adapter wgpu-instance wgpu-surface))
(unless wgpu-adapter
  (wgpu-destroy-surface wgpu-surface)
  (wgpu-destroy-instance wgpu-instance)
  (destroy-window window)
  (terminate)
  (error "could not create adapter"))

(printf "Found %q features" (wgpu-inspect-adapter wgpu-adapter))
#(wgpu-inspect-adapter wgpu-adapter)

(def wgpu-device (wgpu-create-device wgpu-adapter))
(unless wgpu-device
  (if wgpu-adapter
    (wgpu-destroy-adapter wgpu-adapter)
    (pp "adapter already gone"))
  (if wgpu-surface
    (wgpu-destroy-surface wgpu-surface)
    (pp "surface already gone"))
  (if wgpu-instance
    (wgpu-destroy-instance wgpu-instance)
    (pp "instance already gone"))
  (if window
    (destroy-window window)
    (pp "window already gone"))
  (terminate)
  (error "could not create device"))

(wgpu-device-set-uncaptured-error-callback wgpu-device)

(def wgpu-queue (wgpu-device-create-queue wgpu-device))



(def wgpu-swapchain (wgpu-device-create-swapchain wgpu-device wgpu-adapter wgpu-surface))

(var cmdbuff (create-command-buffer))

(def clear-color
  @{:r (math/random)
    :g (math/random)
    :b (math/random)
    :a 1.0})

(var nextTexture 0)
(var wgpu-commandencoder 0)
(var renderPass 0)

(test/timeit
  (while (not (close-window? window))
  ##(print "poll")
    (poll-events)
  ##(print "poll done")
  ##(print "T")
    (set nextTexture (wgpu-swapchain-create-next-textureview wgpu-swapchain))
    # Getting the texture may fail, in particular if the window has been resized
    # and thus the target surface changed.
    (when (nil? nextTexture)
      (printf "Cannot acquire next swap chain texture")
      (break))
  ##(print "E")
    (set wgpu-commandencoder (wgpu-device-create-command-encoder wgpu-device))

    (put clear-color :r (math/random))
    (put clear-color :g (math/random))
    (put clear-color :b (math/random))

  #(print "P")
    (set renderPass (wgpu-create-example-renderpass wgpu-commandencoder nextTexture clear-color))
  #(print "hellobug")
    (wgpu-render-pass-encoder-end renderPass)
  ##(print "D")
    (wgpu-destroy-textureview nextTexture)
  ###(print "debug")
    (wgpu-command-encoder-insert-debug-marker wgpu-commandencoder "hello world")
  ##(print "finish")
    (set cmdbuff (wgpu-command-encoder-finish-ref wgpu-commandencoder cmdbuff))

  ##(print "submit")
    (wgpu-queue-submit wgpu-queue 1 cmdbuff)
  ##(print "present")
    (wgpu-swapchain-present wgpu-swapchain)
  ##(print "presented")
    ))

(print "out of while")
(destroy-command-buffer cmdbuff)

(wgpu-destroy-queue wgpu-queue)
(if wgpu-swapchain
  (wgpu-destroy-swapchain wgpu-swapchain)
  (pp "swapchain already gone"))
(if wgpu-device
  (wgpu-destroy-device wgpu-device)
  (pp "device already gone"))
(if wgpu-adapter
  (wgpu-destroy-adapter wgpu-adapter)
  (pp "adapter already gone"))
(if wgpu-surface
  (wgpu-destroy-surface wgpu-surface)
  (pp "surface already gone"))
(if wgpu-instance
  (wgpu-destroy-instance wgpu-instance)
  (pp "instance already gone"))
(if window
  (destroy-window window)
  (pp "window already gone"))

(terminate)



|








|


<
<
<



|


|

|

|


|

|
|

|





|


|


|


|




|




|
>
>



<
<
















|






|






|



|



|









<

<

|


|


|


|


|





|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(use ../build/wjpu)
(import spork/test :as test)

(initialize-context)

(def GLFW_CLIENT_API 0x00022001)
(def GLFW_NO_API 0)

(hint-next-window GLFW_CLIENT_API GLFW_NO_API)

(def window (create-window 200 200 "welcome window"))
(unless window
  (terminate-context)
  (error "could not create window"))




(def wgpu-instance (wgpu-create-instance))
(unless wgpu-instance
  (destroy-window window)
  (terminate-context)
  (error "could not create instance"))

(def wgpu-surface (get-wgpu-surface wgpu-instance window))
(unless wgpu-surface
  (wgpu-release-instance wgpu-instance)
  (destroy-window window)
  (terminate-context)
  (error "could not create surface"))

(def wgpu-adapter (wgpu-get-adapter wgpu-instance wgpu-surface))
(unless wgpu-adapter
  (wgpu-release-surface wgpu-surface)
  (wgpu-release-instance wgpu-instance)
  (destroy-window window)
  (terminate-context)
  (error "could not create adapter"))

(printf "Found %q features" (wgpu-inspect-adapter wgpu-adapter))
#(wgpu-inspect-adapter wgpu-adapter)

(def wgpu-device (wgpu-get-device wgpu-adapter))
(unless wgpu-device
  (if wgpu-adapter
    (wgpu-release-adapter wgpu-adapter)
    (pp "adapter already gone"))
  (if wgpu-surface
    (wgpu-release-surface wgpu-surface)
    (pp "surface already gone"))
  (if wgpu-instance
    (wgpu-release-instance wgpu-instance)
    (pp "instance already gone"))
  (if window
    (destroy-window window)
    (pp "window already gone"))
  (terminate-context)
  (error "could not create device"))

(wgpu-device-set-uncaptured-error-callback wgpu-device)

(def wgpu-queue (wgpu-device-get-queue wgpu-device))

(print "wgpu-device-set-uncaptured-error-callback wgpu-device")

(def wgpu-swapchain (wgpu-device-create-swapchain wgpu-device wgpu-adapter wgpu-surface))



(def clear-color
  @{:r (math/random)
    :g (math/random)
    :b (math/random)
    :a 1.0})

(var nextTexture 0)
(var wgpu-commandencoder 0)
(var renderPass 0)

(test/timeit
  (while (not (close-window? window))
  ##(print "poll")
    (poll-events)
  ##(print "poll done")
  ##(print "T")
    (def nextTexture (wgpu-swapchain-get-current-textureview wgpu-swapchain))
    # Getting the texture may fail, in particular if the window has been resized
    # and thus the target surface changed.
    (when (nil? nextTexture)
      (printf "Cannot acquire next swap chain texture")
      (break))
  ##(print "E")
    (def wgpu-commandencoder (wgpu-device-create-command-encoder wgpu-device))

    (put clear-color :r (math/random))
    (put clear-color :g (math/random))
    (put clear-color :b (math/random))

  #(print "P")
    (def renderPass (wgpu-get-example-renderpass wgpu-commandencoder nextTexture clear-color))
  #(print "hellobug")
    (wgpu-render-pass-encoder-end renderPass)
  ##(print "D")
    (wgpu-release-textureview nextTexture)
  ###(print "debug")
    (wgpu-command-encoder-insert-debug-marker wgpu-commandencoder "hello world")
  ##(print "finish")
    (def cmdbuff (wgpu-command-encoder-finish-ref wgpu-commandencoder))

  ##(print "submit")
    (wgpu-queue-submit wgpu-queue 1 cmdbuff)
  ##(print "present")
    (wgpu-swapchain-present wgpu-swapchain)
  ##(print "presented")
    ))

(print "out of while")



(if wgpu-swapchain
  (wgpu-release-swapchain wgpu-swapchain)
  (pp "swapchain already gone"))
(if wgpu-device
  (wgpu-release-device wgpu-device)
  (pp "device already gone"))
(if wgpu-adapter
  (wgpu-release-adapter wgpu-adapter)
  (pp "adapter already gone"))
(if wgpu-surface
  (wgpu-release-surface wgpu-surface)
  (pp "surface already gone"))
(if wgpu-instance
  (wgpu-release-instance wgpu-instance)
  (pp "instance already gone"))
(if window
  (destroy-window window)
  (pp "window already gone"))

(terminate-context)