Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been particularly annoyed by a 'bug' for a couple days involving D3DCompile and vertex shaders with constant buffers. I'm assuming the bug is my fault (missing flag or small nuance of the poorly documented API).

During my asset compile process I compile this vertex shader:

cbuffer Frame : register(b0) {
  float4x4 model_view_proj;
  float4x4 inv_model;
  float4x4 inv_view;
  float4x4 inv_projection;
};

struct VS_INPUT {
  float3 position  : POSITION;
  float2 tex_coord : TEXCOORD0;
  float3 normal    : NORMAL;
  float3 binormal  : BINORMAL;
};

struct VS_OUTPUT {
  float4 position  : POSITION;
  float2 tex_coord : TEXCOORD0;
};

VS_OUTPUT vs_main( VS_INPUT IN )
{
  VS_OUTPUT OUT;
  OUT.position = mul(IN.position, Frame.model_view_proj);
  OUT.tex_coord = IN.tex_coord;
  return OUT;
}

With this code:

const D3D_SHADER_MACRO defines[] = {
  { "VERTEX_SHADER", "1" },
  { "D3D11",         "1" },
  { NULL, NULL },
};

D3DCompile(
  src, src_len,
  path,
  &defines[0],
  &include,
  "vs_main",
  "vs_4_0",
  D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY |
  D3DCOMPILE_OPTIMIZATION_LEVEL0 |
  D3DCOMPILE_PACK_MATRIX_ROW_MAJOR, 0,
  &blob,
  &error_msg_blob
)

I have verified (by stepping through) that my ID3DInclude implementation works and all input data is correct. However, I receive a E_FAIL with an associated error message:

error X3004: undeclared identifier 'Frame'

What gives?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Constant buffers don't create a namespace; their members are visible at global scope. So instead of Frame.model_view_proj you just want model_view_proj.

share|improve this answer
    
Thanks! Makes sense in retrospect; it's a natural extension to DX9. –  devbug Jan 16 '13 at 7:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.