コード例 #1
0
void vkeGameRendererDynamic::update(){
	VulkanAppContext *ctxt = VulkanAppContext::GetInstance();
	VulkanDC *dc = VulkanDC::Get();
	VulkanDC::Device *device = dc->getDefaultDevice();
	VkCommandBuffer cmd = VK_NULL_HANDLE;
	VulkanDC::Device::Queue::CommandBufferID cmdID = INIT_COMMAND_ID + 300;

	static float sTime = 0.0f;

	static uint32_t *uniforms = NULL;

	uint32_t cnt = m_node_data->count();
	uint32_t sz = (sizeof(VkeNodeUniform) * cnt) + (m_instance_count * 64);
	static bool ismapped(false);

	nv_math::mat4f tempMatrix;
	const float r2d = 180 / (3.14159265359);
	static float xTheta(0.0f);


	for (uint32_t i = 0; i < m_instance_count; ++i){
		size_t pointerOffset = (sizeof(VkeNodeUniform) * cnt) + (64 * i);
		nv_math::mat4f *matPtr = (nv_math::mat4f*)(((uint8_t*)m_uniforms_local) + pointerOffset);
		m_flight_paths[i]->update(matPtr, sTime);
	}

	m_node_data->update((VkeNodeUniform*)m_uniforms_local, m_instance_count);

	m_camera->setViewport(0, 0, (float)m_width, (float)m_height);
	m_camera->update();

	generateDrawCommands();

	if (!m_is_first_frame){
			vkResetFences(device->getVKDevice(), 1, &m_update_fence[m_current_buffer_index]);
	
			const VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
			VkSubmitInfo subInfo = { VK_STRUCTURE_TYPE_SUBMIT_INFO };
			subInfo.commandBufferCount = 1;
			subInfo.waitSemaphoreCount = 1;
			subInfo.pWaitSemaphores = &m_present_done[m_current_buffer_index];
			subInfo.pWaitDstStageMask = &waitStages;
			subInfo.signalSemaphoreCount = 1;
			subInfo.pSignalSemaphores = &m_render_done[m_current_buffer_index];
			subInfo.pCommandBuffers = &m_primary_commands[m_current_buffer_index];

			vkQueueSubmit(dc->getDefaultQueue()->getVKQueue(), 1, &subInfo, m_update_fence[m_current_buffer_index]);

			/*
				Synchronise the next buffer. 
				This prevents the buffer from being reset when still in use
				when we have more than 2 frames in flight.
			*/
			uint32_t nextBufferIndex = (m_current_buffer_index + 1) % 2;
			present();
			vkWaitForFences(device->getVKDevice(), 1, &m_update_fence[nextBufferIndex], VK_TRUE, 1000000);

		
	}
	else{
		m_is_first_frame = false;
		
	}

	m_current_buffer_index++;
	m_current_buffer_index %= 2;

	sTime += 0.16;


}
コード例 #2
0
void vkeGameRendererDynamic::update(){
	VulkanAppContext *ctxt = VulkanAppContext::GetInstance();
	VulkanDC *dc = VulkanDC::Get();
	VulkanDC::Device *device = dc->getDefaultDevice();
	VkCommandBuffer cmd = VK_NULL_HANDLE;
	VulkanDC::Device::Queue::CommandBufferID cmdID = INIT_COMMAND_ID + 300;

	static float sTime = 0.0f;

	static uint32_t *uniforms = NULL;

	uint32_t sz = (sizeof(VkeNodeUniform) * 100) + (64 * 64);

	static bool ismapped(false);

	nv_math::mat4f tempMatrix;
	const float r2d = 180 / (3.14159265359);
	static float xTheta(0.0f);


	//if (!ismapped){
	VKA_CHECK_ERROR(vkMapMemory(getDefaultDevice(), m_uniforms_staging, 0, sz, 0, (void **)&uniforms), "Could not map buffer memory.\n");
	//ismapped = true;
	//}


	for (uint32_t i = 0; i < 64; ++i){

		size_t pointerOffset = (sizeof(VkeNodeUniform) * 100) + (64 * i);
		nv_math::mat4f *matPtr = (nv_math::mat4f*)(((uint8_t*)uniforms) + pointerOffset);

		m_flight_paths[i]->update(matPtr, sTime);

	}

	m_node_data->update((VkeNodeUniform*)uniforms);

	m_camera->setViewport(0, 0, (float)m_width, (float)m_height);
	m_camera->update();

	VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
	memRange.memory = m_uniforms_staging;
	memRange.offset = 0;
	memRange.size = sz;

	vkFlushMappedMemoryRanges(device->getVKDevice(), 1, &memRange);




	vkUnmapMemory(device->getVKDevice(), m_uniforms_staging);

	if (!m_is_first_frame){

		VkSubmitInfo subInfo;

		memset(&subInfo, 0, sizeof(subInfo));
		subInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
		subInfo.commandBufferCount = 1;
		subInfo.pCommandBuffers = &m_update_commands[m_current_buffer_index];

		vkQueueSubmit(dc->getDefaultQueue()->getVKQueue(), 1, &subInfo, VK_NULL_HANDLE);
		vkQueueWaitIdle(dc->getDefaultQueue()->getVKQueue());



#if defined(WIN32)
		subInfo.waitSemaphoreCount = 1;
		subInfo.pWaitSemaphores = &m_present_done;
		subInfo.signalSemaphoreCount = 0;
		subInfo.pSignalSemaphores = &m_render_done;
#endif

		subInfo.pCommandBuffers = &m_primary_commands[m_current_buffer_index];

		vkQueueSubmit(dc->getDefaultQueue()->getVKQueue(), 1, &subInfo, VK_NULL_HANDLE);
	}
	else{
		m_is_first_frame = false;
	}
	present();

	m_current_buffer_index++;
	m_current_buffer_index %= 2;

	sTime += 0.16;

	generateDrawCommands();




}