Jump to content

  • Log In with Google      Sign In   
  • Create Account


Joakim1234

Member Since 27 Jul 2012
Offline Last Active Jul 28 2012 01:01 PM

Topics I've Started

ID3D11Device::CreateBuffer returning E_INVALIDARG for no apparent reason.[RESOLVED]

27 July 2012 - 06:33 PM

I'm using a little helper function to create vertex buffers:
void AssetManager::CreateVertexBuffer(ID3D11Buffer** buffer, unsigned int bufferSize, void* vertices, D3D11_USAGE bufferUsage, D3D11_CPU_ACCESS_FLAG processorAccess)
{
	D3D11_BUFFER_DESC bufferDesc;
	D3D11_SUBRESOURCE_DATA subResData;

	bufferDesc.Usage = bufferUsage;
	bufferDesc.ByteWidth = bufferSize;
	bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	bufferDesc.CPUAccessFlags = processorAccess;
	bufferDesc.MiscFlags = 0;
	bufferDesc.StructureByteStride = 0;

	subResData.pSysMem = vertices;
	subResData.SysMemPitch = 0;
	subResData.SysMemSlicePitch = 0;
	HR(gD3DDevice->CreateBuffer(&bufferDesc, &subResData, buffer));
}

And it causes a E_INVALIDARG error,but doesn't give a clue about which argument is the invalid one.Here is how the function is called in the program:
vertexBuffer = 0;

VertexType* vertices = new VertexType[vertexCount];;

vertices[0].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); //just random values to see if it debugs at all
vertices[0].texture = XMFLOAT2(0.0f, 1.0f);
vertices[1].position = XMFLOAT3(0.0f, 1.0f, 0.0f);
vertices[1].texture = XMFLOAT2(0.5f, 0.0f);

vertices[2].position = XMFLOAT3(1.0f, -1.0f, 0.0f);
vertices[2].texture = XMFLOAT2(1.0f, 1.0f);


AssetManager->CreateVertexBuffer(&vertexBuffer,sizeof(VertexType)*vertexCount, &vertices);

Could the problem be in "bufferDesc.StructureByteStride = 0;"?Am I supposed to leave it at 0?Cause all the tutorial project files leave it at 0 and they compile just fine.But the problem can't be in the project itself,I linked all the needed libraries and the paths to the SDK.

Possible causes for ''D3DX11CompileFromFile'' to return E_FAIL?[RESOLVED]

27 July 2012 - 01:24 PM

When I call
D3DX11CompileFromFile(pixelShaderPath, NULL, NULL, "SpritePixelShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelShaderBuffer, NULL, NULL);
I get the error message:

Unexpected error encountered
Error Code: E_FAIL(0x80004005)
Calling: D3DX11CompileFromFile(pixelShaderPath, NULL, NULL, "SpritePixelShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelShaderBuffer, NULL, NULL)

The D3DX11CompileFromFile(vertexShaderPath, NULL, NULL, "SpriteVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, NULL, NULL) function doesn't cause an error,but on the next 2 lines where I call CreateVertexShader and CreatePixelShader, CreateVertexShader does cause an error:

Unexpected error encountered
Error Code: E_INVALIDARG(0x80070057)
Calling: CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertexShader))

Which brings me to believe,that D3DX11CompileFromFile(vertexShaderPath, NULL, NULL, "SpriteVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, NULL, NULL) also didn't work out very well.All the pointers are initialized properly before calling these functions,so that can't be it:
vertexShader = 0;
pixelShader = 0;
vertexShaderBuffer = 0;
pixelShaderBuffer = 0;
And it can't be from not finding the SpriteEffect.vs and SpriteEffect.ps files,they're right next to the source files,I also copied them in the debug folder to be next to the .exe just in case.Could the problem be invalid code in the shader files themselves?They're just a simple instanced geometry/bump map effect:
cbuffer MatrixBuffer
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};
struct VertexInputType
{
	float4 position : POSITION;
	float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
float3 instancePosition : TEXCOORD1;
};
struct PixelInputType
{
	float4 position : SV_POSITION;
	float2 tex : TEXCOORD0;
	float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
};
PixelInputType SpriteVertexShader(VertexInputType input)
{
	PixelInputType output;
  
	input.position.w = 1.0f;
	input.position.x += input.instancePosition.x;
	input.position.y += input.instancePosition.y;
	input.position.z += input.instancePosition.z;
	output.position = mul(input.position, worldMatrix);
	output.position = mul(output.position, viewMatrix);
	output.position = mul(output.position, projectionMatrix);
  
output.tex = input.tex;
	output.normal = mul(input.normal, (float3x3)worldMatrix);
	output.normal = normalize(output.normal);
	output.tangent = mul(input.tangent, (float3x3)worldMatrix);
	output.tangent = normalize(output.tangent);
	output.binormal = mul(input.binormal, (float3x3)worldMatrix);
	output.binormal = normalize(output.binormal);
  
	return output;
}

Texture2D shaderTexture;


SamplerState SampleType;
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
};
float4 SpritePixelShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float4 bumpMap;
float3 bumpNormal;
float3 lightDir;
float lightIntensity;
float4 color;
textureColor = shaderTextures[0].Sample(SampleType, input.tex);

bumpMap = shaderTextures[1].Sample(SampleType, input.tex);
bumpMap = (bumpMap * 2.0f) - 1.0f;

bumpNormal = input.normal + bumpMap.x * input.tangent + bumpMap.y * input.binormal;

bumpNormal = normalize(bumpNormal);
lightDir = -lightDirection;
lightIntensity = saturate(dot(bumpNormal, lightDir));
color = saturate(diffuseColor * lightIntensity);
color = color * textureColor;

return color;
}
I don't have syntax highlighting for HLSL,so it's possible that I missed something stupid.Any help would be appreciated.

PARTNERS