I'm using DirectX 11. I pre-compiling the shader and then loading at a runtime. I'm loading the file into a buffer and then sending it in to CreateVertexShader. When I call CreateVertexShader with the debug layer turned on, I get the following error:
Encoded Vertex Shader size doesn't match specified size
I'm compiling the vertex shader at the command line as follows:
fxc /Fc /Od /Zi /T fx_5_0 /Fo "myfile.cso" "myfile.fx"
In the case of a simple shader, the resulting file is around 200 bytes. I can verify that Windows explorer and my code both report the same number of bytes.
I've tried variations of fx_5_0.
Here is how I am loading the file:
uint32_t length, rr;
char *buffer;
FILE *fp;
fp = fopen("<path to file>\\myfile.cso", "rb");
fseek(fp, 0, SEEK_END);
length = ftell(fp);
fseek(fp, 0, SEEK_SET);
buffer = (char*)calloc(1, length);
rr = fread(buffer, sizeof(char), length, fp);
fclose(fp);
assert(rr == length);
Then:
hr = device->lpVtbl->CreateVertexShader(device, buffer, length, NULL, NULL );
(Note: I'm passing NULL to the last param expecting to get S_FALSE as the return code)
I'm not sure what else to try to solve this.
I figured it out.
The entry point was not right in the shader.
The
fxc
command compiled my shader with no errors or warnings, but my shader didn't have the entry point properly defined. Weird.That's why the byte code was only about 200 bytes. That said, my shader was very simple, a pass-through, I could have believed it was 200 bytes. It's more like 15k compiled.
It's really strange how a short HLSL program (1061 bytes of source) explodes to 15k of byte code.