Exemplo n.º 1
0
//==============================================================================
void CountersManager::resolveFrame()
{
	// Write new line and frame no
	m_perframeFile.writeText("\n%llu", getGlobTimestamp());

	U i = 0;
	for(const CounterInfo& inf : cinfo)
	{
		if(inf.m_flags & CF_PER_FRAME)
		{
			if(inf.m_flags & CF_U64)
			{
				m_perframeFile.writeText(", %llu", m_perframeValues[i]);
			}
			else if(inf.m_flags & CF_F64)
			{
				m_perframeFile.writeText(", %f", *((F64*)&m_perframeValues[i]));
			}
			else
			{
				ANKI_ASSERT(0);
			}

			m_perframeValues[i] = 0;
		}

		i++;
	}
}
Exemplo n.º 2
0
//==============================================================================
void CountersManager::flush()
{
	// Resolve per run counters
	U i = 0;
	U j = 0;
	for(const CounterInfo& inf : cinfo)
	{
		if(inf.m_flags & CF_PER_RUN)
		{
			if(j != 0)
			{
				m_perrunFile.writeText(", ");
			}

			if(inf.m_flags & CF_U64)
			{
				m_perrunFile.writeText("%" MAX_NAME "llu", m_perrunValues[i]);
			}
			else if(inf.m_flags & CF_F64)
			{
				if(inf.m_flags & CF_FPS)
				{
					m_perrunFile.writeText("%" MAX_NAME "f", 
						(F64)getGlobTimestamp() / *((F64*)&m_perrunValues[i]));
				}
				else
				{
					m_perrunFile.writeText("%" MAX_NAME "f", 
						*((F64*)&m_perrunValues[i]));
				}
			}
			else
			{
				ANKI_ASSERT(0);
			}

			m_perrunValues[i] = 0;
			++j;
		}

		++i;
	}
	m_perrunFile.writeText("\n");

	// Close and flush files
	m_perframeFile.close();
	m_perrunFile.close();
}
Exemplo n.º 3
0
//==============================================================================
void Renderer::render(SceneGraph& scene, 
	Array<GlCommandBufferHandle, JOB_CHAINS_COUNT>& jobs)
{
	m_scene = &scene;
	Camera& cam = m_scene->getActiveCamera();

	// Calc a few vars
	//
	Timestamp camUpdateTimestamp = cam.FrustumComponent::getTimestamp();
	if(m_projectionParamsUpdateTimestamp 
			< m_scene->getActiveCameraChangeTimestamp()
		|| m_projectionParamsUpdateTimestamp < camUpdateTimestamp
		|| m_projectionParamsUpdateTimestamp == 1)
	{
		ANKI_ASSERT(cam.getCameraType() == Camera::Type::PERSPECTIVE);
		computeProjectionParams(cam.getProjectionMatrix());
		m_projectionParamsUpdateTimestamp = getGlobTimestamp();
	}

	ANKI_COUNTER_START_TIMER(RENDERER_MS_TIME);
	m_ms.run(jobs[0]);
	ANKI_ASSERT(jobs[0].getReferenceCount() == 1);
	jobs[0].flush();
	ANKI_COUNTER_STOP_TIMER_INC(RENDERER_MS_TIME);

	m_tiler.runMinMax(m_ms._getDepthRt());

	ANKI_COUNTER_START_TIMER(RENDERER_IS_TIME);
	m_is.run(jobs[1]);
	ANKI_COUNTER_STOP_TIMER_INC(RENDERER_IS_TIME);

	m_bs.run(jobs[1]);

	ANKI_COUNTER_START_TIMER(RENDERER_PPS_TIME);
	if(m_pps.getEnabled())
	{
		m_pps.run(jobs[1]);
	}
	ANKI_COUNTER_STOP_TIMER_INC(RENDERER_PPS_TIME);

	if(m_dbg.getEnabled())
	{
		m_dbg.run(jobs[1]);
	}

	++m_framesNum;
}
Exemplo n.º 4
0
//==============================================================================
void MoveComponent::updateWorldTransform()
{
	m_prevWTrf = m_wtrf;
	const Bool dirty = bitsEnabled(MF_MARKED_FOR_UPDATE);

	// If dirty then update world transform
	if(dirty)
	{
		const MoveComponent* parent = getParent();

		if(parent)
		{
			if(bitsEnabled(MF_IGNORE_LOCAL_TRANSFORM))
			{
				m_wtrf = parent->getWorldTransform();
			}
			else
			{
				m_wtrf = 
					parent->getWorldTransform().combineTransformations(m_ltrf);
			}
		}
		else
		{
			m_wtrf = m_ltrf;
		}

		m_node->componentUpdated(*this, ASYNC_UPDATE);
		timestamp = getGlobTimestamp();

		// Now it's a good time to cleanse parent
		disableBits(MF_MARKED_FOR_UPDATE);
	}

	// Update the children
	visitChildren([&](MoveComponent& mov)
	{
		// If parent is dirty then make children dirty as well
		if(dirty)
		{
			mov.markForUpdate();
		}

		mov.updateWorldTransform();
	});
}
Exemplo n.º 5
0
//==============================================================================
void Hdr::run(GlCommandBufferHandle& jobs)
{
	ANKI_ASSERT(m_enabled);

	// For the passes it should be NEAREST
	//vblurFai.setFiltering(Texture::TFrustumType::NEAREST);

	// pass 0
	m_vblurFb.bind(jobs, true);
	jobs.setViewport(0, 0, m_width, m_height);
	m_tonePpline.bind(jobs);

	if(m_parameterUpdateTimestamp > m_commonUboUpdateTimestamp)
	{
		updateDefaultBlock(jobs);
		m_commonUboUpdateTimestamp = getGlobTimestamp();
	}

	m_r->getIs()._getRt().bind(jobs, 0);
	m_commonBuff.bindShaderBuffer(jobs, 0);

	m_r->drawQuad(jobs);

	// Blurring passes
	for(U32 i = 0; i < m_blurringIterationsCount; i++)
	{
		if(i == 0)
		{
			jobs.bindTextures(0, {m_hblurRt, m_vblurRt});
		}

		// hpass
		m_hblurFb.bind(jobs, true);
		m_hblurPpline.bind(jobs);		
		m_r->drawQuad(jobs);

		// vpass
		m_vblurFb.bind(jobs, true);
		m_vblurPpline.bind(jobs);
		m_r->drawQuad(jobs);
	}

	// For the next stage it should be LINEAR though
	//vblurFai.setFiltering(Texture::TFrustumType::LINEAR);
}
Exemplo n.º 6
0
//==============================================================================
void Hdr::initInternal(const ConfigSet& initializer)
{
	m_enabled = initializer.get("pps.hdr.enabled");

	if(!m_enabled)
	{
		return;
	}

	const F32 renderingQuality = initializer.get("pps.hdr.renderingQuality");

	m_width = renderingQuality * (F32)m_r->getWidth();
	alignRoundDown(16, m_width);
	m_height = renderingQuality * (F32)m_r->getHeight();
	alignRoundDown(16, m_height);

	m_exposure = initializer.get("pps.hdr.exposure");
	m_blurringDist = initializer.get("pps.hdr.blurringDist");
	m_blurringIterationsCount = 
		initializer.get("pps.hdr.blurringIterationsCount");

	initFb(m_hblurFb, m_hblurRt);
	initFb(m_vblurFb, m_vblurRt);

	// init shaders
	GlDevice& gl = getGlDevice();
	GlCommandBufferHandle jobs(&gl);

	m_commonBuff = GlBufferHandle(jobs, GL_SHADER_STORAGE_BUFFER, 
		sizeof(Vec4), GL_DYNAMIC_STORAGE_BIT);

	updateDefaultBlock(jobs);

	jobs.flush();

	m_toneFrag.load("shaders/PpsHdr.frag.glsl", &getResourceManager());

	m_tonePpline = 
		m_r->createDrawQuadProgramPipeline(m_toneFrag->getGlProgram());

	const char* SHADER_FILENAME = 
		"shaders/VariableSamplingBlurGeneric.frag.glsl";

	String pps(getAllocator());
	pps.sprintf("#define HPASS\n"
		"#define COL_RGB\n"
		"#define BLURRING_DIST float(%f)\n"
		"#define IMG_DIMENSION %u\n"
		"#define SAMPLES %u\n",
		m_blurringDist, m_height, 
		static_cast<U>(initializer.get("pps.hdr.samples")));

	m_hblurFrag.load(ProgramResource::createSourceToCache(
		SHADER_FILENAME, pps.toCString(), "r_", 
		getResourceManager()).toCString(),
		&getResourceManager());

	m_hblurPpline = 
		m_r->createDrawQuadProgramPipeline(m_hblurFrag->getGlProgram());

	pps.sprintf("#define VPASS\n"
		"#define COL_RGB\n"
		"#define BLURRING_DIST float(%f)\n"
		"#define IMG_DIMENSION %u\n"
		"#define SAMPLES %u\n",
		m_blurringDist, m_width, 
		static_cast<U>(initializer.get("pps.hdr.samples")));

	m_vblurFrag.load(ProgramResource::createSourceToCache(
		SHADER_FILENAME, pps.toCString(), "r_",
		getResourceManager()).toCString(),
		&getResourceManager());

	m_vblurPpline = 
		m_r->createDrawQuadProgramPipeline(m_vblurFrag->getGlProgram());

	// Set timestamps
	m_parameterUpdateTimestamp = getGlobTimestamp();
	m_commonUboUpdateTimestamp = getGlobTimestamp();
}
Exemplo n.º 7
0
//==============================================================================
void Ssao::run(GlCommandBufferHandle& cmdb)
{
	ANKI_ASSERT(m_enabled);

	const Camera& cam = m_r->getSceneGraph().getActiveCamera();

	cmdb.setViewport(0, 0, m_width, m_height);

	// 1st pass
	//
	m_vblurFb.bind(cmdb, true);
	m_ssaoPpline.bind(cmdb);

	m_uniformsBuff.bindShaderBuffer(cmdb, 0);

	Array<GlTextureHandle, 3> tarr = {{
		m_r->getMs()._getSmallDepthRt(),
		m_r->getMs()._getRt1(),
		m_noiseTex}};
	cmdb.bindTextures(0, tarr.begin(), tarr.getSize());

	// Write common block
	if(m_commonUboUpdateTimestamp 
			< m_r->getProjectionParametersUpdateTimestamp()
		|| m_commonUboUpdateTimestamp < cam.FrustumComponent::getTimestamp()
		|| m_commonUboUpdateTimestamp == 1)
	{
		GlClientBufferHandle tmpBuff;
		tmpBuff.create(cmdb, sizeof(ShaderCommonUniforms),
			nullptr);

		ShaderCommonUniforms& blk = 
			*((ShaderCommonUniforms*)tmpBuff.getBaseAddress());

		blk.m_projectionParams = m_r->getProjectionParameters();

		blk.m_projectionMatrix = cam.getProjectionMatrix().getTransposed();

		m_uniformsBuff.write(cmdb, tmpBuff, 0, 0, tmpBuff.getSize());
		m_commonUboUpdateTimestamp = getGlobTimestamp();
	}

	// Draw
	m_r->drawQuad(cmdb);

	// Blurring passes
	//
	for(U i = 0; i < m_blurringIterationsCount; i++)
	{
		if(i == 0)
		{
			Array<GlTextureHandle, 2> tarr = {{m_hblurRt, m_vblurRt}};
			cmdb.bindTextures(0, tarr.begin(), tarr.getSize());
		}

		// hpass
		m_hblurFb.bind(cmdb, true);
		m_hblurPpline.bind(cmdb);
		m_r->drawQuad(cmdb);

		// vpass
		m_vblurFb.bind(cmdb, true);
		m_vblurPpline.bind(cmdb);
		m_r->drawQuad(cmdb);
	}
}