Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualcollie

Posted 08 February 2013 - 12:43 PM

I have a problem where certain floats in a VertexShaderInput are either NaN or 0.000000000.
I have 4 streams being sent to the vertex shader.

float2 'textureCoordinates' of slot 0 always appear to be NaN.
float 'bitWidth' of slot 2 always appear to be 0.000000000.

struct VertexShaderInput
{
    // Vertex buffer slot 0.
    float4 vertexPosition      : POSITION0;
    float2 textureCoordinates  : TEXCOORD0;
    float vertexNumber         : TEXCOORD1;
    
    // Vertex buffer slot 1.
    float4 bitColour           : COLOR0;
    
    // Vertex buffer slot 2.
    float bitWidth             : TEXCOORD2;
    
    // Vertex buffer slot 4.
    float2 bitOffset           : TEXCOORD3;
};

The other floats appear to have the expected values when debugged.  Slot 2-3 are instanced streams.
I have tried changing float sizes and the matching DXGI_FORMAT_xxxx_FLOAT to no avail.

In the data I have given each float an incrementing value to make it easier to check the input.
 

  const D3D11_INPUT_ELEMENT_DESC vertexLayoutDesc[] =
  {    
    // Vertex buffer slot 0.
    { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0,
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // vertexPosition
    { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,       0, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // textureCoordinates
    { "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT,          0, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // vertexNumber    
    
    // Vertex buffer slot 1.
    { "COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitColour
    
    // Vertex buffer slot 2.
    { "TEXCOORD", 2, DXGI_FORMAT_R32_FLOAT,          2, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitWidth
    
    // Vertex buffer slot 3.
    { "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT,       3, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitOffset
  };
 
  hr = device->CreateInputLayout(
    vertexLayoutDesc,
    ARRAYSIZE(vertexLayoutDesc),
    vertexShaderBytecode,
    vertexShaderBytecodeLength,
    &_inputLayout);

deviceContext->IASetInputLayout(_inputLayout);

 struct VertexPositions
 {
     DirectX::XMFLOAT4 _vertexPosition;
     DirectX::XMFLOAT2 _textureCoordinates;
     FLOAT             _vertexNumber;
 }
 
 VertexPositions vpnts[] =
  {
    {
      DirectX::XMFLOAT4(1.0f, 2.0f, 3.0f, 4.0f),   // vertexPosition
      DirectX::XMFLOAT2(5.0f, 6.0f),               // textureCoordinates
      7.0f                                         // vertexNumber
    },
    {
      DirectX::XMFLOAT4(8.0f, 9.0f, 10.0f, 10.0f), // vertexPosition
      DirectX::XMFLOAT2(12.0f, 13.0f),             // textureCoordinates
      14.0f                                        // vertexNumber
    },
    {
      DirectX::XMFLOAT4(15.0f, 16.0f, 17.0f, 18.0f),  // vertexPosition
      DirectX::XMFLOAT2(19.0f, 20.0f),                // textureCoordinates
      21.0f                                           // vertexNumber
      },
    {
      DirectX::XMFLOAT4(22.0f, 24.0f, 24.0f, 25.0f),  // vertexPosition
      DirectX::XMFLOAT2(26.0f, 27.0f),                // textureCoordinates
      28.0f                                           // vertexNumber
    }
  };
 
#pragma region Vertex Buffer slot 0
  D3D11_BUFFER_DESC vertexBufferDesc;
  ::ZeroMemory(&vertexBufferDesc, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc.ByteWidth = sizeof(VertexPositions) * 4;
  vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc.CPUAccessFlags = 0;
  vertexBufferDesc.MiscFlags = 0;

  D3D11_SUBRESOURCE_DATA vertexBufferData;
  ::ZeroMemory(&vertexBufferData, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData.pSysMem = vpnts;
  vertexBufferData.SysMemPitch = 0;
  vertexBufferData.SysMemSlicePitch = 0;

  hr = device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &_vbBitBlock);
#pragma endregion

  INT instanceCount = 1;

  DirectX::XMFLOAT4* bitColors = new DirectX::XMFLOAT4[1];
  (*bitColors).x = 29.0f;
  (*bitColors).y = 30.0f;
  (*bitColors).z = 31.0f;
  (*bitColors).w = 32.0f;
 
  FLOAT* bitWidths = new FLOAT[1];
  (*bitWidths) = 33.0f;
 
  DirectX::XMFLOAT2* bitOffsets = new DirectX::XMFLOAT2[1];
  (*bitOffsets).x = 34.0f;
  (*bitOffsets).y = 35.0f;
 
#pragma region Vertex Buffer slot 1
  D3D11_BUFFER_DESC vertexBufferDesc_one;
  ::ZeroMemory(&vertexBufferDesc_one, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_one.ByteWidth = sizeof(DirectX::XMFLOAT4) * instanceCount;
  vertexBufferDesc_one.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_one.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_one.CPUAccessFlags = 0;
  vertexBufferDesc_one.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_one;
  ::ZeroMemory(&vertexBufferData_one, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_one.pSysMem = bitColors;
  vertexBufferData_one.SysMemPitch = 0;
  vertexBufferData_one.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_one, &vertexBufferData_one, &_vbBitColors);
  assert(SUCCEEDED(hr));
#pragma endregion

#pragma region Vertex Buffer slot 2
  D3D11_BUFFER_DESC vertexBufferDesc_two;
  ::ZeroMemory(&vertexBufferDesc_two, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_two.ByteWidth = sizeof(FLOAT) * instanceCount;
  vertexBufferDesc_two.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_two.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_two.CPUAccessFlags = 0;
  vertexBufferDesc_two.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_two;
  ::ZeroMemory(&vertexBufferData_two, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_two.pSysMem = bitWidths;
  vertexBufferData_two.SysMemPitch = 0;
  vertexBufferData_two.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_two, &vertexBufferData_two, &_vbBitWidths);
  assert(SUCCEEDED(hr));
#pragma endregion

#pragma region Vertex Buffer slot 3
  D3D11_BUFFER_DESC vertexBufferDesc_three;
  ::ZeroMemory(&vertexBufferDesc_three, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_three.ByteWidth = sizeof(DirectX::XMFLOAT2) * instanceCount;
  vertexBufferDesc_three.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_three.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_three.CPUAccessFlags = 0;
  vertexBufferDesc_three.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_three;
  ::ZeroMemory(&vertexBufferData_three, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_three.pSysMem = bitOffsets;
  vertexBufferData_three.SysMemPitch = 0;
  vertexBufferData_three.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_three, &vertexBufferData_three, &_vbBitOffsets);
  assert(SUCCEEDED(hr));
#pragma endregion
 
  const int NumVertexBuffers = 4;

  UINT strides[NumVertexBuffers];
  strides[0] = sizeof(VertexPositions);   // stride 28.
  strides[1] = sizeof(DirectX::XMFLOAT4); // stride 16.
  strides[2] = sizeof(FLOAT);             // stride 4.
  strides[3] = sizeof(DirectX::XMFLOAT2); // stride 8.

  // Set the buffer offsets.
  UINT offsets[NumVertexBuffers];
  offsets[0] = 0;
  offsets[1] = 0;
  offsets[2] = 0;
  offsets[3] = 0;

  // Set the array of pointers to the vertex and instance buffers.
  ID3D11Buffer* bufferPointers[NumVertexBuffers];
  bufferPointers[0] = _vbBitBlock;    
  bufferPointers[1] = _vbBitColors;
  bufferPointers[2] = _vbBitWidths;
  bufferPointers[3] = _vbBitOffsets;

  DeviceContext->IASetVertexBuffers(0, NumVertexBuffers, bufferPointers, strides, offsets);
 
  DeviceContext->DrawIndexedInstanced(6, instanceCount, 0, 0, 0);


The vertex buffers captured from PIX below appear to be correct.
 

 Currently used format:  float
---------------------------------------------------------------------------------------------------------------------------------
 
  0    [0x00000000-0x00000003]    |                  +1
  1    [0x00000004-0x00000007]    |                  +2
  2    [0x00000008-0x0000000b]    |                  +3
  3    [0x0000000c-0x0000000f]    |                  +4
  4    [0x00000010-0x00000013]    |                  +5
  5    [0x00000014-0x00000017]    |                  +6
  6    [0x00000018-0x0000001b]    |                  +7
  7    [0x0000001c-0x0000001f]    |                  +8
  8    [0x00000020-0x00000023]    |                  +9
  9    [0x00000024-0x00000027]    |                 +10
 10    [0x00000028-0x0000002b]    |                 +10
 11    [0x0000002c-0x0000002f]    |                 +12
 12    [0x00000030-0x00000033]    |                 +13
 13    [0x00000034-0x00000037]    |                 +14
 14    [0x00000038-0x0000003b]    |                 +15
 15    [0x0000003c-0x0000003f]    |                 +16
 16    [0x00000040-0x00000043]    |                 +17
 17    [0x00000044-0x00000047]    |                 +18
 18    [0x00000048-0x0000004b]    |                 +19
 19    [0x0000004c-0x0000004f]    |                 +20
 20    [0x00000050-0x00000053]    |                 +21
 21    [0x00000054-0x00000057]    |                 +22
 22    [0x00000058-0x0000005b]    |                 +24
 23    [0x0000005c-0x0000005f]    |                 +24
 24    [0x00000060-0x00000063]    |                 +25
 25    [0x00000064-0x00000067]    |                 +26
 26    [0x00000068-0x0000006b]    |                 +27
 27    [0x0000006c-0x0000006f]    |                 +28

  0    [0x00000000-0x00000003]    |                 +29
  1    [0x00000004-0x00000007]    |                 +30
  2    [0x00000008-0x0000000b]    |                 +31
  3    [0x0000000c-0x0000000f]    |                 +32

  0    [0x00000000-0x00000003]    |                 +33

  0    [0x00000000-0x00000003]    |                 +34
  1    [0x00000004-0x00000007]    |                 +35

Debugging the vertex shader input values within hlsl shows that most values do appear to be correct.
 

vertexPosition        x = 1.000000000, y = 2.000000000, z = 3.000000000, w = 4.000000000    float4
textureCoordinates    x = NaN, y = NaN    float2
vertexNumber          7.000000000    float
bitColour             x = 29.000000000, y = 30.000000000, z = 31.000000000, w = 32.000000000    float4
bitWidth              0.000000000    float
bitOffset             x = 34.000000000, y = 35.000000000    float2

So whats happened to 'textureCoordinates' and 'bitWidth'?

I've left out the IASetIndexBuffer() code as I don't think it's causing the issue.
I am using debug D3D11_CREATE_DEVICE_DEBUG and during execution there appears to be no DX errors or warnings.

 

Hopefully I've given enough information above to describe what I'm doing.

I've been trying to figure this out for the last week by commenting bits out and changing type sizes but nothing works.
As far as I can see it appears what I'm doing is correct so any pointers into what could be giving me the NaN and 0.000000000 would be *really* appreciated.
 
Many thanks.

Cole


#2collie

Posted 08 February 2013 - 11:43 AM

I have a problem where certain floats in a VertexShaderInput are either NaN or 0.000000000.
I have 4 streams being sent to the vertex shader.

float2 'textureCoordinates' of slot 0 always appear to be NaN.
float 'bitWidth' of slot 2 always appear to be 0.000000000.

struct VertexShaderInput
{
    // Vertex buffer slot 0.
    float4 vertexPosition      : POSITION0;
    float2 textureCoordinates  : TEXCOORD0;
    float vertexNumber         : TEXCOORD1;
    
    // Vertex buffer slot 1.
    float4 bitColour           : COLOR0;
    
    // Vertex buffer slot 2.
    float bitWidth             : TEXCOORD2;
    
    // Vertex buffer slot 4.
    float2 bitOffset           : TEXCOORD3;
};

The other floats appear to have the expected values when debugged.  Slot 2-3 are instanced streams.
I have tried changing float sizes and the matching DXGI_FORMAT_xxxx_FLOAT to no avail.

In the data I have given each float an incrementing value to make it easier to check the input.
 

  const D3D11_INPUT_ELEMENT_DESC vertexLayoutDesc[] =
  {    
    // Vertex buffer slot 0.
    { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0,
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // vertexPosition
    { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,       0, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // textureCoordinates
    { "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT,          0, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // vertexNumber    
    
    // Vertex buffer slot 1.
    { "COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitColour
    
    // Vertex buffer slot 2.
    { "TEXCOORD", 2, DXGI_FORMAT_R32_FLOAT,          2, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitWidth
    
    // Vertex buffer slot 3.
    { "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT,       3, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitOffset
  };
 
 struct VertexPositions
 {
     DirectX::XMFLOAT4 _vertexPosition;
     DirectX::XMFLOAT2 _textureCoordinates;
     FLOAT             _vertexNumber;
 }
 
 VertexPositions vpnts[] =
  {
    {
      DirectX::XMFLOAT4(1.0f, 2.0f, 3.0f, 4.0f),   // vertexPosition
      DirectX::XMFLOAT2(5.0f, 6.0f),               // textureCoordinates
      7.0f                                         // vertexNumber
    },
    {
      DirectX::XMFLOAT4(8.0f, 9.0f, 10.0f, 10.0f), // vertexPosition
      DirectX::XMFLOAT2(12.0f, 13.0f),             // textureCoordinates
      14.0f                                        // vertexNumber
    },
    {
      DirectX::XMFLOAT4(15.0f, 16.0f, 17.0f, 18.0f),  // vertexPosition
      DirectX::XMFLOAT2(19.0f, 20.0f),                // textureCoordinates
      21.0f                                           // vertexNumber
      },
    {
      DirectX::XMFLOAT4(22.0f, 24.0f, 24.0f, 25.0f),  // vertexPosition
      DirectX::XMFLOAT2(26.0f, 27.0f),                // textureCoordinates
      28.0f                                           // vertexNumber
    }
  };
 
#pragma region Vertex Buffer slot 0
  D3D11_BUFFER_DESC vertexBufferDesc;
  ::ZeroMemory(&vertexBufferDesc, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc.ByteWidth = sizeof(VertexPositions) * 4;
  vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc.CPUAccessFlags = 0;
  vertexBufferDesc.MiscFlags = 0;

  D3D11_SUBRESOURCE_DATA vertexBufferData;
  ::ZeroMemory(&vertexBufferData, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData.pSysMem = vpnts;
  vertexBufferData.SysMemPitch = 0;
  vertexBufferData.SysMemSlicePitch = 0;

  hr = device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &_vbBitBlock);
#pragma endregion

  INT instanceCount = 1;

  DirectX::XMFLOAT4* bitColors = new DirectX::XMFLOAT4[1];
  (*bitColors).x = 29.0f;
  (*bitColors).y = 30.0f;
  (*bitColors).z = 31.0f;
  (*bitColors).w = 32.0f;
 
  FLOAT* bitWidths = new FLOAT[1];
  (*bitWidths) = 33.0f;
 
  DirectX::XMFLOAT2* bitOffsets = new DirectX::XMFLOAT2[1];
  (*bitOffsets).x = 34.0f;
  (*bitOffsets).y = 35.0f;
 
#pragma region Vertex Buffer slot 1
  D3D11_BUFFER_DESC vertexBufferDesc_one;
  ::ZeroMemory(&vertexBufferDesc_one, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_one.ByteWidth = sizeof(DirectX::XMFLOAT4) * instanceCount;
  vertexBufferDesc_one.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_one.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_one.CPUAccessFlags = 0;
  vertexBufferDesc_one.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_one;
  ::ZeroMemory(&vertexBufferData_one, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_one.pSysMem = bitColors;
  vertexBufferData_one.SysMemPitch = 0;
  vertexBufferData_one.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_one, &vertexBufferData_one, &_vbBitColors);
  assert(SUCCEEDED(hr));
#pragma endregion

#pragma region Vertex Buffer slot 2
  D3D11_BUFFER_DESC vertexBufferDesc_two;
  ::ZeroMemory(&vertexBufferDesc_two, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_two.ByteWidth = sizeof(FLOAT) * instanceCount;
  vertexBufferDesc_two.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_two.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_two.CPUAccessFlags = 0;
  vertexBufferDesc_two.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_two;
  ::ZeroMemory(&vertexBufferData_two, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_two.pSysMem = bitWidths;
  vertexBufferData_two.SysMemPitch = 0;
  vertexBufferData_two.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_two, &vertexBufferData_two, &_vbBitWidths);
  assert(SUCCEEDED(hr));
#pragma endregion

#pragma region Vertex Buffer slot 3
  D3D11_BUFFER_DESC vertexBufferDesc_three;
  ::ZeroMemory(&vertexBufferDesc_three, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_three.ByteWidth = sizeof(DirectX::XMFLOAT2) * instanceCount;
  vertexBufferDesc_three.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_three.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_three.CPUAccessFlags = 0;
  vertexBufferDesc_three.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_three;
  ::ZeroMemory(&vertexBufferData_three, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_three.pSysMem = bitOffsets;
  vertexBufferData_three.SysMemPitch = 0;
  vertexBufferData_three.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_three, &vertexBufferData_three, &_vbBitOffsets);
  assert(SUCCEEDED(hr));
#pragma endregion
 
  const int NumVertexBuffers = 4;

  UINT strides[NumVertexBuffers];
  strides[0] = sizeof(VertexPositions);   // stride 28.
  strides[1] = sizeof(DirectX::XMFLOAT4); // stride 16.
  strides[2] = sizeof(FLOAT);             // stride 4.
  strides[3] = sizeof(DirectX::XMFLOAT2); // stride 8.

  // Set the buffer offsets.
  UINT offsets[NumVertexBuffers];
  offsets[0] = 0;
  offsets[1] = 0;
  offsets[2] = 0;
  offsets[3] = 0;

  // Set the array of pointers to the vertex and instance buffers.
  ID3D11Buffer* bufferPointers[NumVertexBuffers];
  bufferPointers[0] = _vbBitBlock;    
  bufferPointers[1] = _vbBitColors;
  bufferPointers[2] = _vbBitWidths;
  bufferPointers[3] = _vbBitOffsets;

  DeviceContext->IASetVertexBuffers(0, NumVertexBuffers, bufferPointers, strides, offsets);
 
  DeviceContext->DrawIndexedInstanced(6, instanceCount, 0, 0, 0);


The vertex buffers captured from PIX below appear to be correct.
 

 Currently used format:  float
---------------------------------------------------------------------------------------------------------------------------------
 
  0    [0x00000000-0x00000003]    |                  +1
  1    [0x00000004-0x00000007]    |                  +2
  2    [0x00000008-0x0000000b]    |                  +3
  3    [0x0000000c-0x0000000f]    |                  +4
  4    [0x00000010-0x00000013]    |                  +5
  5    [0x00000014-0x00000017]    |                  +6
  6    [0x00000018-0x0000001b]    |                  +7
  7    [0x0000001c-0x0000001f]    |                  +8
  8    [0x00000020-0x00000023]    |                  +9
  9    [0x00000024-0x00000027]    |                 +10
 10    [0x00000028-0x0000002b]    |                 +10
 11    [0x0000002c-0x0000002f]    |                 +12
 12    [0x00000030-0x00000033]    |                 +13
 13    [0x00000034-0x00000037]    |                 +14
 14    [0x00000038-0x0000003b]    |                 +15
 15    [0x0000003c-0x0000003f]    |                 +16
 16    [0x00000040-0x00000043]    |                 +17
 17    [0x00000044-0x00000047]    |                 +18
 18    [0x00000048-0x0000004b]    |                 +19
 19    [0x0000004c-0x0000004f]    |                 +20
 20    [0x00000050-0x00000053]    |                 +21
 21    [0x00000054-0x00000057]    |                 +22
 22    [0x00000058-0x0000005b]    |                 +24
 23    [0x0000005c-0x0000005f]    |                 +24
 24    [0x00000060-0x00000063]    |                 +25
 25    [0x00000064-0x00000067]    |                 +26
 26    [0x00000068-0x0000006b]    |                 +27
 27    [0x0000006c-0x0000006f]    |                 +28

  0    [0x00000000-0x00000003]    |                 +29
  1    [0x00000004-0x00000007]    |                 +30
  2    [0x00000008-0x0000000b]    |                 +31
  3    [0x0000000c-0x0000000f]    |                 +32

  0    [0x00000000-0x00000003]    |                 +33

  0    [0x00000000-0x00000003]    |                 +34
  1    [0x00000004-0x00000007]    |                 +35

Debugging the vertex shader input values within hlsl shows that most values do appear to be correct.
 

vertexPosition        x = 1.000000000, y = 2.000000000, z = 3.000000000, w = 4.000000000    float4
textureCoordinates    x = NaN, y = NaN    float2
vertexNumber          7.000000000    float
bitColour             x = 29.000000000, y = 30.000000000, z = 31.000000000, w = 32.000000000    float4
bitWidth              0.000000000    float
bitOffset             x = 34.000000000, y = 35.000000000    float2

So whats happened to 'textureCoordinates' and 'bitWidth'?

I've left out the IASetIndexBuffer() code as I don't think it's causing the issue.
I am using debug D3D11_CREATE_DEVICE_DEBUG and during execution there appears to be no DX errors or warnings.

 

Hopefully I've given enough information above to describe what I'm doing.

I've been trying to figure this out for the last week by commenting bits out and changing type sizes but nothing works.
As far as I can see it appears what I'm doing is correct so any pointers into what could be giving me the NaN and 0.000000000 would be *really* appreciated.
 
Many thanks.

Cole


#1collie

Posted 08 February 2013 - 11:38 AM

I have a problem where certain floats in a VertexShaderInput are either NaN or 0.000000000.
I have 4 streams being sent to the vertex shader.

float2 'textureCoordinates' of slot 0 always appear to be NaN.
float 'bitWidth' of slot 2 always appear to be 0.000000000.

struct VertexShaderInput
{
    // Vertex buffer slot 0.
    float4 vertexPosition      : POSITION0;
    float2 textureCoordinates  : TEXCOORD0;
    float vertexNumber         : TEXCOORD1;
    
    // Vertex buffer slot 1.
    float4 bitColour           : COLOR0;
    
    // Vertex buffer slot 2.
    float bitWidth             : TEXCOORD2;
    
    // Vertex buffer slot 4.
    float2 bitOffset           : TEXCOORD3;
};

The other floats appear to have the expected values when debugged.  Slot 2-3 are instanced streams.
I have tried changing float sizes and the matching DXGI_FORMAT_xxxx_FLOAT to no avail.

In the data I have given each float an incrementing value to make it easier to check the input.
 

  const D3D11_INPUT_ELEMENT_DESC vertexLayoutDesc[] =
  {    
    // Vertex buffer slot 0.
    { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0,
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // vertexPosition
    { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,       0, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // textureCoordinates
    { "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT,          0, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_VERTEX_DATA,   0 }, // vertexNumber    
    
    // Vertex buffer slot 1.
    { "COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitColour
    
    // Vertex buffer slot 2.
    { "TEXCOORD", 2, DXGI_FORMAT_R32_FLOAT,          2, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitWidth
    
    // Vertex buffer slot 3.
    { "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT,       3, D3D11_APPEND_ALIGNED_ELEMENT, 
      D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitOffset
  };
 
 struct VertexPositions
 {
     DirectX::XMFLOAT4 _vertexPosition;
     DirectX::XMFLOAT2 _textureCoordinates;
     FLOAT             _vertexNumber;
 }
 
 VertexPositions vpnts[] =
  {
    {
      DirectX::XMFLOAT4(1.0f, 2.0f, 3.0f, 4.0f),   // vertexPosition
      DirectX::XMFLOAT2(5.0f, 6.0f),               // textureCoordinates
      7.0f                                         // vertexNumber
    },
    {
      DirectX::XMFLOAT4(8.0f, 9.0f, 10.0f, 10.0f), // vertexPosition
      DirectX::XMFLOAT2(12.0f, 13.0f),             // textureCoordinates
      14.0f                                        // vertexNumber
    },
    {
      DirectX::XMFLOAT4(15.0f, 16.0f, 17.0f, 18.0f),  // vertexPosition
      DirectX::XMFLOAT2(19.0f, 20.0f),                // textureCoordinates
      21.0f                                           // vertexNumber
      },
    {
      DirectX::XMFLOAT4(22.0f, 24.0f, 24.0f, 25.0f),  // vertexPosition
      DirectX::XMFLOAT2(26.0f, 27.0f),                // textureCoordinates
      28.0f                                           // vertexNumber
    }
  };
 
#pragma region Vertex Buffer slot 0
  D3D11_BUFFER_DESC vertexBufferDesc;
  ::ZeroMemory(&vertexBufferDesc, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc.ByteWidth = sizeof(VertexPositions) * 4;
  vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc.CPUAccessFlags = 0;
  vertexBufferDesc.MiscFlags = 0;

  D3D11_SUBRESOURCE_DATA vertexBufferData;
  ::ZeroMemory(&vertexBufferData, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData.pSysMem = vpnts;
  vertexBufferData.SysMemPitch = 0;
  vertexBufferData.SysMemSlicePitch = 0;

  hr = device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &_vbBitBlock);
#pragma endregion

  INT instanceCount = 1;

  DirectX::XMFLOAT4* bitColors = new DirectX::XMFLOAT4[1];
  (*bitColors).x = 29.0f;
  (*bitColors).y = 30.0f;
  (*bitColors).z = 31.0f;
  (*bitColors).w = 32.0f;
 
  FLOAT* bitWidths = new FLOAT[1];
  (*bitWidths) = 33.0f;
 
  DirectX::XMFLOAT2* bitOffsets = new DirectX::XMFLOAT2[1];
  (*bitOffsets).x = 34.0f;
  (*bitOffsets).y = 35.0f;
 
#pragma region Vertex Buffer slot 1
  D3D11_BUFFER_DESC vertexBufferDesc_one;
  ::ZeroMemory(&vertexBufferDesc_one, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_one.ByteWidth = sizeof(DirectX::XMFLOAT4) * instanceCount;
  vertexBufferDesc_one.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_one.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_one.CPUAccessFlags = 0;
  vertexBufferDesc_one.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_one;
  ::ZeroMemory(&vertexBufferData_one, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_one.pSysMem = bitColors;
  vertexBufferData_one.SysMemPitch = 0;
  vertexBufferData_one.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_one, &vertexBufferData_one, &_vbBitColors);
  assert(SUCCEEDED(hr));
#pragma endregion

#pragma region Vertex Buffer slot 2
  D3D11_BUFFER_DESC vertexBufferDesc_two;
  ::ZeroMemory(&vertexBufferDesc_two, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_two.ByteWidth = sizeof(FLOAT) * instanceCount;
  vertexBufferDesc_two.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_two.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_two.CPUAccessFlags = 0;
  vertexBufferDesc_two.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_two;
  ::ZeroMemory(&vertexBufferData_two, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_two.pSysMem = bitWidths;
  vertexBufferData_two.SysMemPitch = 0;
  vertexBufferData_two.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_two, &vertexBufferData_two, &_vbBitWidths);
  assert(SUCCEEDED(hr));
#pragma endregion

#pragma region Vertex Buffer slot 3
  D3D11_BUFFER_DESC vertexBufferDesc_three;
  ::ZeroMemory(&vertexBufferDesc_three, sizeof(D3D11_BUFFER_DESC));
  vertexBufferDesc_three.ByteWidth = sizeof(DirectX::XMFLOAT2) * instanceCount;
  vertexBufferDesc_three.Usage = D3D11_USAGE_DEFAULT;
  vertexBufferDesc_three.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  vertexBufferDesc_three.CPUAccessFlags = 0;
  vertexBufferDesc_three.MiscFlags = 0;
 
  D3D11_SUBRESOURCE_DATA vertexBufferData_three;
  ::ZeroMemory(&vertexBufferData_three, sizeof(D3D11_SUBRESOURCE_DATA));
  vertexBufferData_three.pSysMem = bitOffsets;
  vertexBufferData_three.SysMemPitch = 0;
  vertexBufferData_three.SysMemSlicePitch = 0;
    
  hr = device->CreateBuffer(&vertexBufferDesc_three, &vertexBufferData_three, &_vbBitOffsets);
  assert(SUCCEEDED(hr));
#pragma endregion
 
  const int NumVertexBuffers = 4;

  UINT strides[NumVertexBuffers];
  strides[0] = sizeof(VertexPositions);   // stride 28.
  strides[1] = sizeof(DirectX::XMFLOAT4); // stride 16.
  strides[2] = sizeof(FLOAT);             // stride 4.
  strides[3] = sizeof(DirectX::XMFLOAT2); // stride 8.

  // Set the buffer offsets.
  UINT offsets[NumVertexBuffers];
  offsets[0] = 0;
  offsets[1] = 0;
  offsets[2] = 0;
  offsets[3] = 0;

  // Set the array of pointers to the vertex and instance buffers.
  ID3D11Buffer* bufferPointers[NumVertexBuffers];
  bufferPointers[0] = _vbBitBlock;    
  bufferPointers[1] = _vbBitColors;
  bufferPointers[2] = _vbBitWidths;
  bufferPointers[3] = _vbBitOffsets;

  DeviceContext->IASetVertexBuffers(0, NumVertexBuffers, bufferPointers, strides, offsets);
 
  DeviceContext->DrawIndexedInstanced(6, instanceCount, 0, 0, 0);


The vertex buffers captured from PIX below appear to be correct.
 

 Currently used format:  float
---------------------------------------------------------------------------------------------------------------------------------
 
  0    [0x00000000-0x00000003]    |                  +1
  1    [0x00000004-0x00000007]    |                  +2
  2    [0x00000008-0x0000000b]    |                  +3
  3    [0x0000000c-0x0000000f]    |                  +4
  4    [0x00000010-0x00000013]    |                  +5
  5    [0x00000014-0x00000017]    |                  +6
  6    [0x00000018-0x0000001b]    |                  +7
  7    [0x0000001c-0x0000001f]    |                  +8
  8    [0x00000020-0x00000023]    |                  +9
  9    [0x00000024-0x00000027]    |                 +10
 10    [0x00000028-0x0000002b]    |                 +10
 11    [0x0000002c-0x0000002f]    |                 +12
 12    [0x00000030-0x00000033]    |                 +13
 13    [0x00000034-0x00000037]    |                 +14
 14    [0x00000038-0x0000003b]    |                 +15
 15    [0x0000003c-0x0000003f]    |                 +16
 16    [0x00000040-0x00000043]    |                 +17
 17    [0x00000044-0x00000047]    |                 +18
 18    [0x00000048-0x0000004b]    |                 +19
 19    [0x0000004c-0x0000004f]    |                 +20
 20    [0x00000050-0x00000053]    |                 +21
 21    [0x00000054-0x00000057]    |                 +22
 22    [0x00000058-0x0000005b]    |                 +24
 23    [0x0000005c-0x0000005f]    |                 +24
 24    [0x00000060-0x00000063]    |                 +25
 25    [0x00000064-0x00000067]    |                 +26
 26    [0x00000068-0x0000006b]    |                 +27
 27    [0x0000006c-0x0000006f]    |                 +28

  0    [0x00000000-0x00000003]    |                 +29
  1    [0x00000004-0x00000007]    |                 +30
  2    [0x00000008-0x0000000b]    |                 +31
  3    [0x0000000c-0x0000000f]    |                 +32

  0    [0x00000000-0x00000003]    |                 +33

  0    [0x00000000-0x00000003]    |                 +34
  1    [0x00000004-0x00000007]    |                 +35

Debugging the vertex shader input values within hlsl shows that the most values do appear to be coming in correct.
 

vertexPosition        x = 1.000000000, y = 2.000000000, z = 3.000000000, w = 4.000000000    float4
textureCoordinates    x = NaN, y = NaN    float2
vertexNumber          7.000000000    float
bitColour             x = 29.000000000, y = 30.000000000, z = 31.000000000, w = 32.000000000    float4
bitWidth              0.000000000    float
bitOffset             x = 34.000000000, y = 35.000000000    float2

So whats happened to 'textureCoordinates' and 'bitWidth'?

I've left out the IASetIndexBuffer() code as I don't think it's causing the issue.
I am using debug D3D11_CREATE_DEVICE_DEBUG and during execution there appears to be no DX errors or warnings.

 

Hopefully I've given enough information above to describe what I'm doing.

I've been trying to figure this out for the last week by commenting bits out and changing type sizes but nothing works.
As far as I can see it appears what I'm doing is correct so any pointers into what could be giving me the NaN and 0.000000000 would be *really* appreciated.
 
Many thanks.

Cole


PARTNERS