Draw call bugthe book specifies that vertex shader is ran 6 times using draw call parameter vertexCount


the book specifies that vertex shader is ran 6 times using draw call parameter vertexCount. however vertexCount parameter returns quad.vertices.count which is 18. I tried to divide it by 3 but somehow it didn;t work instead leaving it as 18 actually made the render work. can someone explain ?

Hi there

There is an error in the book, as @lolepicpeter has pointed out. :clap:

The vertices array contains 18 items, making up 6 vertices.

Thus the draw call shouldn’t draw quad.vertices.count number of vertices, which would be 18, but should draw only 6.

I’m not sure why that isn’t working for you? I did the code through to the point where you do the draw call and did / 3 in this project:

vertexcount.zip (46.1 KB)

1 Like

oh yes. It was my fault on my end :sweat_smile:.
I had the new array of vertices with indices as indexdrawing which had less elements in vertex array hehe.

but even if i left it as quad.vertices.count (18) it still rendered correctly which is strange … I would lie to know why it worked

Later in the book, you’ll learn about using the GPU Frame Capture, so that you can examine the GPU attachments such as buffers and textures.

This is what’s happening on the GPU:

You’re drawing 18 vertices, but there’s only 6 vertices-worth of data. So when the GPU gets to the 7th vertex, it’s reading out of buffer. I’m actually surprised that it does work with 18 vertices. I guess it depends what’s in GPU memory.

In this example, it’s reading zeros and drawing zero-sized triangles at the centre. You can just see the green dot where it’s drawing.

At the bottom right, the purple exclamation point signals an error. In this case it’s drawing degenerate (zero) triangles.

2 Likes

A slightly out of topic question but do you think if i master this book. Will i be qualified enough to apply for a position like this? :sweat_smile:. It’s my end goal and this book as of right now is the best learning resource i’ve ever had regarding Metal. I’ve tried video tutorials but they still don’t compare. I hope u will update it for even better experience for beginners like me :smiley: .

I don’t want to dampen your enthusiasm, but the book will only start you on the road!

That position asks for a Masters in Computer Science and a proficiency in C++, which this book won’t teach you.

However, keep working on your rendering, math and programming skills, and jump on every opportunity you’re given :grin:. Never say no!

1 Like

thanks for being honest with me :slight_smile: this is what i needed. Do you think you could see yourself with these jobs ?

I’m more of an independent, so I wouldn’t want to work at Apple.

I don’t have traditional math skills, so anything I achieve is done through a lot of hard work and research (which I really enjoy). And I’m not great at C++.

Fortunately for using MSL (Metal Shading Language) you don’t need a lot of C++, but I’m sure that any position at Apple would require strong skills.

in my country slovakia there’s hardly any iOS job not to mention metal jobs like these :sweat_smile:. But i hope future would be brighter, cause i love this field :smiley: testing what apple hardware can do with their native apis is rly exciting for me

1 Like

however i got another unsettlement. we somehow changed the vertexDescriptor stride from MemoryLayout<SIMD3>.stride to MemoryLayout.stride * 3


to

in theory it should be the same but somehow the old one with SIMD3 stopped working and the new one worked. Can you offer me explanation?

I’m not quite sure what your code reads currently.

The stride of MemoryLayout<Float> is 4, so * 3 is 12.

The stride of MemoryLayout<SIMD3<Float>> is 16. There’s padding going on internally.

The stride should match what your code is. If you’re using a float3, it’s 16; if you’re using Float * 3, it`s 12.

sorry dont pay attention to it. i found out the make buffer function for vertex wasnt modified to correctly for float3 so yeah my fault :slight_smile:

1 Like

can you advise to some course i could take to learn these essential maths requires by this field? does kodeco provides such courses?

No, Kodeco doesn’t currently have any math courses.

Many of the chapters in Metal by Tutorials have a resources folder that contains reference.markdown, which contains useful links.

The best Linear Algebra introductions IMO are:

Essence of linear algebra
and
immersive linear algebra

These aren’t courses, as such, but are a great introduction.

If you’re not quite ready to step up to Linear Algebra, this is a great free book:

3D Math Primer for Graphics and Game Development

And of course Khan Academy is great, including Pixar in a Box

Iam kinda unsettled by this …


I don’t understand why they didn’t include row instead of columns since it makes visually more sense to look at because you don;t have to flip it rows since it usualle rowsXcolumns not columnsXrow. Is there any logical explanation for this?

I can’t provide a logical explanation because it is just a choice.

simd uses column major, and so does OpenGL, but DirectX uses row-major.

You can use rows if you choose as long as you make it clear everywhere: float3x3(rows: rows)

Hi caroline, i recently decided to give university one more chance i wanna to travel either to UK or US to study but i think i will end up in UK since i rly cant afford expensive US. But i’m wondering which major is better to choose since iam interested in optimizing games rather than game designing, so my question is which course should i choose between normal CS MSc Computing | University of Northampton or game programing course Games Programming Degree BSc | University of Northampton

I can’t possibly advise you on that, I’m afraid. I don’t have experience in academia.

Hi Caroline, first of all how are you :slight_smile: . I got a new question regarding Apple Silicon and the the content of the book. Do you u think with Apple having this whole new CPU, GPU and memory architecture. Would there be a need to create new or update the book to take advantage of its new unified memory architecture and other technologies?