コード例 #1
0
void FSlateD3DRenderer::Private_CreateViewport( TSharedRef<SWindow> InWindow, const FVector2D &WindowSize )
{
	TSharedRef< FGenericWindow > NativeWindow = InWindow->GetNativeWindow().ToSharedRef();

	bool bFullscreen = IsViewportFullscreen( *InWindow );
	bool bWindowed = true;//@todo implement fullscreen: !bFullscreen;

	DXGI_SWAP_CHAIN_DESC SwapChainDesc;
	FMemory::Memzero(&SwapChainDesc, sizeof(SwapChainDesc) );
	SwapChainDesc.BufferCount = 1;
	SwapChainDesc.BufferDesc.Width = FMath::TruncToInt(WindowSize.X);
	SwapChainDesc.BufferDesc.Height = FMath::TruncToInt(WindowSize.Y);
	SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
	SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	SwapChainDesc.OutputWindow = (HWND)NativeWindow->GetOSWindowHandle();
	SwapChainDesc.SampleDesc.Count = 1;
	SwapChainDesc.SampleDesc.Quality = 0;
	SwapChainDesc.Windowed = bWindowed;
	SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
	SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

	TRefCountPtr<IDXGIDevice> DXGIDevice;
	HRESULT Hr = GD3DDevice->QueryInterface( __uuidof(IDXGIDevice), (void**)DXGIDevice.GetInitReference() );
	check( SUCCEEDED(Hr) );

	TRefCountPtr<IDXGIAdapter> DXGIAdapter;
	Hr = DXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void **)DXGIAdapter.GetInitReference() );
	check( SUCCEEDED(Hr) );

	TRefCountPtr<IDXGIFactory> DXGIFactory;
	DXGIAdapter->GetParent(__uuidof(IDXGIFactory), (void **)DXGIFactory.GetInitReference() );
	check( SUCCEEDED(Hr) );

	FSlateD3DViewport Viewport;

	Hr = DXGIFactory->CreateSwapChain(DXGIDevice.GetReference(), &SwapChainDesc, Viewport.D3DSwapChain.GetInitReference() );
	check( SUCCEEDED(Hr) );

	Hr = DXGIFactory->MakeWindowAssociation((HWND)NativeWindow->GetOSWindowHandle(),DXGI_MWA_NO_ALT_ENTER);
	check(SUCCEEDED(Hr));

	uint32 Width = FMath::TruncToInt(WindowSize.X);
	uint32 Height = FMath::TruncToInt(WindowSize.Y);

	Viewport.ViewportInfo.MaxDepth = 1.0f;
	Viewport.ViewportInfo.MinDepth = 0.0f;
	Viewport.ViewportInfo.Width = Width;
	Viewport.ViewportInfo.Height = Height;
	Viewport.ViewportInfo.TopLeftX = 0;
	Viewport.ViewportInfo.TopLeftY = 0;
	
	CreateBackBufferResources( Viewport.D3DSwapChain, Viewport.BackBufferTexture, Viewport.RenderTargetView );

	Viewport.ProjectionMatrix = CreateProjectionMatrixD3D( Width, Height );

	WindowToViewportMap.Add( &InWindow.Get(), Viewport );

}
コード例 #2
0
FIndexBufferRHIRef FOpenGLDynamicRHI::RHICreateIndexBuffer(uint32 Stride,uint32 Size, uint32 InUsage, FRHIResourceCreateInfo& CreateInfo)
{
	VERIFY_GL_SCOPE();

	const void *Data = NULL;

	// If a resource array was provided for the resource, create the resource pre-populated
	if(CreateInfo.ResourceArray)
	{
		check(Size == CreateInfo.ResourceArray->GetResourceDataSize());
		Data = CreateInfo.ResourceArray->GetResourceData();
	}

	TRefCountPtr<FOpenGLIndexBuffer> IndexBuffer = new FOpenGLIndexBuffer(Stride, Size, InUsage, Data);
	return IndexBuffer.GetReference();
}
コード例 #3
0
static void CompileShader( const FString& Filename, const FString& EntryPoint, const FString& ShaderModel, TRefCountPtr<ID3DBlob>& OutBlob )
{
	uint32 ShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if UE_BUILD_DEBUG
	ShaderFlags |= D3D10_SHADER_DEBUG;
#else
	ShaderFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3;
#endif

	TRefCountPtr<ID3DBlob> ErrorBlob;
	HRESULT Hr = D3DX11CompileFromFile( *Filename, NULL, NULL, TCHAR_TO_ANSI(*EntryPoint), TCHAR_TO_ANSI(*ShaderModel), ShaderFlags, 0, NULL, OutBlob.GetInitReference(), ErrorBlob.GetInitReference(), NULL );
	if( FAILED(Hr) )
	{
		if( ErrorBlob.GetReference() )
		{
			checkf(0, ANSI_TO_TCHAR(ErrorBlob->GetBufferPointer()));
		}
	}
}
コード例 #4
0
ファイル: D3D11State.cpp プロジェクト: xiangyuan/Unreal4
FSamplerStateRHIRef FD3D11DynamicRHI::RHICreateSamplerState(const FSamplerStateInitializerRHI& Initializer)
{
	D3D11_SAMPLER_DESC SamplerDesc;
	FMemory::Memzero(&SamplerDesc,sizeof(D3D11_SAMPLER_DESC));

	int32 MaxAnisotropyCVar = GetCachedScalabilityCVars().MaxAnisotropy;

	SamplerDesc.AddressU = TranslateAddressMode(Initializer.AddressU);
	SamplerDesc.AddressV = TranslateAddressMode(Initializer.AddressV);
	SamplerDesc.AddressW = TranslateAddressMode(Initializer.AddressW);
	SamplerDesc.MipLODBias = Initializer.MipBias;
	SamplerDesc.MaxAnisotropy = FMath::Clamp(Initializer.MaxAnisotropy > 0 ? Initializer.MaxAnisotropy : MaxAnisotropyCVar,1,16);
	SamplerDesc.MinLOD = Initializer.MinMipLevel;
	SamplerDesc.MaxLOD = Initializer.MaxMipLevel;

	// Determine whether we should use one of the comparison modes
	const bool bComparisonEnabled = Initializer.SamplerComparisonFunction != SCF_Never;
	switch(Initializer.Filter)
	{
	case SF_AnisotropicLinear:
	case SF_AnisotropicPoint:
		if (SamplerDesc.MaxAnisotropy == 1)
		{
			SamplerDesc.Filter = bComparisonEnabled ? D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
		}
		else
		{
			// D3D11 doesn't allow using point filtering for mip filter when using anisotropic filtering
			SamplerDesc.Filter = bComparisonEnabled ? D3D11_FILTER_COMPARISON_ANISOTROPIC : D3D11_FILTER_ANISOTROPIC;
		}
		
		break;
	case SF_Trilinear:
        SamplerDesc.Filter = bComparisonEnabled ? D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
		break;
	case SF_Bilinear:
		SamplerDesc.Filter = bComparisonEnabled ? D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT : D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
		break;
	case SF_Point:
		SamplerDesc.Filter = bComparisonEnabled ? D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_POINT;
		break;
	}
	const FLinearColor LinearBorderColor = FColor(Initializer.BorderColor);
	SamplerDesc.BorderColor[0] = LinearBorderColor.R;
	SamplerDesc.BorderColor[1] = LinearBorderColor.G;
	SamplerDesc.BorderColor[2] = LinearBorderColor.B;
	SamplerDesc.BorderColor[3] = LinearBorderColor.A;
	SamplerDesc.ComparisonFunc = TranslateSamplerCompareFunction(Initializer.SamplerComparisonFunction);

#if LOCK_GSamplerStateCache
	QUICK_SCOPE_CYCLE_COUNTER(FD3D11DynamicRHI_RHICreateSamplerState_LockAndCreate);
	FScopeLock Lock(&GSamplerStateCacheLock);
#endif

	// D3D11 will return the same pointer if the particular state description was already created
	TRefCountPtr<ID3D11SamplerState> SamplerStateHandle;
	VERIFYD3D11RESULT(Direct3DDevice->CreateSamplerState(&SamplerDesc, SamplerStateHandle.GetInitReference()));

	FD3D11SamplerState** Found = GSamplerStateCache.Find(SamplerStateHandle);
	if (Found)
	{
		return *Found;
	}

	FD3D11SamplerState* SamplerState = new FD3D11SamplerState;
	SamplerState->Resource = SamplerStateHandle;
	// Manually add reference as we control the creation/destructions
	SamplerState->AddRef();
	GSamplerStateCache.Add(SamplerStateHandle.GetReference(), SamplerState);
	return SamplerState;
}
コード例 #5
0
void FD3D11StateCacheBase::VerifyCacheState()
{
	if (!Direct3DDeviceIMContext)
	{
		return;
	}

	// Verify Shader States
	{
		TRefCountPtr<ID3D11VertexShader> VertexShader;
		TRefCountPtr<ID3D11HullShader> HullShader;
		TRefCountPtr<ID3D11DomainShader> DomainShader;
		TRefCountPtr<ID3D11GeometryShader> GeometryShader;
		TRefCountPtr<ID3D11PixelShader> PixelShader;
		TRefCountPtr<ID3D11ComputeShader> ComputeShader;

		Direct3DDeviceIMContext->VSGetShader(VertexShader.GetInitReference(), nullptr, nullptr);
		Direct3DDeviceIMContext->HSGetShader(HullShader.GetInitReference(), nullptr, nullptr);
		Direct3DDeviceIMContext->DSGetShader(DomainShader.GetInitReference(), nullptr, nullptr);
		Direct3DDeviceIMContext->GSGetShader(GeometryShader.GetInitReference(), nullptr, nullptr);
		Direct3DDeviceIMContext->PSGetShader(PixelShader.GetInitReference(), nullptr, nullptr);
		Direct3DDeviceIMContext->CSGetShader(ComputeShader.GetInitReference(), nullptr, nullptr);

		check(VertexShader.GetReference() == CurrentVertexShader);
		check(HullShader.GetReference() == CurrentHullShader);
		check(DomainShader.GetReference() == CurrentDomainShader);
		check(GeometryShader.GetReference() == CurrentGeometryShader);
		check(PixelShader.GetReference() == CurrentPixelShader);
		check(ComputeShader.GetReference() == CurrentComputeShader);
	}

	// Verify Depth Stencil State
	{
		TRefCountPtr<ID3D11DepthStencilState> DepthStencilState;
		uint32 StencilRef;

		Direct3DDeviceIMContext->OMGetDepthStencilState(DepthStencilState.GetInitReference(), &StencilRef);

		check(DepthStencilState.GetReference() == CurrentDepthStencilState);
		check(StencilRef == CurrentReferenceStencil);
	}

	// Verify Rasterizer State
	{
		TRefCountPtr<ID3D11RasterizerState> RasterizerState;

		Direct3DDeviceIMContext->RSGetState(RasterizerState.GetInitReference());

		check(RasterizerState.GetReference() == CurrentRasterizerState);
	}

	// Verify Blend State
	{
		TRefCountPtr<ID3D11BlendState> BlendState;
		float BlendFactor[4];
		uint32 SampleMask;

		Direct3DDeviceIMContext->OMGetBlendState(BlendState.GetInitReference(), BlendFactor, &SampleMask);

		check(BlendState.GetReference() == CurrentBlendState);
		check(FMemory::Memcmp(BlendFactor, CurrentBlendFactor, sizeof(CurrentBlendFactor)) == 0);
		check(SampleMask == CurrentBlendSampleMask);
	}

	// Verify Viewport state
	{
		D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
		uint32 numVP = CurrentNumberOfViewports;
		Direct3DDeviceIMContext->RSGetViewports(&numVP,&vp[0]);
		check(numVP == CurrentNumberOfViewports);
		check( FMemory::Memcmp( &vp, &CurrentViewport[0],sizeof(D3D11_VIEWPORT) * CurrentNumberOfViewports) ==0);
	}
	
	// Verify Input Layout
	{
		TRefCountPtr<ID3D11InputLayout> InputLayout;
		Direct3DDeviceIMContext->IAGetInputLayout(InputLayout.GetInitReference());
		check(InputLayout.GetReference() == CurrentInputLayout);
	}

	// Verify Sampler States
	{
		VerifySamplerStates<SF_Vertex>();
		VerifySamplerStates<SF_Hull>();
		VerifySamplerStates<SF_Domain>();
		VerifySamplerStates<SF_Geometry>();
		VerifySamplerStates<SF_Pixel>();
		VerifySamplerStates<SF_Compute>();
	}

	// Verify Vertex Buffers
	{
		ID3D11Buffer* VertexBuffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
		uint32 Strides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
		uint32 Offsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];

		Direct3DDeviceIMContext->IAGetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, VertexBuffers, Strides, Offsets);

		for (uint32 Index = 0; Index < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; Index++)
		{
			check(VertexBuffers[Index] == CurrentVertexBuffers[Index].VertexBuffer);
			check(Strides[Index] == CurrentVertexBuffers[Index].Stride);
			check(Offsets[Index] == CurrentVertexBuffers[Index].Offset);
			if (VertexBuffers[Index])
			{
				VertexBuffers[Index]->Release();
			}
		}
	}

	// Verify Index Buffer
	{
		TRefCountPtr<ID3D11Buffer> IndexBuffer;
		DXGI_FORMAT Format;
		uint32 Offset;

		Direct3DDeviceIMContext->IAGetIndexBuffer(IndexBuffer.GetInitReference(), &Format, &Offset);

		check(IndexBuffer.GetReference() == CurrentIndexBuffer);
		check(Format == CurrentIndexFormat);
		check(Offset == CurrentIndexOffset);
	}

	// Verify Primitive Topology
	{
		D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology;
		Direct3DDeviceIMContext->IAGetPrimitiveTopology(&PrimitiveTopology);
		check(PrimitiveTopology == CurrentPrimitiveTopology);
	}

	// Verify Constant Buffers
	{
		((FD3D11StateCache*)this)->VerifyConstantBuffers<SF_Vertex>();
		((FD3D11StateCache*)this)->VerifyConstantBuffers<SF_Hull>();
		((FD3D11StateCache*)this)->VerifyConstantBuffers<SF_Domain>();
		((FD3D11StateCache*)this)->VerifyConstantBuffers<SF_Geometry>();
		((FD3D11StateCache*)this)->VerifyConstantBuffers<SF_Pixel>();
		((FD3D11StateCache*)this)->VerifyConstantBuffers<SF_Compute>();
	}

	// Verify Shader Resource Views
	{
		VerifyShaderResourceViews<SF_Vertex>();
		VerifyShaderResourceViews<SF_Hull>();
		VerifyShaderResourceViews<SF_Domain>();
		VerifyShaderResourceViews<SF_Geometry>();
		VerifyShaderResourceViews<SF_Pixel>();
		VerifyShaderResourceViews<SF_Compute>();
	}
}