4
4
# to run pixel shaders with image and numerical parameters (so you
5
5
# can draw images, shapes, etc from Display.)
6
6
7
+ set ::isLaptop 1
7
8
set makeGpu {
8
9
set macos [expr {$tcl_platform(os) eq "Darwin"}]
9
10
10
- if {!$macos } {
11
+ if {!$::isLaptop } {
11
12
foreach renderFile [glob -nocomplain "/dev/dri/render*"] {
12
13
if {![file readable $renderFile]} {
13
14
puts stderr "Gpu: Warning: $renderFile is not readable by current user; Vulkan device may not appear.
@@ -70,6 +71,8 @@ Try doing `sudo adduser folk render`."
70
71
dc include <stdlib.h>
71
72
if {$macos} {
72
73
dc cflags -I/opt/homebrew/include -L/opt/homebrew/lib
74
+ }
75
+ if {$::isLaptop} {
73
76
dc include <GLFW/glfw3.h>
74
77
dc cflags -lglfw
75
78
}
@@ -112,7 +115,7 @@ Try doing `sudo adduser folk render`."
112
115
}
113
116
dc proc init {int displayIdx} void [csubst {
114
117
$[vktry volkInitialize()]
115
- $[if {$macos } { expr {"glfwInit();"} }]
118
+ $[if {$::isLaptop } { expr {"glfwInit();"} }]
116
119
117
120
// Set up VkInstance instance:
118
121
{
@@ -125,22 +128,30 @@ Try doing `sudo adduser folk render`."
125
128
createInfo.enabledLayerCount = sizeof(validationLayers)/sizeof(validationLayers[0]);
126
129
createInfo.ppEnabledLayerNames = validationLayers;
127
130
128
- const char* enabledExtensions[] = $[expr { $macos ? {{
129
- VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME,
130
- VK_KHR_SURFACE_EXTENSION_NAME,
131
- "VK_EXT_metal_surface",
131
+ uint32_t enabledExtensionCount = 1;
132
+ const char* enabledExtensions[10] = {
132
133
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
133
- }} : {{
134
- // 2 extensions for non-X11/Wayland display
135
- VK_KHR_SURFACE_EXTENSION_NAME,
136
- VK_KHR_DISPLAY_EXTENSION_NAME,
137
- VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
138
- }} }];
139
- createInfo.enabledExtensionCount = sizeof(enabledExtensions)/sizeof(enabledExtensions[0]);
140
- createInfo.ppEnabledExtensionNames = enabledExtensions;
134
+ };
135
+
141
136
$[if {$macos} { expr {{
137
+ enabledExtensions[enabledExtensionCount++] = VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME;
142
138
createInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
143
139
}} }]
140
+ $[if {$::isLaptop} { expr {{
141
+ uint32_t extCount;
142
+ const char** extensions = glfwGetRequiredInstanceExtensions(&extCount);
143
+
144
+ while (extCount > 0) {
145
+ enabledExtensions[enabledExtensionCount++] = extensions[--extCount];
146
+ }
147
+ }} } else { expr {{
148
+ enabledExtensions[enabledExtensionCount++] = VK_KHR_SURFACE_EXTENSION_NAME;
149
+ enabledExtensions[enabledExtensionCount++] = VK_KHR_DISPLAY_EXTENSION_NAME;
150
+ }} }]
151
+
152
+ createInfo.ppEnabledExtensionNames = enabledExtensions;
153
+ createInfo.enabledExtensionCount = enabledExtensionCount;
154
+
144
155
VkResult res = vkCreateInstance(&createInfo, NULL, &instance);
145
156
if (res != VK_SUCCESS) {
146
157
fprintf(stderr, "Failed vkCreateInstance: %s (%d)\n",
@@ -202,14 +213,13 @@ Try doing `sudo adduser folk render`."
202
213
203
214
VkPhysicalDeviceFeatures deviceFeatures = {0};
204
215
205
- const char *deviceExtensions[] = $[expr { $macos ? { {
216
+ const char *deviceExtensions[] = {
206
217
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
218
+ VK_KHR_MAINTENANCE3_EXTENSION_NAME,
219
+ $[expr { $macos ? {
207
220
"VK_KHR_portability_subset",
208
- VK_KHR_MAINTENANCE3_EXTENSION_NAME
209
- }} : {{
210
- VK_KHR_SWAPCHAIN_EXTENSION_NAME,
211
- VK_KHR_MAINTENANCE3_EXTENSION_NAME
212
- }} }];
221
+ } : {} }]
222
+ };
213
223
214
224
VkDeviceCreateInfo createInfo = {0};
215
225
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
@@ -236,14 +246,14 @@ Try doing `sudo adduser folk render`."
236
246
237
247
// Get drawing surface.
238
248
VkSurfaceKHR surface;
239
- $[expr { $macos ? {
249
+ $[expr { $::isLaptop ? [csubst {
240
250
GLFWwindow* window;
241
251
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
242
- window = glfwCreateWindow(640, 480 , "Window Title", NULL, NULL);
252
+ window = glfwCreateWindow($WIDTH, $HEIGHT , "Window Title", NULL, NULL);
243
253
if (glfwCreateWindowSurface(instance, window, NULL, &surface) != VK_SUCCESS) {
244
254
fprintf(stderr, "Gpu: Failed to create GLFW window surface\n"); exit(1);
245
255
}
246
- } : [csubst {
256
+ }] : [csubst {
247
257
// TODO: support multiple displays, pick best display mode
248
258
249
259
uint32_t displayCount;
@@ -291,7 +301,7 @@ Try doing `sudo adduser folk render`."
291
301
if (capabilities.currentExtent.width != UINT32_MAX) {
292
302
extent = capabilities.currentExtent;
293
303
} else {
294
- $[expr { $macos ? {
304
+ $[expr { $::isLaptop ? {
295
305
glfwGetFramebufferSize(window, (int*) &extent.width, (int*) &extent.height);
296
306
if (capabilities.minImageExtent.width > extent.width) { extent.width = capabilities.minImageExtent.width; }
297
307
if (capabilities.maxImageExtent.width < extent.width) { extent.width = capabilities.maxImageExtent.width; }
@@ -808,12 +818,12 @@ Try doing `sudo adduser folk render`."
808
818
presentInfo.pImageIndices = &imageIndex;
809
819
presentInfo.pResults = NULL;
810
820
811
- vkQueuePresentKHR(presentQueue, &presentInfo);
821
+ $[vktry { vkQueuePresentKHR(presentQueue, &presentInfo)}]
812
822
}
813
823
}
814
824
815
825
dc proc poll {} void {
816
- $[expr { $macos ? { glfwPollEvents(); } : {} }]
826
+ $[expr { $::isLaptop ? { glfwPollEvents(); } : {} }]
817
827
}
818
828
819
829
# Construct a reusable GLSL function that can be linked into and
@@ -1554,7 +1564,7 @@ Try doing `sudo adduser folk render`."
1554
1564
source "lib/colors.tcl"
1555
1565
1556
1566
proc Start-display-process {code} {
1557
- if {$::tcl_platform(os) eq "Darwin" } {
1567
+ if {$::isLaptop } {
1558
1568
# On macOS, you must talk to the GPU on the main thread, so we
1559
1569
# don't Start a subprocess here. We trampoline this code into
1560
1570
# a claim so we can run the rest of display.folk before
@@ -1574,6 +1584,7 @@ proc Start-display-process {code} {
1574
1584
Start-display-process {
1575
1585
puts "Display pid: [pid]"
1576
1586
set macos [expr {$::tcl_platform(os) eq "Darwin"}]
1587
+ set ::isLaptop 1
1577
1588
1578
1589
source "virtual-programs/images.folk"
1579
1590
namespace eval Gpu $makeGpu
@@ -1646,7 +1657,9 @@ Start-display-process {
1646
1657
while true {
1647
1658
set ::displayList [dict create] ;# Keys are layer numbers; values are lists of commands
1648
1659
Step
1649
- if {$macos} { update }
1660
+ if {$::isLaptop} {
1661
+ update
1662
+ }
1650
1663
1651
1664
foreach match [Statements::findMatches {/wisher/ wishes the GPU draws pipeline /name/ with /...options/}] {
1652
1665
try {
@@ -1682,7 +1695,7 @@ Start-display-process {
1682
1695
}
1683
1696
Gpu::drawEnd
1684
1697
}]
1685
- if {$macos } { Gpu::poll }
1698
+ if {$::isLaptop } { Gpu::poll }
1686
1699
1687
1700
Commit { Claim the display time is "render $renderTime us ($::stepTime)" }
1688
1701
}
@@ -1700,7 +1713,7 @@ namespace eval ::Display {
1700
1713
variable WIDTH
1701
1714
variable HEIGHT
1702
1715
variable LAYER 0
1703
- if {$::tcl_platform(os) eq "Darwin" } {
1716
+ if {$::isLaptop } {
1704
1717
set WIDTH [* 640 2]; set HEIGHT [* 480 2]
1705
1718
} else {
1706
1719
regexp {mode "(\d+)x(\d+)(?:-\d+)?"} [exec fbset] -> WIDTH HEIGHT
0 commit comments