Skip to content

fix stride calculation on types bigger than a vec4#359

Open
vvcarvalho wants to merge 2 commits intocbaggers:masterfrom
vvcarvalho:master
Open

fix stride calculation on types bigger than a vec4#359
vvcarvalho wants to merge 2 commits intocbaggers:masterfrom
vvcarvalho:master

Conversation

@vvcarvalho
Copy link

If the data definition via defstruct-g or a built-in type exceeds a vec4 , the usage of %gl:vertex-attrib-*pointer call changes.

In CEPL, the stride was previously always 0, meaning the generic vertex attributes are tightly packed (as per the spec). The splitting of a type into multiple pointers and their offsets was already done. However, in both Fedora 37 and macOS 12.6 it gave unexpected results with vertex attributes on types that exceeded the size of a vec4.

The reason, though not documented (AFAICT), is likely due to the stride being necessary in cases for types longer than a vec4 for vertex attributes. By always providing it, we get the expected results.

The patch was tested using the following pipeline:

(defun-g vert ((data g-pnt)
               (instance :mat4)
               &uniform
               (view :mat4)
               (proj :mat4))
  (* proj view instance (v! (pos data) 1.0)))

(defun-g frag ()
  (vec4 1.0))

(defpipeline-g test-instancing ()
  (vert g-pnt :mat4)
  (frag))

Thanks for CEPL!

If the data definition via defstruct-g or a built-in type exceeds a vec4 
, the usage of `%gl:vertex-attrib-*pointer` calls changes.

In CEPL, the stride was previously always 0, meaning the generic vertex
attributes are tightly packed (as per the spec). The splitting of a type
into multiple pointers and their offsets was already done. However, in 
both Fedora 37 and macOS 12.6 it gave unexpected results.

The reason, though not documented (AFAICT), is likely due to the stride
being necessary in cases for types longer than a vec4 for vertex 
attributes. By always providing it, we get the expected results.

A sample pipeline is given:
```
(defun-g vert ((data g-pnt)
               (instance :mat4)
               &uniform
               (view :mat4)
               (proj :mat4))
  (* proj view instance (v! (pos data) 1.0)))

(defun-g frag ()
  (vec4 1.0))

(defpipeline-g test-instancing ()
  (vert g-pnt :mat4)
  (frag))
```

The data definition and map-g is left to the patch reader.
@cbaggers
Copy link
Owner

Thank you for the PR! I am not back yet, but I'm not gone either. This won't be forgotten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants