# StructuredBuffer and matrix layout

This topic is 470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Not sure if this is a bug of a feature, but apparently this code always generates column-major matrices:

StructuredBuffer<float4x4>


This is regardless of using D3DCOMPILE_PACK_MATRIX_ROW_MAJOR or #pragma pack_matrix(row_major).

Anyone has an elegant way to fix it? It's a real irritating 'feature'.

##### Share on other sites

Yes, I've seen that behavior as well when using compute shaders. My workaround was to use a StructuredBuffer<float4> instead and use 4 loads. In terms of the compiled assembly this isn't really any less efficient, since a float4x4 by will get split into 4 loads when compiled to assembly (you can only load 4 DWORDs at a time from structured buffers).

##### Share on other sites

Yes, I've seen that behavior as well when using compute shaders. My workaround was to use a StructuredBuffer instead and use 4 loads. In terms of the compiled assembly this isn't really any less efficient, since a float4x4 by will get split into 4 loads when compiled to assembly (you can only load 4 DWORDs at a time from structured buffers).

While searching for an answer I stumbled upon your blog, which is the just about the only place that this packing issue is mentioned (bad MSDN...). I actually used your advise and loaded the 4 vectors myself, just to find out that the skinning shader went from 46 instructions with column-major to 176 instructions with row-major.

I knew that row-major is more inefficient than row-major, but x4 instructions is just too much.

##### Share on other sites

Sorry for bump but I just stumbled upon this recently. Was frustrated as I already had my matrices column-major when sending to the shader so I couldn't understand why it got sampled transposed.

I just transposed() the matrix after sampling in the shader.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!