Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no pointer arithmetic for <code>void*</code> pointers. Use <code>char*</code> pointers to perform byte-wise pointer computations.</p> <p>Or a lot better than that: Use the <em>real</em> type the pointer is pointing to, and don't multiply offsets. Simply write <code>vertex[index+base]</code> assuming <code>vertex</code> points to your type containing 28 bytes of data.</p> <p><strong>Performance consideration:</strong> Align your vertex attributes to a power of two for coalesced memory access. This means, add 4 bytes of padding after each vertex entry. To automatically do this, use <code>float8</code> as the vertex type if your attributes are all floating point values. I assume you work with position and normal data or something similar, so it might be a good idea to write a custom struct which encapsulates both vectors in a convenient and self-explaining way:</p> <pre class="lang-opencl prettyprint-override"><code>// Defining a type for the vertex data. This is 32 bytes large. // You can share this code in a header for inclusion in both OpenCL and C / C++! typedef struct { float4 pos; float4 normal; } VertexData; // Example kernel __kernel void computeNormalKernel(__global VertexData *vertex, uint base) { uint index = get_global_id(0); VertexData thisVertex = vertex[index+base]; // It can't be simpler! thisVertex.normal = computeNormal(...); // Like you'd do it in C / C++! vertex[index+base] = thisVertex; // Of couse also when writing } </code></pre> <p>Note: This code doesn't work with your stride of 28 if you just change one of the <code>float4</code>s to a <code>float3</code>, since <code>float3</code> also consumes 4 floats of memory. But you can write it like this, which will not add padding (but note that this will penalize memory access bandwidth):</p> <pre><code>typedef struct { float pos[4]; float normal[3]; // Assuming you want 3 floats here } VertexData; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload