Ejemplo n.º 1
0
//==============================================================================================================================
bool OBJMeshShader::Initialize()
{
	ConstantBuffer<ZShadeSandboxLighting::cbMaterialShadingBuffer> objShadingCB(m_pD3DSystem);
	objShadingCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbMaterialShadingBuffer)));
	m_pShadingCB = objShadingCB.Buffer();
	
	ConstantBuffer<cbMatrixBuffer> matrixBufferCB(m_pD3DSystem);
	matrixBufferCB.Initialize(PAD16(sizeof(cbMatrixBuffer)));
	m_pMatrixCB = matrixBufferCB.Buffer();
	
	ConstantBuffer<ZShadeSandboxLighting::cbLightBuffer> lightCB(m_pD3DSystem);
	lightCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbLightBuffer)));
	m_pLightCB = lightCB.Buffer();

	ConstantBuffer<ZShadeSandboxLighting::cbSunLightBuffer> sunCB(m_pD3DSystem);
	sunCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbSunLightBuffer)));
	m_pSunCB = sunCB.Buffer();

	ClearInputLayout();
	SetInputLayoutDesc("OBJMeshShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_normal_tex, 3);
	LoadVertexShader("OBJMeshVS");
	LoadPixelShader("OBJMeshPS");
	LoadPixelShader("OBJMeshWireframePS");
	AssignVertexShaderLayout("OBJMeshShader");
	
	return true;
}
Ejemplo n.º 2
0
//==============================================================================================================================
bool DeferredShader::Initialize()
{
	ConstantBuffer<cbPackBuffer> packCB(m_pD3DSystem);
	packCB.Initialize(PAD16(sizeof(cbPackBuffer)));
	m_pPackCB = packCB.Buffer();
	
	ConstantBuffer<cbMatrixBuffer> matrixCB(m_pD3DSystem);
	matrixCB.Initialize(PAD16(sizeof(cbMatrixBuffer)));
	m_pMatrixCB = matrixCB.Buffer();
	
	ConstantBuffer<cbMatrixBuffer2> matrix2CB(m_pD3DSystem);
	matrix2CB.Initialize(PAD16(sizeof(cbMatrixBuffer2)));
	m_pMatrix2CB = matrix2CB.Buffer();
	
	ClearInputLayout();
	
	SetInputLayoutDesc("DeferredShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_normal_tex, 3);
	
	LoadVertexShader("DeferredShaderVS");
	LoadPixelShader("DeferredShaderPS");
	LoadPixelShader("DeferredShaderWireframePS");
	
	AssignVertexShaderLayout("DeferredShader");
	
	return true;
}
//==============================================================================================================================
bool TerrainTessellationQuadShadowShader::Initialize()
{
	ConstantBuffer<cTessellationBuffer> tessellationCB(m_pD3DSystem);
	tessellationCB.Initialize(PAD16(sizeof(cTessellationBuffer)));
	m_pTessellationCB = tessellationCB.Buffer();
	
	ConstantBuffer<cDomainConstBuffer> domainCB(m_pD3DSystem);
	domainCB.Initialize(PAD16(sizeof(cDomainConstBuffer)));
	m_pDomainCB = domainCB.Buffer();

	ConstantBuffer<cMatrixBuffer> matrixBufferCB(m_pD3DSystem);
	matrixBufferCB.Initialize(PAD16(sizeof(cMatrixBuffer)));
	m_pMatrixBufferCB = matrixBufferCB.Buffer();
	
	ClearInputLayout();
	SetInputLayoutDesc("TerrainTessellationQuadShadowShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_tex, 2);
	
	LoadVertexShader("TerrainTessellationQuadVS");
	LoadHullShader("TerrainTessellationQuadShadowHS");
	LoadDomainShader("TerrainTessellationQuadDS");
	LoadPixelShader("TerrainTessellationShadowPS");
	
	AssignVertexShaderLayout("TerrainTessellationQuadShadowShader");
	
	return true;
}
Ejemplo n.º 4
0
//==================================================================================================================================
HDR::HDR(D3D* d3d)
:   PostProcess(d3d)
//,	hdrTarget(0)
,	luminance(0)
,	bright(0)
,	summed(0)
,	blurredH(0)
,	blurredHV(0)
,	m_pBloomConstants(0)
,	m_pCSConstants(0)
{
	mType = EPostProcessTypes::Type::eHDR;
	
	ConstantBuffer<cbBloomConstants> bloomCB(mD3DSystem);
	bloomCB.Initialize(PAD16(sizeof(cbBloomConstants)));
	m_pBloomConstants = bloomCB.Buffer();
	
	ConstantBuffer<cbConstants> constCB(mD3DSystem);
	constCB.Initialize(PAD16(sizeof(cbConstants)));
	m_pCSConstants = constCB.Buffer();
	
	int backbufferWidth = mD3DSystem->GetEngineOptions()->m_screenWidth;
	int backbufferHeight = mD3DSystem->GetEngineOptions()->m_screenHeight;
	
	// Float format will change the bandwidth needed. 
	//#define FLOAT_FORMAT DXGI_FORMAT_R32G32B32A32_FLOAT
	//#define FLOAT_FORMAT DXGI_FORMAT_R16G16B16A16_FLOAT
	#define FLOAT_FORMAT DXGI_FORMAT_R11G11B10_FLOAT
	
	UINT bindflags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
	
	//target = PostProcessManager::CreateRenderTarget(backbufferWidth, backbufferHeight, FLOAT_FORMAT, bindflags, 2);
	
	bindflags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
	
	luminance = PostProcessManager::CreateRenderTarget(backbufferWidth / 2, backbufferHeight / 2, DXGI_FORMAT_R32_FLOAT, bindflags, 1);
	summed = PostProcessManager::CreateRenderTarget(backbufferWidth / 2, backbufferHeight / 2, FLOAT_FORMAT, bindflags, BLUR_LEVELS);
	blurredH = PostProcessManager::CreateRenderTarget(backbufferWidth / 2, backbufferHeight / 2, FLOAT_FORMAT, bindflags, BLUR_LEVELS);
	blurredHV = PostProcessManager::CreateRenderTarget(backbufferWidth / 2, backbufferHeight / 2, FLOAT_FORMAT, bindflags, BLUR_LEVELS);
	bright = PostProcessManager::CreateRenderTarget(backbufferWidth / 2, backbufferHeight / 2, FLOAT_FORMAT, bindflags, BLUR_LEVELS);
	
	fMiddleGreyValue = 5.0f;
	fBloomThreshold = 1.8f;
	fBloomMultiplier = 2.0f;
	
	PostProcessManager::mShader->LoadComputeShader("GetAvgLum");
	PostProcessManager::mShader->LoadComputeShader("BlurHorizontal");
	PostProcessManager::mShader->LoadComputeShader("BlurVertical");
	PostProcessManager::mShader->LoadComputeShader("Add");
	PostProcessManager::mShader->LoadComputeShader("ComputeLuminanceAndBright");
	PostProcessManager::mShader->LoadPixelShader("ToneMapWithBloom");
}
//==============================================================================================================================
bool AmbientLightDeferredShader::Initialize()
{
	ConstantBuffer<cbDeferredLightBuffer> lightCB(m_pD3DSystem);
	lightCB.Initialize(PAD16(sizeof(cbDeferredLightBuffer)));
	m_pLightCB = lightCB.Buffer();
	
	LoadVertexShader("AmbientLightDeferredVS");
	LoadPixelShader("AmbientLightDeferredPS");
	LoadPixelShader("AmbientLightDeferredWireframePS");
	
	return true;
}
Ejemplo n.º 6
0
//==============================================================================================================================
bool OBJMeshShader::Initialize()
{
	ConstantBuffer<cbOBJShadingConst> objShadingCB(m_pD3DSystem);
	objShadingCB.Initialize(PAD16(sizeof(cbOBJShadingConst)));
	m_pOBJShadingCB = objShadingCB.Buffer();
	
	ConstantBuffer<cbMatrixBuffer> matrixBufferCB(m_pD3DSystem);
	matrixBufferCB.Initialize(PAD16(sizeof(cbMatrixBuffer)));
	m_pMatrixBufferCB = matrixBufferCB.Buffer();
	
	ClearInputLayout();
	SetInputLayoutDesc("OBJMeshShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_normal_tex, 3);
	
	LoadVertexShader("OBJMeshVS");
	LoadPixelShader("OBJMeshPS");
	LoadPixelShader("OBJMeshWireframePS");
	
	AssignVertexShaderLayout("OBJMeshShader");
	
	return true;
}
//==============================================================================================================================
bool DebugGBufferDeferredShader::Initialize()
{
	ConstantBuffer<cbInvMatrixBuffer> matrixCB(m_pD3DSystem);
	matrixCB.Initialize(PAD16(sizeof(cbInvMatrixBuffer)));
	m_pMatrixCB = matrixCB.Buffer();

	LoadVertexShader("DebugGBufferDeferredVS");
	LoadPixelShader("DebugGBufferDeferredPS");
	LoadPixelShader("DebugGBufferDepthDeferredPS");
	LoadPixelShader("DebugGBufferDeferredWireframePS");
	
	return true;
}
//==============================================================================================================================
bool TriMaterialTessellationShader::Initialize()
{
	ConstantBuffer<cTessellationBuffer> tessellationCB(m_pD3DSystem);
	tessellationCB.Initialize(PAD16(sizeof(cTessellationBuffer)));
	m_pTessellationCB = tessellationCB.Buffer();
	
	ConstantBuffer<Const_Per_Frame> perFrameCB(m_pD3DSystem);
	perFrameCB.Initialize(PAD16(sizeof(Const_Per_Frame)));
	m_pPerFrameCB = perFrameCB.Buffer();
	
	ConstantBuffer<Const_Per_Object> perObjectCB(m_pD3DSystem);
	perObjectCB.Initialize(PAD16(sizeof(Const_Per_Object)));
	m_pPerObjectCB = perObjectCB.Buffer();
	
	ConstantBuffer<ZShadeSandboxLighting::cbLightBuffer> lightCB(m_pD3DSystem);
	lightCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbLightBuffer)));
	m_pLightCB = lightCB.Buffer();
	
	ConstantBuffer<ZShadeSandboxLighting::cbSunLightBuffer> sunCB(m_pD3DSystem);
	sunCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbSunLightBuffer)));
	m_pSunCB = sunCB.Buffer();
	
	ClearInputLayout();
	
	SetInputLayoutDesc("TriMaterialTessellationShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_normal_tex, 3);
	
	LoadVertexShader("MaterialTessellationShaderVS");
	LoadHullShader("TriMaterialTessellationShaderHS");
	LoadDomainShader("TriMaterialTessellationShaderDS");
	LoadPixelShader("MaterialTessellationShaderPS");
	LoadPixelShader("MaterialTessellationShaderWireframePS");
	
	AssignVertexShaderLayout("TriMaterialTessellationShader");
	
	bFlipHorizontally = false;
	bFlipVertically = false;
	
	return true;
}
//==============================================================================================================================
bool ShadowMapBuildShader::Initialize()
{
	ConstantBuffer<cbShadowMapConst> shadowMapCB(m_pD3DSystem);
	shadowMapCB.Initialize(PAD16(sizeof(cbShadowMapConst)));
	m_pShadowMapCB = shadowMapCB.Buffer();
	
	ClearInputLayout();
	//SetInputLayoutDesc("ShadowMapBuildShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos, 1);
	SetInputLayoutDesc("ShadowMapBuildShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_normal_tex, 3);
	
	LoadVertexShader("ShadowMapBuilderVS");
	LoadPixelShader("ShadowMapBuilderPS");
	
	AssignVertexShaderLayout("ShadowMapBuildShader");
	
	return true;
}
//==============================================================================================================================
bool TerrainTessellationQuadSSAOShader::Initialize()
{
	ConstantBuffer<cTessellationBuffer> tessellationCB(m_pD3DSystem);
	tessellationCB.Initialize(PAD16(sizeof(cTessellationBuffer)));
	m_pTessellationCB = tessellationCB.Buffer();

	ConstantBuffer<cDomainConstBuffer> domainCB(m_pD3DSystem);
	domainCB.Initialize(PAD16(sizeof(cDomainConstBuffer)));
	m_pDomainCB = domainCB.Buffer();

	ConstantBuffer<cMatrixBuffer> matrixBufferCB(m_pD3DSystem);
	matrixBufferCB.Initialize(PAD16(sizeof(cMatrixBuffer)));
	m_pMatrixBufferCB = matrixBufferCB.Buffer();

	ConstantBuffer<cShadingConstBuffer> shadingCB(m_pD3DSystem);
	shadingCB.Initialize(PAD16(sizeof(cShadingConstBuffer)));
	m_pShadingCB = shadingCB.Buffer();

	ConstantBuffer<ZShadeSandboxLighting::cbLightBuffer> lightCB(m_pD3DSystem);
	lightCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbLightBuffer)));
	m_pLightCB = lightCB.Buffer();

	ConstantBuffer<ZShadeSandboxLighting::cbSunLightBuffer> sunCB(m_pD3DSystem);
	sunCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbSunLightBuffer)));
	m_pSunCB = sunCB.Buffer();

	ClearInputLayout();
	SetInputLayoutDesc("TerrainTessellationQuadSSAOShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_tex, 2);

	LoadVertexShader("TerrainTessellationQuadVS");
	LoadHullShader("TerrainTessellationQuadShadowHS");
	LoadDomainShader("TerrainTessellationQuadDS");
	LoadPixelShader("TerrainTessellationNormalDepthPS");

	AssignVertexShaderLayout("TerrainTessellationQuadSSAOShader");

	return true;
}
//==============================================================================================================================
bool MaterialTessellationShader::Initialize()
{
	ConstantBuffer<ZShadeSandboxLighting::cbMaterialTessellationBuffer> tessellationCB(m_pD3DSystem);
	tessellationCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbMaterialTessellationBuffer)));
	m_pTessellationCB = tessellationCB.Buffer();
	
	ConstantBuffer<ZShadeSandboxLighting::cbMaterialDomainBuffer> domainCB(m_pD3DSystem);
	domainCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbMaterialDomainBuffer)));
	m_pDomainCB = domainCB.Buffer();
	
	ConstantBuffer<ZShadeSandboxLighting::cbMaterialShadingBuffer> shadingCB(m_pD3DSystem);
	shadingCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbMaterialShadingBuffer)));
	m_pShadingCB = shadingCB.Buffer();
	
	ConstantBuffer<ZShadeSandboxLighting::cbLightBuffer> lightCB(m_pD3DSystem);
	lightCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbLightBuffer)));
	m_pLightCB = lightCB.Buffer();
	
	ConstantBuffer<ZShadeSandboxLighting::cbSunLightBuffer> sunCB(m_pD3DSystem);
	sunCB.Initialize(PAD16(sizeof(ZShadeSandboxLighting::cbSunLightBuffer)));
	m_pSunCB = sunCB.Buffer();
	
	ClearInputLayout();
	SetInputLayoutDesc("MaterialTessellationShader", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_normal_tex, 3);
	switch (mType)
	{
		case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad:
		{
			LoadVertexShader("QuadMaterialTessellationVS");
			LoadHullShader("QuadMaterialTessellationHS");
			LoadDomainShader("QuadMaterialTessellationDS");
			LoadPixelShader("QuadMaterialTessellationPS");
			LoadPixelShader("QuadMaterialTessellationWireframePS");
		}
		break;
		case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri:
		{
			LoadVertexShader("TriMaterialTessellationVS");
			LoadHullShader("TriMaterialTessellationHS");
			LoadDomainShader("TriMaterialTessellationDS");
			LoadPixelShader("TriMaterialTessellationPS");
			LoadPixelShader("TriMaterialTessellationWireframePS");
		}
		break;
	}
	AssignVertexShaderLayout("MaterialTessellationShader");
	
	// Instancing
	SetInputLayoutDesc("MaterialTessellationShaderInstance", ZShadeSandboxMesh::VertexLayout::mesh_layout_pos_normal_tex_instance, 4);
	switch (mType)
	{
		case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad:
		{
			LoadVertexShader("QuadMaterialTessellationInstanceVS");
		}
		break;
		case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri:
		{
			LoadVertexShader("TriMaterialTessellationInstanceVS");
		}
		break;
	}
	AssignVertexShaderLayout("MaterialTessellationShaderInstance");
	
	return true;
}
Ejemplo n.º 12
0
OceanSimulator::OceanSimulator(OceanParameter& params, ID3D11Device* pd3dDevice)
{
    HRESULT hr;

	// If the device becomes invalid at some point, delete current instance and generate a new one.
	m_pd3dDevice = pd3dDevice;
	m_pd3dDevice->GetImmediateContext(&m_pd3dImmediateContext);

	// Height map H(0)
	int height_map_size = (params.dmap_dim + 4) * (params.dmap_dim + 1);
	D3DXVECTOR2* h0_data = new D3DXVECTOR2[height_map_size * sizeof(D3DXVECTOR2)];
	float* omega_data = new float[height_map_size * sizeof(float)];
	initHeightMap(params, h0_data, omega_data);

	m_param = params;
	int hmap_dim = params.dmap_dim;
	int input_full_size = (hmap_dim + 4) * (hmap_dim + 1);
	// This value should be (hmap_dim / 2 + 1) * hmap_dim, but we use full sized buffer here for simplicity.
	int input_half_size = hmap_dim * hmap_dim;
	int output_size = hmap_dim * hmap_dim;

	// For filling the buffer with zeroes.
	char* zero_data = new char[3 * output_size * sizeof(float) * 2];
	memset(zero_data, 0, 3 * output_size * sizeof(float) * 2);

	// RW buffer allocations
	// H0
	UINT float2_stride = 2 * sizeof(float);
	createBufferAndUAV(m_pd3dDevice, h0_data, input_full_size * float2_stride, float2_stride, &m_pBuffer_Float2_H0, &m_pUAV_H0, &m_pSRV_H0);

	// Notice: The following 3 buffers should be half sized buffer because of conjugate symmetric input. But
	// we use full sized buffers due to the CS4.0 restriction.

	// Put H(t), Dx(t) and Dy(t) into one buffer because CS4.0 allows only 1 UAV at a time
	createBufferAndUAV(m_pd3dDevice, zero_data, 3 * input_half_size * float2_stride, float2_stride, &m_pBuffer_Float2_Ht, &m_pUAV_Ht, &m_pSRV_Ht);

	// omega
	createBufferAndUAV(m_pd3dDevice, omega_data, input_full_size * sizeof(float), sizeof(float), &m_pBuffer_Float_Omega, &m_pUAV_Omega, &m_pSRV_Omega);

	// Notice: The following 3 should be real number data. But here we use the complex numbers and C2C FFT
	// due to the CS4.0 restriction.
	// Put Dz, Dx and Dy into one buffer because CS4.0 allows only 1 UAV at a time
	createBufferAndUAV(m_pd3dDevice, zero_data, 3 * output_size * float2_stride, float2_stride, &m_pBuffer_Float_Dxyz, &m_pUAV_Dxyz, &m_pSRV_Dxyz);

	SAFE_DELETE_ARRAY(zero_data);
	SAFE_DELETE_ARRAY(h0_data);
	SAFE_DELETE_ARRAY(omega_data);

	// D3D11 Textures
	createTextureAndViews(m_pd3dDevice, hmap_dim, hmap_dim, DXGI_FORMAT_R32G32B32A32_FLOAT, &m_pDisplacementMap, &m_pDisplacementSRV, &m_pDisplacementRTV);
	createTextureAndViews(m_pd3dDevice, hmap_dim, hmap_dim, DXGI_FORMAT_R16G16B16A16_FLOAT, &m_pGradientMap, &m_pGradientSRV, &m_pGradientRTV);

	// Samplers
	D3D11_SAMPLER_DESC sam_desc;
	sam_desc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
	sam_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	sam_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	sam_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	sam_desc.MipLODBias = 0; 
	sam_desc.MaxAnisotropy = 1; 
	sam_desc.ComparisonFunc = D3D11_COMPARISON_NEVER; 
	sam_desc.BorderColor[0] = 1.0f;
	sam_desc.BorderColor[1] = 1.0f;
	sam_desc.BorderColor[2] = 1.0f;
	sam_desc.BorderColor[3] = 1.0f;
	sam_desc.MinLOD = -FLT_MAX;
	sam_desc.MaxLOD = FLT_MAX;
	m_pd3dDevice->CreateSamplerState(&sam_desc, &m_pPointSamplerState);

	// Compute shaders
    ID3DBlob* pBlobUpdateSpectrumCS = NULL;

    FUtil::CompileShaderFromFile("FFT//ocean_simulator_cs.hlsl", "UpdateSpectrumCS", "cs_4_0", &pBlobUpdateSpectrumCS);

    m_pd3dDevice->CreateComputeShader(pBlobUpdateSpectrumCS->GetBufferPointer(), pBlobUpdateSpectrumCS->GetBufferSize(), NULL, &m_pUpdateSpectrumCS);
    
    SAFE_RELEASE(pBlobUpdateSpectrumCS);

	// Vertex & pixel shaders
    ID3DBlob* pBlobQuadVS = NULL;
    ID3DBlob* pBlobUpdateDisplacementPS = NULL;
    ID3DBlob* pBlobGenGradientFoldingPS = NULL;

    FUtil::CompileShaderFromFile("FFT//ocean_simulator_vs_ps.hlsl", "QuadVS", "vs_4_0", &pBlobQuadVS);
    FUtil::CompileShaderFromFile("FFT//ocean_simulator_vs_ps.hlsl", "UpdateDisplacementPS", "ps_4_0", &pBlobUpdateDisplacementPS);
    FUtil::CompileShaderFromFile("FFT//ocean_simulator_vs_ps.hlsl", "GenGradientFoldingPS", "ps_4_0", &pBlobGenGradientFoldingPS);

    m_pd3dDevice->CreateVertexShader(pBlobQuadVS->GetBufferPointer(), pBlobQuadVS->GetBufferSize(), NULL, &m_pQuadVS);
    m_pd3dDevice->CreatePixelShader(pBlobUpdateDisplacementPS->GetBufferPointer(), pBlobUpdateDisplacementPS->GetBufferSize(), NULL, &m_pUpdateDisplacementPS);
    m_pd3dDevice->CreatePixelShader(pBlobGenGradientFoldingPS->GetBufferPointer(), pBlobGenGradientFoldingPS->GetBufferSize(), NULL, &m_pGenGradientFoldingPS);
	SAFE_RELEASE(pBlobUpdateDisplacementPS);
	SAFE_RELEASE(pBlobGenGradientFoldingPS);

	// Input layout
	D3D11_INPUT_ELEMENT_DESC quad_layout_desc[] =
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
	};
	m_pd3dDevice->CreateInputLayout(quad_layout_desc, 1, pBlobQuadVS->GetBufferPointer(), pBlobQuadVS->GetBufferSize(), &m_pQuadLayout);

	SAFE_RELEASE(pBlobQuadVS);

	// Quad vertex buffer
	D3D11_BUFFER_DESC vb_desc;
	vb_desc.ByteWidth = 4 * sizeof(D3DXVECTOR4);
	vb_desc.Usage = D3D11_USAGE_IMMUTABLE;
	vb_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vb_desc.CPUAccessFlags = 0;
	vb_desc.MiscFlags = 0;

	float quad_verts[] =
	{
		-1, -1, 0, 1,
		-1,  1, 0, 1,
		 1, -1, 0, 1,
		 1,  1, 0, 1,
	};
	D3D11_SUBRESOURCE_DATA init_data;
	init_data.pSysMem = &quad_verts[0];
	init_data.SysMemPitch = 0;
	init_data.SysMemSlicePitch = 0;
	
	m_pd3dDevice->CreateBuffer(&vb_desc, &init_data, &m_pQuadVB);


	// Constant buffers
	UINT actual_dim = m_param.dmap_dim;
	UINT input_width = actual_dim + 4;
	// We use full sized data here. The value "output_width" should be actual_dim/2+1 though.
	UINT output_width = actual_dim;
	UINT output_height = actual_dim;
	UINT dtx_offset = actual_dim * actual_dim;
	UINT dty_offset = actual_dim * actual_dim * 2;
	UINT immutable_consts[] = {actual_dim, input_width, output_width, output_height, dtx_offset, dty_offset};
	D3D11_SUBRESOURCE_DATA init_cb0 = {&immutable_consts[0], 0, 0};

	D3D11_BUFFER_DESC cb_desc;
	cb_desc.Usage = D3D11_USAGE_IMMUTABLE;
	cb_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	cb_desc.CPUAccessFlags = 0;
	cb_desc.MiscFlags = 0;    
	cb_desc.ByteWidth = PAD16(sizeof(immutable_consts));
	m_pd3dDevice->CreateBuffer(&cb_desc, &init_cb0, &m_pImmutableCB);


	ID3D11Buffer* cbs[1] = {m_pImmutableCB};
	m_pd3dImmediateContext->CSSetConstantBuffers(0, 1, cbs);
	m_pd3dImmediateContext->PSSetConstantBuffers(0, 1, cbs);

	cb_desc.Usage = D3D11_USAGE_DEFAULT;
	cb_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	cb_desc.CPUAccessFlags = 0;
	cb_desc.MiscFlags = 0;    
	cb_desc.ByteWidth = PAD16(sizeof(float) * 3);
	hr = m_pd3dDevice->CreateBuffer(&cb_desc, NULL, &m_pPerFrameCB);

	// FFT
	fft512x512_create_plan(&m_fft_plan, m_pd3dDevice, 3);

