cbaggers / cepl

Code Evaluate Play Loop
BSD 2-Clause "Simplified" License
860 stars 52 forks source link

The function CEPL::V! is undefined. #361

Open acekingke opened 1 year ago

acekingke commented 1 year ago

I compile the codes as follow:

(in-package :cepl)

(defparameter *array* nil)
(defparameter *stream* nil)
(defparameter *running* nil)

;; Lisp data for triangle vertices
(defparameter *triangle-data*
   (list (list (v!  0.5 -0.36 0) (v! 0 1 0 1))
         (list (v!    0   0.5 0) (v! 1 0 0 1))
         (list (v! -0.5 -0.36 0) (v! 0 0 1 1))))

;; A struct that works on gpu and cpu
(defstruct-g pos-col
  (position :vec3 :accessor pos)
  (color :vec4 :accessor col))

;; A GPU vertex shader using a Lisp syntax (see Varjo)
(defun-g vert ((vert pos-col))
  (values (v! (pos vert) 1.0)
          (col vert)))

;; A GPU fragment shader
(defun-g frag ((color :vec4))
  color)

;; Composing those gpu functions into a pipeline
(defpipeline-g prog-1 ()
  (vert pos-col)
  (frag :vec4))

;; Here is what we do each frame:
(defun step-demo ()
  (step-host)        ;; Advance the host environment frame
  (update-repl-link) ;; Keep the REPL responsive while running
  (clear)            ;; Clear the drawing buffer
  (map-g #'prog-1 *stream*) ;; Render data from GPU datastream
  (swap))            ;; Display newly rendered buffer

(defun run-loop ()
  (setf *running* t
    ;; Create a gpu array from our Lisp vertex data
        *array* (make-gpu-array *triangle-data* :element-type 'pos-col)
    ;; Create a GPU datastream
        *stream* (make-buffer-stream *array*))
  ;; continue rendering frames until *running* is set to nil
  (loop :while (and  *running*
             (not (shutting-down-p))) :do
     (continuable (step-demo))))

(defun stop-loop ()
  (setf *running* nil))

I use emacs + slime, When I compile it with key C+c C+k , It got errors like this:

The function CEPL::V! is undefined.
   [Condition of type UNDEFINED-FUNCTION]

Restarts:
 0: [CONTINUE] Retry calling V!.
 1: [USE-VALUE] Call specified function.
 2: [RETURN-VALUE] Return specified values.
 3: [RETURN-NOTHING] Return zero values.
 4: [*ABORT] Return to SLIME's top level.
 5: [ABORT] abort thread (#<THREAD "worker" RUNNING {7001B3CAE3}>)

Backtrace:
  0: ("undefined function" 0.5 -0.36 0)
  1: ((SB-C::TOP-LEVEL-FORM (SETQ *PACKAGE* (SB-INT:FIND-UNDELETED-PACKAGE-OR-LOSE "CEPL")))) [toplevel]
  2: (SB-FASL::LOAD-FASL-GROUP #S(SB-FASL::FASL-INPUT :STREAM #<SB-SYS:FD-STREAM for "file /Users/kyc/homework/lisp/runcepl.fasl" {7001B50273}> :TABLE #(40 #1="/Users/kyc/homework/lisp/runcepl.lisp" #<PA$
  3: ((LAMBDA NIL :IN SB-FASL::LOAD-AS-FASL))
  4: (SB-IMPL::CALL-WITH-LOADER-PACKAGE-NAMES #<FUNCTION (LAMBDA NIL :IN SB-FASL::LOAD-AS-FASL) {7001B5305B}>)
  5: (SB-FASL::LOAD-AS-FASL #<SB-SYS:FD-STREAM for "file /Users/kyc/homework/lisp/runcepl.fasl" {7001B50273}> NIL NIL)
  6: ((LABELS SB-FASL::LOAD-STREAM-1 :IN LOAD) #<SB-SYS:FD-STREAM for "file /Users/kyc/homework/lisp/runcepl.fasl" {7001B50273}> T)
  7: (SB-FASL::CALL-WITH-LOAD-BINDINGS #<FUNCTION (LABELS SB-FASL::LOAD-STREAM-1 :IN LOAD) {81FF41B}> #<SB-SYS:FD-STREAM for "file /Users/kyc/homework/lisp/runcepl.fasl" {7001B50273}> T #<SB-SYS:FD-STREA$
  8: (LOAD #P"/Users/kyc/homework/lisp/runcepl.fasl" :VERBOSE NIL :PRINT NIL :IF-DOES-NOT-EXIST :ERROR :EXTERNAL-FORMAT :DEFAULT)
 --more--
ebrasca commented 1 year ago

That function has been move to https://github.com/cbaggers/rtg-math It is also described in the README file , 2018-02-17!

metayan commented 1 year ago

One solution is to use cepl.examples:

cd ~/quicklisp/local-projects/
git clone https://github.com/cbaggers/cepl.examples
sbcl --eval '(ql:register-local-projects)' --quit

and replacing the first line in your example with

(ql:quickload :cepl.examples)
(in-package :cepl.examples)

Having a look at fraggle - especially fraggle.asd and package.lisp - might also be helpful to figure out which dependencies are needed.

acekingke commented 1 year ago

@metayan I do it following your advice, But it did not work, My compute is m2 macos.

* (ql:quickload :cepl.examples)
(in-package :cepl.examples)To load "cepl.examples":
  Load 1 ASDF system:
    cepl.examples
; Loading "cepl.examples"
.To load "dirt":
  Load 5 ASDF systems:
    asdf cepl cffi cl-opengl documentation-utils
  Install 2 Quicklisp releases:
    cl-soil dirt
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-soil/2018-08-31/cl-soil-release-quicklisp-f27087ce-git.tgz">
; 322.66KB
==================================================
330,400 bytes in 0.69 seconds (465.46KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/dirt/2017-10-19/dirt-release-quicklisp-0d13ebc2-git.tgz">
; 5.46KB
==================================================
5,590 bytes in 0.00 seconds (6332.93KB/sec)
; Loading "dirt"
..................................................
..................................................
..................................................
[package cl-soil].................................
[package stb-image]...............................
[package dirt].
To load "cepl.examples":
  Load 1 ASDF system:
    cepl.examples
; Loading "cepl.examples"
To load "temporal-functions":
  Load 1 ASDF system:
    fn
  Install 1 Quicklisp release:
    temporal-functions
; Fetching #<URL "http://beta.quicklisp.org/archive/temporal-functions/2017-10-19/temporal-functions-20171019-git.tgz">
; 6.43KB
==================================================
6,586 bytes in 0.00 seconds (3522.26KB/sec)
; Loading "temporal-functions"
[package temporal-functions]......................
[package tiny-time-manager].....
To load "cepl.examples":
  Load 1 ASDF system:
    cepl.examples
; Loading "cepl.examples"
To load "with-setf":
  Load 1 ASDF system:
    asdf
  Install 1 Quicklisp release:
    with-setf
; Fetching #<URL "http://beta.quicklisp.org/archive/with-setf/2018-02-28/with-setf-release-quicklisp-df3eed9d-git.tgz">
; 2.50KB
==================================================
2,558 bytes in 0.00 seconds (1503.04KB/sec)
; Loading "with-setf"
[package with-setf]
To load "cepl.examples":
  Load 1 ASDF system:
    cepl.examples
; Loading "cepl.examples"
...............
debugger invoked on a LOAD-FOREIGN-LIBRARY-ERROR in thread
#<THREAD "main thread" RUNNING {70016C80A3}>:
  Unable to load foreign library (ASSIMP).
  Error opening shared object "libassimp.dylib":
  dlopen(libassimp.dylib, 0x000A): tried: 'libassimp.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibassimp.dylib' (no such file), '/usr/lib/libassimp.dylib' (no such file, not in dyld cache), 'libassimp.dylib' (no such file).

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [RETRY                        ] Try loading the foreign library again.
  1: [USE-VALUE                    ] Use another library instead.
  2: [TRY-RECOMPILING              ] Recompile library and try loading it again
  3: [RETRY                        ] Retry
                                     loading FASL for #<CL-SOURCE-FILE "classimp" "library">.
  4: [ACCEPT                       ] Continue, treating
                                     loading FASL for #<CL-SOURCE-FILE "classimp" "library">
                                     as having been successful.
  5:                                 Retry ASDF operation.
  6: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the
                                     configuration.
  7:                                 Retry ASDF operation.
  8:                                 Retry ASDF operation after resetting the
                                     configuration.
  9: [ABORT                        ] Give up on "cepl.examples"
 10: [REGISTER-LOCAL-PROJECTS      ] Register local projects and try again.
 11:                                 Exit debugger, returning to top level.

(CFFI::FL-ERROR "Unable to load foreign library (~A).~%  ~A" ASSIMP #<(COMMON-LISP:SIMPLE-BASE-STRING 288) Error opening shared object "libassimp.dylib":
  dlopen(libassimp.dylib, 0x000A): tried: 'libassimp.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibassimp.dylib' (no such file), '/usr/l... {7007275F1F}>)
   source: (ERROR 'LOAD-FOREIGN-LIBRARY-ERROR :FORMAT-CONTROL CONTROL
            :FORMAT-ARGUMENTS ARGUMENTS)
0]
metayan commented 1 year ago

Oh yes, cepl.examples has a bunch of dependencies, like assimp, that first need to be installed on the system to be able to use them from Lisp. Can be done with Homebrew.

However, to keep it simple I made a small example for you with minimal dependencies: https://github.com/metayan/cepl-minimal

Got your triangle example to run by replacing the (in-package :cepl) with

(in-package :cepl-minimal)

loading cepl-minimal and then C-c C-k the triangle file in Emacs.

Also made https://github.com/metayan/cepl-start which has some helper functions for display handling that I find useful.

acekingke commented 1 year ago

Thank you, it works.

metayan @.***> 于2023年5月29日周一 05:45写道:

Oh yes, cepl.examples has a bunch of dependencies, like assimp, that first need to be installed on the system to be able to use them from Lisp. Can be done with Homebrew.

However, to keep it simple I made a small example for you with minimal dependencies: https://github.com/metayan/cepl-minimal

Got your triangle example to run by replacing the (in-package :cepl) with

(in-package :cepl-minimal)

loading cepl-minimal and then C-c C-k the triangle file in Emacs.

Also made https://github.com/metayan/cepl-start which has some helper functions for display handling that I find useful.

— Reply to this email directly, view it on GitHub https://github.com/cbaggers/cepl/issues/361#issuecomment-1566274301, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZ4FRSJZ3OTBAU6ELZXHJDXIPBP5ANCNFSM6AAAAAAYM4L744 . You are receiving this because you authored the thread.Message ID: @.***>

acekingke commented 1 year ago

when I use brew install assimp , it got error like this:

 trying to link against unsupported version of assimp. 3.0-5.0.x supported, got version 5.2