Skip to content

Commit

Permalink
specify layout qualifiers earlier in generated code for compute shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
3b committed Feb 22, 2018
1 parent 923e4b3 commit b497014
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
5 changes: 5 additions & 0 deletions api.lisp
Expand Up @@ -112,6 +112,11 @@ itself). "
do (format t "#extension ~a : ~a~%"
(expand-extension-keyword ext)
(if enable "enable" "disable")))
;; put layout() at beginning for compute stage
(when (and (eql *current-shader-stage* :compute)
(layout-qualifiers *print-as-main*))
(print-main-layout-qualifiers (layout-qualifiers *print-as-main*)))

(loop with dumped = (make-hash-table)
for object in objects
for stage-binding = (stage-binding object)
Expand Down
34 changes: 20 additions & 14 deletions printer.lisp
Expand Up @@ -430,24 +430,30 @@
(defprint array-access (o)
(format t "~a" (translate-name o)))

(defun print-main-layout-qualifiers (q)
(maphash (lambda (k v)
(format t "layout(~{~@[~a=~]~@[~a~^,~]~}) ~a;~%"
(loop for (a b) on v by #'cddr
;; allow nil -> X or X -> X
;; to mean single element without =
for single = (or (not a) (eq a b))
collect (unless single
(%translate-name a :lc-underscore t))
collect (if (and single b)
(%translate-name b :lc-underscore t)
b))
(translate-name k)))
q))

(defprint global-function (o)
(assert-statement)
;; fixme: clean this layout stuff up...
;; if function is "main", check for extra layout qualifiers
(when (and (string= (translate-name o) "main") (layout-qualifiers o))
(maphash (lambda (k v)
(format t "layout(~{~@[~a=~]~@[~a~^,~]~}) ~a;~%"
(loop for (a b) on v by #'cddr
;; allow nil -> X or X -> X
;; to mean single element without =
for single = (or (not a) (eq a b))
collect (unless single
(%translate-name a :lc-underscore t))
collect (if (and single b)
(%translate-name b :lc-underscore t)
b))
(translate-name k)))
(layout-qualifiers o)))
(when (and (string= (translate-name o) "main") (layout-qualifiers o)
;; compute layout qualifiers need printed earlier so
;; other functions can use gl_WorkGroupSize etc
(not (eql *current-shader-stage* :compute)))
(print-main-layout-qualifiers (layout-qualifiers o)))

;; print function def
(format t "~a ~a ~<(~;~@{~:_~a~#[~:;, ~]~}~;)~:> {~%"
Expand Down

0 comments on commit b497014

Please sign in to comment.