<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Compiler ignoriert #pragma pack]]></title><description><![CDATA[<p>Hallo zusammen<br />
Ich habe folgende Struktur:</p>
<pre><code class="language-cpp">// ******************************************** struct &quot;Light&quot; *******************************************
// This struct describes a single light source. Be aware that no member of this structure must cross
// a 128-Bit boundary, otherwise this structure cannot simply be copied to the GPU registers.
// Author: Samuel Lörtscher
// *******************************************************************************************************
#pragma pack(push,16)
struct Light{
public:
 // --------------------------------------- public dynamic members ---------------------------------------
 Color    Color;        // color
 Vector3  Position;     // position vector
 Vector3  Direction;    // direction vector
 float32  Theta;        // inner cone angle
 float32  Phi;          // outer cone angle
 float32  Fallof;       // fallof
 float32  Attenuation0; // the first attenuation
 float32  Attenuation1; // the second attenuation
 float32  Attenuation2; // the third attenuation
 // ------------------------------------------------------------------------------------------------------
};
#pragma pack(pop)
// *******************************************************************************************************
</code></pre>
<p>Diese sollte doch nun 72Bytes gross sein? Tatsächlich ist sie aber nur 64Bytes gross, so als würde ich das pack nicht machen? Hat vielleicht jemand eine Idee, wie ich den Compiler (Visual Studio 2010) dazu zwingen kann, diese Struktur korrekt auszurichten?</p>
<p>Mfg Samuel</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/273783/compiler-ignoriert-pragma-pack</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 23:31:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/273783.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Sep 2010 11:44:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 12:33:29 GMT]]></title><description><![CDATA[<p>Hallo zusammen<br />
Ich habe folgende Struktur:</p>
<pre><code class="language-cpp">// ******************************************** struct &quot;Light&quot; *******************************************
// This struct describes a single light source. Be aware that no member of this structure must cross
// a 128-Bit boundary, otherwise this structure cannot simply be copied to the GPU registers.
// Author: Samuel Lörtscher
// *******************************************************************************************************
#pragma pack(push,16)
struct Light{
public:
 // --------------------------------------- public dynamic members ---------------------------------------
 Color    Color;        // color
 Vector3  Position;     // position vector
 Vector3  Direction;    // direction vector
 float32  Theta;        // inner cone angle
 float32  Phi;          // outer cone angle
 float32  Fallof;       // fallof
 float32  Attenuation0; // the first attenuation
 float32  Attenuation1; // the second attenuation
 float32  Attenuation2; // the third attenuation
 // ------------------------------------------------------------------------------------------------------
};
#pragma pack(pop)
// *******************************************************************************************************
</code></pre>
<p>Diese sollte doch nun 72Bytes gross sein? Tatsächlich ist sie aber nur 64Bytes gross, so als würde ich das pack nicht machen? Hat vielleicht jemand eine Idee, wie ich den Compiler (Visual Studio 2010) dazu zwingen kann, diese Struktur korrekt auszurichten?</p>
<p>Mfg Samuel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951936</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Mon, 13 Sep 2010 12:33:29 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 12:00:20 GMT]]></title><description><![CDATA[<p>Ishildur schrieb:</p>
<blockquote>
<p>Diese sollte doch nun 68Bytes gross sein? Tatsächlich ist sie aber nur 64Bytes gross, so als würde ich das pack nicht machen? Hat vielleicht jemand eine Idee, wie ich den Compiler (Visual Studio 2010) dazu zwingen kann, diese Struktur korrekt auszurichten?</p>
</blockquote>
<p>1. Ich nehme an, dass Color ein ARGB Wert ist mit 4x 32 Bit Zahlen.<br />
2. Ich nehme an, dass Vector3 eine Struktur mit 3x 32 Bit Zahlen ist.<br />
3. Dann wäre 64 Bytes für mich absolut in Ordnung. Wieso sollten es 68 Bytes sein, wenn es auf ein vielfaches von 16 Bytes packen sollen?</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951949</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951949</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 13 Sep 2010 12:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 12:32:26 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9752">@Dravere</a></p>
<blockquote>
<p>wenn es auf ein vielfaches von 16 Bytes packen sollen?</p>
</blockquote>
<p>Oje, in diesem Fall habe ich wohl packed falsch verstanden. Nein was ich brauche ist ein packing, bei welcher keine der Membervariablen eine 128bit Grenze überschreitet:</p>
<pre><code class="language-cpp">struct Light{
public:
 // --------------------------------------- public dynamic members ---------------------------------------
 Color    Color;        // --&gt; neuer 128bit Bereich (0 padding)
 Vector3  Position;     // --&gt; neuer 128bit Bereich (0 byte padding)
 Vector3  Direction;    // --&gt; neuer 128bit Bereich (4 byte padding)
 float32  Theta;        // --&gt; neuer 128bit Bereich (4 byte padding)
 float32  Phi;          // 
 float32  Fallof;       // 
 float32  Attenuation0; // 
 float32  Attenuation1; // --&gt; neuer 128bit Bereich (0 padding)
 float32  Attenuation2; //
 // ------------------------------------------------------------------------------------------------------
};
</code></pre>
<p>Würde man bspw. nach Position kein padding von 1 byte machen, würde Direction anschliessend auf 2 128Bit Register der Grafikkarte verteilt und das ist nix gut!</p>
<p>Weisst du, wie man sowas machen kann? Ich meine mir ist schon klar, dass ich einfach Bytes hineinpflastern kann, aber ich meine eine etwas elegantere Möglichkeit, also nicht</p>
<pre><code class="language-cpp">struct A{
 Vector3 B;
 uint32   Padding0;
 Vector3 C;
 uint32   Padding1;
};
</code></pre>
<p>oder sowas</p>
<p>P.S.<br />
Hier sieht man die Packing rules von HLSL <a href="http://msdn.microsoft.com/en-us/library/bb509632%28v=VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb509632(v=VS.85).aspx</a><br />
Natürlich müssen meine C++ Strukturen identisch gepackt werden, damit ich sie in die Konstantenregistern der Vertex- und Pixelshader kopieren kann, ohne in jedem Frame das Ganze auseinanderfrickeln zu müssen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951956</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Mon, 13 Sep 2010 12:32:26 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 12:45:33 GMT]]></title><description><![CDATA[<p>Grundsätzlich so:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

struct Color
{
  float a, r, g, b;
};

struct Vector3
{
  float x, y, z;
};

typedef float float32;

struct Light
{
  __declspec(align(16)) Color    Color;        // color
  __declspec(align(16)) Vector3  Position;     // position vector
  __declspec(align(16)) Vector3  Direction;    // direction vector
  __declspec(align(16)) float32  Theta;        // inner cone angle
  __declspec(align(16)) float32  Phi;          // outer cone angle
  __declspec(align(16)) float32  Fallof;       // fallof
  __declspec(align(16)) float32  Attenuation0; // the first attenuation
  __declspec(align(16)) float32  Attenuation1; // the second attenuation
  __declspec(align(16)) float32  Attenuation2; // the third attenuation
};

int main()
{
  std::cout &lt;&lt; sizeof(Light) &lt;&lt; std::endl;
  std::cin.get();
}
</code></pre>
<p>Aber das wäre dann logischerweise eine Struktur mit 144 Bytes (9 x 16 Bytes).</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951977</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 13 Sep 2010 12:45:33 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 12:55:09 GMT]]></title><description><![CDATA[<p>Du willst doch, dass die Vector3-Member deiner Struktur 16 statt 12 Bytes breit sind, wenn ich dich richtig verstanden habe. Das könntest du bei der Definition von Vector3 so erreichen:</p>
<pre><code class="language-cpp">__declspec(align(16)) struct Vector3 {
  //...
};
</code></pre>
<p>EDIT: Ok, Dravere macht's besser. Ich wusste gar nicht, dass man das pro Member notieren kann (hab aber auch nur mal davon gelesen und es nie angewendet).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951978</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951978</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 13 Sep 2010 12:55:09 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 13:05:04 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9752">@Dravere</a><br />
Leider hast du mich noch nicht ganz verstanden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Theta, Phi, Fallof und Attenuation0 sollen nicht nach 128-bit ausgerichtet sein sondern nur Theta (sonst würde ja als Folge jeder einzelne Wert in einem separaten Register stehen (soviele Register habe ich gar nicht). Diese vier sollen in einem einzigen Register gepackt werden. Genauso wie Attenuation1 und Attenuation2.<br />
Wichtig ist auch dass jtzt nicht die erste Komponente von Direction in die letze Komponete des Registers gepackt wird, wo bereits Position drinn steht, sondern in einem neuen Register anfangen usw...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951987</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951987</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Mon, 13 Sep 2010 13:05:04 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 13:18:03 GMT]]></title><description><![CDATA[<p>Ishildur schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9752">@Dravere</a><br />
Leider hast du mich noch nicht ganz verstanden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Theta, Phi, Fallof und Attenuation0 sollen nicht nach 128-bit ausgerichtet sein sondern nur Theta (sonst würde ja als Folge jeder einzelne Wert in einem separaten Register stehen (soviele Register habe ich gar nicht). Diese vier sollen in einem einzigen Register gepackt werden. Genauso wie Attenuation1 und Attenuation2.<br />
Wichtig ist auch dass jtzt nicht die erste Komponente von Direction in die letze Komponete des Registers gepackt wird, wo bereits Position drinn steht, sondern in einem neuen Register anfangen usw...</p>
</blockquote>
<p>Ja aber das erreichst du doch, wenn du nur die beiden Vector3-Member auf 16 Bytes ausrichtest (mit Däckelspeck... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ).</p>
<pre><code class="language-cpp">struct Light
{
  Color    Color;        // color
  __declspec(align(16)) Vector3  Position;     // position vector
  __declspec(align(16)) Vector3  Direction;    // direction vector
  float32  Theta;        // inner cone angle
  float32  Phi;          // outer cone angle
  float32  Fallof;       // fallof
  float32  Attenuation0; // the first attenuation
  float32  Attenuation1; // the second attenuation
  float32  Attenuation2; // the third attenuation
};
</code></pre>
<p>Oder liege ich da falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951995</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 13 Sep 2010 13:18:03 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler ignoriert #pragma pack on Mon, 13 Sep 2010 13:25:30 GMT]]></title><description><![CDATA[<p>_matze schrieb:</p>
<blockquote>
<p>Oder liege ich da falsch?</p>
</blockquote>
<p>Hätte ich jetzt auch gesagt. Allerdings wird die Struktur dann 80 Bytes gross werden, weil er nochmals 8 Bytes ganz am Ende einfügt. Aber das sollte hoffentlich kein Problem darstellen.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1952001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1952001</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 13 Sep 2010 13:25:30 GMT</pubDate></item></channel></rss>