Ejemplo n.º 1
0
void FSlateD3DPS::Create( const FString& Filename, const FString& EntryPoint, const FString& ShaderModel )
{
	TRefCountPtr<ID3DBlob> Blob;
	CompileShader( Filename, EntryPoint, ShaderModel, Blob);

	HRESULT Hr = GD3DDevice->CreatePixelShader( Blob->GetBufferPointer(), Blob->GetBufferSize(), NULL, PixelShader.GetInitReference() );
	check( SUCCEEDED(Hr) );


	TRefCountPtr<ID3D11ShaderReflection> Reflector;
	Hr = D3DReflect( Blob->GetBufferPointer(), Blob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**)Reflector.GetInitReference() );
	check( SUCCEEDED(Hr) );

	GetShaderBindings( Reflector, ShaderBindings );
}
Ejemplo n.º 2
0
void FSlateD3DVS::Create( const FString& Filename, const FString& EntryPoint, const FString& ShaderModel, D3D11_INPUT_ELEMENT_DESC* VertexLayout, uint32 VertexLayoutCount )
{
	TRefCountPtr<ID3DBlob> Blob;
	CompileShader( Filename, EntryPoint, ShaderModel, Blob);

	HRESULT Hr = GD3DDevice->CreateVertexShader( Blob->GetBufferPointer(), Blob->GetBufferSize(), NULL, VertexShader.GetInitReference() );
	check( SUCCEEDED(Hr) );

	Hr = GD3DDevice->CreateInputLayout( VertexLayout, VertexLayoutCount, Blob->GetBufferPointer(), Blob->GetBufferSize(), InputLayout.GetInitReference() );
	check( SUCCEEDED(Hr) );

	TRefCountPtr<ID3D11ShaderReflection> Reflector;
	Hr = D3DReflect( Blob->GetBufferPointer(), Blob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**)Reflector.GetInitReference() );
	check( SUCCEEDED(Hr) );

	GetShaderBindings( Reflector, ShaderBindings );
}
Ejemplo n.º 3
0
static UBOOL D3D9CompileShaderWrapper(
	const TCHAR* ShaderFilename,
	const TCHAR* FunctionName,
	const TCHAR* ShaderProfile,
	DWORD CompileFlags,
	const FShaderCompilerEnvironment& InEnvironment,
	const vector<D3DXMACRO>& Macros,
	FShaderCompilerOutput& Output,
	vector<FD3D9ConstantDesc>& Constants,
	FString& DisassemblyString,
	FString& ErrorString
	)
{
	const FString& SourceFile = LoadShaderSourceFile(ShaderFilename);

	TRefCountPtr<ID3DXBuffer> Shader;
	TRefCountPtr<ID3DXBuffer> Errors;
	FD3DIncludeEnvironment Environment(InEnvironment);
	TRefCountPtr<ID3DXConstantTable> ConstantTable;
	FTCHARToANSI AnsiSourceFile(SourceFile.c_str());
	HRESULT Result = D3DXCompileShader(
						AnsiSourceFile, 
						SourceFile.size(), 
						&Macros[0], 
						&Environment, 
						TCHAR_TO_ANSI(FunctionName), 
						TCHAR_TO_ANSI(ShaderProfile),
						CompileFlags, 
						Shader.GetInitReference(),
						Errors.GetInitReference(), 
						ConstantTable.GetInitReference());

	if( FAILED(Result) )
	{
		ErrorString = TEXT("Compile Failed without warnings!");
		void* ErrorBuffer = Errors ? Errors->GetBufferPointer() : NULL;
		if( ErrorBuffer )
		{
			FANSIToTCHAR Convert((ANSICHAR*)ErrorBuffer);
			ErrorString = Convert;
		}
	}
	else
	{
		// get the ShaderCode
		INT NumShaderBytes = Shader->GetBufferSize();
		Output.ShaderCode.resize(NumShaderBytes);
		appMemcpy(&Output.ShaderCode[0], Shader->GetBufferPointer(), NumShaderBytes);

		// collect the constant table
		D3DXCONSTANTTABLE_DESC ConstantTableDesc;
		VERIFYD3DRESULT(ConstantTable->GetDesc(&ConstantTableDesc));
		for(UINT ConstantIndex = 0; ConstantIndex < ConstantTableDesc.Constants; ++ConstantIndex)
		{
			D3DXHANDLE ConstantHandle = ConstantTable->GetConstant(NULL, ConstantIndex);

			D3DXCONSTANT_DESC ConstantDesc;
			UINT NumConstants = 1;
			VERIFYD3DRESULT(ConstantTable->GetConstantDesc(ConstantHandle, &ConstantDesc, &NumConstants));

			FD3D9ConstantDesc NamedConstantDesc;
			appStrcpyANSI(NamedConstantDesc.Name, ConstantDesc.Name);
			NamedConstantDesc.bIsSampler = ConstantDesc.RegisterSet == D3DXRS_SAMPLER;
			NamedConstantDesc.RegisterIndex = ConstantDesc.RegisterIndex;
			NamedConstantDesc.RegisterCount = ConstantDesc.RegisterCount;
			Constants.push_back(NamedConstantDesc);
		}

		// disassemble a shader
		TRefCountPtr<ID3DXBuffer> DisassemblyBuffer;
		VERIFYD3DRESULT(D3DXDisassembleShader((const DWORD*)Shader->GetBufferPointer(), FALSE, NULL, DisassemblyBuffer.GetInitReference()));
		DisassemblyString = ANSI_TO_TCHAR((ANSICHAR*)DisassemblyBuffer->GetBufferPointer());
	}

	return TRUE;
}