#ifdef CS_DEBUG_BUFFER
	D3D11_BUFFER_DESC buf_desc;
	buf_desc.ByteWidth = 3 * input_half_size * float2_stride;
    buf_desc.Usage = D3D11_USAGE_STAGING;
    buf_desc.BindFlags = 0;
    buf_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    buf_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
    buf_desc.StructureByteStride = float2_stride;

	m_pd3dDevice->CreateBuffer(&buf_desc, NULL, &m_pDebugBuffer);
	assert(m_pDebugBuffer);
#endif
}
Ejemplo n.º 13
0
/*---------------------------------------------------------------------*/
void
fill_entry_descriptors( char *image_file, char *img, int img_size,
                        entry_t ** res_entries, int *res_nb_entries )
{
  int elf_offset;
  int max_size = 0;
  int max_name = 0;
  int i;

  // Check file integrity
  if ( ( img_size < ( 16 * 3 ) ) ||
       img[0] != 'R' ||
       img[1] != 'E' || img[2] != 'S' || img[3] != 'E' || img[4] != 'T' )
    fatal( "%s is not a valid Playstation 2 ROM image\n", image_file );

  // Get number of ROMDIR entries
  romdir_t *romdir = ( romdir_t * ) img;
  int offset = 0;
  entry_t *entries;
  int nb_entries = 0;
  while ( romdir[nb_entries].name[0] ) {
    nb_entries++;
    offset += 16;
    if ( offset > img_size )
      fatal( "%s is not a valid Playstation 2 ROM image: "
             "ROMDIR section ended prematuraly\n", image_file );
  }

  // Alloc the resulting entries
  entries = malloc( sizeof( entry_t ) * nb_entries );

  // fill the resulting entries w.r.t the EXTINFO and ROMDIR sections
  unsigned char *extinfo = img + ( ( nb_entries + 1 ) * sizeof( romdir_t ) );
  for ( i = 0; i < nb_entries; i++ ) {
    //print("%p [%p]\n",extinfo,img);
    if ( extinfo >= ( unsigned char * ) ( img + img_size ) )
      fatal( "%s is not a valid Playstation 2 ROM image: "
             "EXTINFO section ended prematuraly\n", image_file );

    // fill entry infos
    strcpy( entries[i].name, romdir[i].name );
    if ( max_name < strlen( entries[i].name ) )
      max_name = strlen( entries[i].name );

    entries[i].flags = 0;
    int size = romdir[i].extinfo_size;
    while ( size ) {

      if ( extinfo >= ( unsigned char * ) ( img + img_size ) )
        fatal( "%s is not a valid Playstation 2 ROM image: "
               "EXTINFO section ended prematuraly\n", image_file );
      extinfo_t *ei = ( extinfo_t * ) extinfo;

      switch ( ei->id ) {
      case EXTINFO_ID_DATE:
        entries[i].date = *( unsigned int * ) ( ei + 1 );
        entries[i].flags |= ENTRY_FLAG_DATE;
        break;
      case EXTINFO_ID_VERSION:
        entries[i].version = ei->value;
        entries[i].flags |= ENTRY_FLAG_VERSION;
        break;
      case EXTINFO_ID_DESCR:
        strcpy( entries[i].descr, ( char * ) ( ei + 1 ) );
        entries[i].flags |= ENTRY_FLAG_DESCR;
        break;
      case EXTINFO_ID_NULL:
        strcpy( entries[i].descr, ( char * ) ( ei + 1 ) );
        entries[i].flags |= ENTRY_FLAG_NULL;
        break;
      default:
        fatal( "%s is not a valid Playstation 2 archive: "
               "invalid EXTINFO id for IRX %s\n",
               image_file, entries[i].name );
      }

      size -= ( sizeof( extinfo_t ) + ei->size );
      extinfo += ( sizeof( extinfo_t ) + ei->size );
    }
  }

  // The IRX files are located right after sizeof(ROMDIR) + sizeof(EXTINFO)
  elf_offset = PAD16( romdir[1].size + romdir[2].size );
  entries[0].irx_size = romdir[0].size;
  entries[1].irx_size = romdir[1].size;
  entries[2].irx_size = romdir[2].size;
  for ( i = 3; i < nb_entries; i++ ) {
    entries[i].irx_binary = ( char * ) ( elf_offset + ( int ) img );
    entries[i].irx_size = romdir[i].size;
    elf_offset += PAD16( romdir[i].size );
    if ( max_size < romdir[i].size )
      max_size = romdir[i].size;
  }
  verbose_set_length_of_size_column( digits_in_number( max_size ) );
  verbose_set_length_of_name_column( max_name );
  *res_entries = entries;
  *res_nb_entries = nb_entries;
}
Ejemplo n.º 14
0
/*---------------------------------------------------------------------*/
void
delete_entries_from_image( char *image_name, char *irx_args[], int num_irx )
{
  // Read the entire file
  char *img;
  int size, i, j;
  read_file( image_name, &img, &size );

  // Fill our entry descriptors
  entry_t *entry;
  int nb_entries;
  fill_entry_descriptors( image_name, img, size, &entry, &nb_entries );

  romdir_t *romdir_entry = ( romdir_t * ) img;

  int romdir_original = 0;
  int romdir_updated = 0;
  int extinfo_original = 0;
  int extinfo_updated = 0;
  int irx_original = 0;
  int irx_updated = 0;

  int new_romdir_size = 0;
  int new_extinfo_size = 0;
  int new_irx_size = 0;

  char *romdir_section = img;
  char *extinfo_section = romdir_section + romdir_entry[1].size;
  char *irx_section = extinfo_section + PAD16( romdir_entry[2].size );

  if ( verbose ) {
    int max_name = 0;
    // find out the size of the name column
    for ( j = 0; j < num_irx; j++ ) {
      for ( i = 0; i < nb_entries; i++ ) {
        if ( strcmp( entry[i].name, irx_args[j] ) == 0 ) {
          if ( max_name < strlen( entry[i].name ) )
            max_name = strlen( entry[i].name );
          break;
        }
      }
    }
    verbose_set_length_of_name_column( max_name );
  }
  // mark irx entries to delete
  for ( j = 0; j < num_irx; j++ ) {
    for ( i = 0; i < nb_entries; i++ ) {
      if ( strcmp( entry[i].name, irx_args[j] ) == 0 ) {
        if ( verbose )
          verbose_print_delete_message( entry[i].name, entry[i].irx_size );
        entry[i].name[0] = -1;
        break;
      }
    }
    if ( i == nb_entries )
      fatal( "Entry %s not found in ROM image %s", irx_args[j], image_name );
  }

  // Update all section at once
  for ( i = 0; i < nb_entries; i++ ) {
    // pad the previous section with zeros, if any
    memset( irx_section + irx_updated, 0,
            PAD16( irx_updated ) - irx_updated );
    irx_original = PAD16( irx_original );
    irx_updated = PAD16( irx_updated );
    new_irx_size = PAD16( new_irx_size );
    if ( entry[i].name[0] == -1 ) {
      // this entry must be deleted
      if ( i > 2 )
        irx_original += romdir_entry[i].size;
      extinfo_original += romdir_entry[i].extinfo_size;
      romdir_original += sizeof( romdir_t );
    } else {
      // this entry is kept back
      if ( i > 2 ) {
        memmove( irx_section + irx_updated, irx_section + irx_original,
                 romdir_entry[i].size );
        irx_original += romdir_entry[i].size;
        irx_updated += romdir_entry[i].size;
        new_irx_size += romdir_entry[i].size;
      }
      memmove( extinfo_section + extinfo_updated,
               extinfo_section + extinfo_original,
               romdir_entry[i].extinfo_size );
      extinfo_original += romdir_entry[i].extinfo_size;
      extinfo_updated += romdir_entry[i].extinfo_size;
      new_extinfo_size += romdir_entry[i].extinfo_size;

      memmove( romdir_section + romdir_updated,
               romdir_section + romdir_original, sizeof( romdir_t ) );
      romdir_original += sizeof( romdir_t );
      romdir_updated += sizeof( romdir_t );
      new_romdir_size += sizeof( romdir_t );
    }
  }
  // copy the last romdir entry (dummy)
  memset( romdir_section + romdir_updated, 0, sizeof( romdir_t ) );
  romdir_original += sizeof( romdir_t );
  romdir_updated += sizeof( romdir_t );
  new_romdir_size += sizeof( romdir_t );

  // Update the overall size of the previous sections
  romdir_entry[1].size = new_romdir_size;
  romdir_entry[2].size = new_extinfo_size;

  // pad the extinfo section
  memset( extinfo_section + new_extinfo_size, 0,
          PAD16( new_extinfo_size ) - new_extinfo_size );
  new_extinfo_size = PAD16( new_extinfo_size );


  // decal the EXTINFO and IRX sections to their new position
  memmove( img + new_romdir_size, extinfo_section, new_extinfo_size );
  memmove( img + new_romdir_size + new_extinfo_size, irx_section,
           new_irx_size );

  // done ! save the result to disk
  write_file( image_name, img,
              new_romdir_size + new_extinfo_size + new_irx_size );

}