I am really new to DirectCompute technologies and trying to learn from the documentation on the msdn website, which is at least dense.
I would like to create a basic hlsl file that takes a 4x4 matrix and a 4xN matrix and returns a multiplied result. But after spending some time playing with the code, I found some strange things that I don’t understand - mainly with the way the streams transmit buffers and output in the process.
With all these examples, I pass two 16 floating-point buffers and select 16 floating-point buffers, and then send with 4x1x1 grouping - I can show you the code, but I honestly don’t know what will help you. Let me know if there is a section of my C ++ code that you want to see.
with the following code:
StructuredBuffer<float4x4> base_matrix : register(t0);
I get the following values:
1.000 0.000 0.000 0.000 1.000 0.000 0.000 0.000 1.000 0.000 0.000 0.000 1.000 0.000 0.000 0.000
This makes sense to me - the buffer is parsed as 4 threads, each of which performs 1 grouping of float4.
with the following code:
StructuredBuffer<float4x4> base_matrix : register(t0);
I get the following values:
1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
and with the actual code I want to run:
StructuredBuffer<float4x4> base_matrix : register(t0); StructuredBuffer<float4> extended_matrix : register(t1); RWStructuredBuffer<float4> BufferOut : register(u0); [numthreads(1, 1, 1)] void CSMain( uint3 DTid : SV_DispatchThreadID ) { BufferOut[DTid.x] = mul(base_matrix[0],extended_matrix[DTid.x]) }
I get the following values:
0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
I can say that a critical thing is missing here, but for my life I can’t find the relevant documentation telling me how it works. Can someone help me understand what is going on in this code?
Thank you for your time,
Zach
As a further note, this code was minimized using the Microsoft DirectX SDK sample (June 2010) \ Samples \ C ++ \ Direct3D11 \ BasicCompute11. If I'm doing something terribly wrong, feel free to let me know. I am REALLY new in HLSL.
Edit: code to create my buffer.
CreateStructuredBuffer( g_pDevice, sizeof(float)*16, 1, g_matrix, &g_pBuf0 ); CreateStructuredBuffer( g_pDevice, sizeof(float)*4, NUM_ELEMENTS, g_extended_matrix, &g_pBuf1 ); CreateStructuredBuffer( g_pDevice, sizeof(float)*4, NUM_ELEMENTS, NULL, &g_pBufResult );
Attempt .1, .2, .3, .4 ...
StructuredBuffer<float4x4> base_matrix : register(t0); StructuredBuffer<float4> extended_matrix : register(t1); StructuredBuffer<uint> loop_multiplier : register(t2); RWStructuredBuffer<float4> BufferOut : register(u0); [numthreads(1, 1, 1)] void CSMain( uint3 DTid : SV_DispatchThreadID ) { BufferOut[DTid.x].x = .1; BufferOut[DTid.x].y = .2; BufferOut[DTid.x].z = .3; BufferOut[DTid.x].w = .4; }
got this:
0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100 0.100