void VolumetricLighting::InitRenderTarget(SetupContext& context) {
	if (!m_outputTexturesInited) {
		m_outputTexturesInited = true;

		using gxapi::eFormat;

		auto formatSDFCullData = eFormat::R32_UINT;
		auto formatDst = eFormat::R16G16B16A16_FLOAT;

		gxapi::UavTexture2DArray uavDesc;
		uavDesc.activeArraySize = 1;
		uavDesc.firstArrayElement = 0;
		uavDesc.mipLevel = 0;
		uavDesc.planeIndex = 0;

		gxapi::SrvTexture2DArray srvDesc;
		srvDesc.activeArraySize = 1;
		srvDesc.firstArrayElement = 0;
		srvDesc.numMipLevels = -1;
		srvDesc.mipLevelClamping = 0;
		srvDesc.mostDetailedMip = 0;
		srvDesc.planeIndex = 0;

		uint32_t dispatchW, dispatchH;
		SetWorkgroupSize((unsigned)m_depthTexSrv.GetResource().GetWidth(), (unsigned)m_depthTexSrv.GetResource().GetHeight(), 16, 16, dispatchW, dispatchH);

		//TODO 1D tex
		Texture2DDesc desc;
		desc.width = dispatchW * dispatchH;
		desc.height = 1024;
		desc.format = formatSDFCullData;
		TextureUsage uavusage{ true, true, false, true };

		Texture2D sdfCullDataTex = context.CreateTexture2D(desc, uavusage);
		sdfCullDataTex.SetName("SDF culling sdf cull data tex");
		m_sdfCullDataUAV = context.CreateUav(sdfCullDataTex, formatSDFCullData, uavDesc);

		m_sdfCullDataSRV = context.CreateSrv(sdfCullDataTex, formatSDFCullData, srvDesc);


		for (int c = 0; c < 2; ++c) {
			desc.width = m_depthTexSrv.GetResource().GetWidth();
			desc.height = m_depthTexSrv.GetResource().GetHeight();
			desc.format = formatDst;

			Texture2D dstTex = context.CreateTexture2D(desc, uavusage);
			sdfCullDataTex.SetName("SDF culling dst tex");
			m_volDstTexUAV[c] = context.CreateUav(dstTex, formatDst, uavDesc);
			m_volDstTexUAV[c].GetResource().SetName((std::string("SDF culling vol dst UAV") + std::to_string(c)).c_str());
		}

		desc.width = m_depthTexSrv.GetResource().GetWidth();
		desc.height = m_depthTexSrv.GetResource().GetHeight();
		desc.format = formatDst;

		Texture2D dstTex = context.CreateTexture2D(desc, uavusage);
		sdfCullDataTex.SetName("SDF culling dst tex");
		m_dstTexUAV = context.CreateUav(dstTex, formatDst, uavDesc);
	}
}
void DepthReduction::InitRenderTarget(SetupContext& context) {
	using gxapi::eFormat;

	auto formatDepthReductionResult = eFormat::R32G32_FLOAT;

	gxapi::UavTexture2DArray uavDesc;
	uavDesc.activeArraySize = 1;
	uavDesc.firstArrayElement = 0;
	uavDesc.mipLevel = 0;
	uavDesc.planeIndex = 0;

	gxapi::SrvTexture2DArray srvDesc;
	srvDesc.activeArraySize = 1;
	srvDesc.firstArrayElement = 0;
	srvDesc.numMipLevels = -1;
	srvDesc.mipLevelClamping = 0;
	srvDesc.mostDetailedMip = 0;
	srvDesc.planeIndex = 0;

	unsigned dispatchW, dispatchH;
	SetWorkgroupSize((unsigned)std::ceil(m_width * 0.5f), m_height, 16, 16, dispatchW, dispatchH);

	Texture2D tex = context.CreateTexture2D({ dispatchW, dispatchH, formatDepthReductionResult }, { true, true, false, true });
	tex.SetName("Depth reduction intermediate texture");
	m_uav = context.CreateUav(tex, formatDepthReductionResult, uavDesc);
	
	m_srv = context.CreateSrv(tex, formatDepthReductionResult, srvDesc);
	
}