Пример #1
0
void Symmetry::draw(ShaderProgram*  shader) {
	for (Map::iterator it = originalObjects->begin(); it != originalObjects->end(); ++it) {
		WorldObject * wo = it->second;
		//wo->setPosTrans(transform());
		wo->draw(shader);
		//wo->setPosTrans(glm::mat4(1.0f));
	}
}
Пример #2
0
void WorldObjectEffect::updateTask(BulkDivideInfo bi, int threadIndex, const vector<unique_ptr<WorldObject>> *grp, WorldObjectEffect *effect)
{
	effect->workerThreadsCreated++;
	//ComPtr<ID3D12GraphicsCommandList> commandList;
	//ComPtr<ID3D12CommandAllocator> commandAllocator;
	int frameIndex;
	while (true) {
		{
			unique_lock<mutex> lock(effect->multiRenderLock);
			effect->waiting_for_rendering++;
			effect->render_start.notify_one();
			effect->render_wait.wait(lock);
			if (effect->allThreadsShouldEnd) break; // jump out of while loop
		}
		// now running outside lock so that all worker threads run in parallel
		//if (threadIndex > 0) Sleep(10);
		//Log("rendering " << this_thread::get_id() << endl);
		//this_thread::sleep_for(1s);
		//Log("rendering ended " << this_thread::get_id() << endl);
		frameIndex = xapp().getCurrentBackBufferIndex();
		if (!threadLocal.initialized) {
			threadLocal.initialized = true;
			Log(" obj bulk update thread " << std::hex << this_thread::get_id() << " " << bi.start << endl);
			//Log(" obj bulk update thread " << bi.start << endl);
			this_thread::sleep_for(4s);
			ThrowIfFailed(xapp().device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&threadLocal.commandAllocator)));
			ThrowIfFailed(xapp().device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, threadLocal.commandAllocator.Get(), effect->pipelineState.Get(), IID_PPV_ARGS(&threadLocal.commandList)));
		} else {
			threadLocal.commandAllocator->Reset();
			threadLocal.commandList->Reset(threadLocal.commandAllocator.Get(), effect->pipelineState.Get());
		}
		//Log(" obj bulk update thread " << bi.end << " complete" << endl);
		threadLocal.commandList->SetGraphicsRootSignature(effect->rootSignature.Get());
		// TODO check
		//threadLocal.commandList->RSSetViewports(1, xapp().vr.getViewport());
		//threadLocal.commandList->RSSetScissorRects(1, xapp().vr.getScissorRect());

		// Set CBVs
		//commandLists[frameIndex]->SetGraphicsRootConstantBufferView(0, cbvResource->GetGPUVirtualAddress() + cbvAlignedSize);
		//threadLocal.commandList->SetGraphicsRootConstantBufferView(1, xapp().lights.cbvResource->GetGPUVirtualAddress());

		// Indicate that the back buffer will be used as a render target.
		//	commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(renderTargets[frameIndex].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));

		CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle = xapp().getRTVHandle(frameIndex);
		CD3DX12_CPU_DESCRIPTOR_HANDLE dsvHandle(xapp().dsvHeaps[frameIndex]->GetCPUDescriptorHandleForHeapStart());
		threadLocal.commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle);
		threadLocal.commandList->SetGraphicsRootConstantBufferView(0, effect->getCBVVirtualAddress(frameIndex, threadIndex, 0, 0));
		for (auto i = bi.start; i <= bi.end; i++) {
			WorldObject *w = grp->at(i).get();
			//commandList->SetGraphicsRootConstantBufferView(0, effect->getCBVVirtualAddress(frameIndex, w->objectNum));
			w->threadNum = threadIndex;
			//if (threadIndex == 1) 			this_thread::sleep_for(30ms);
			//Log(" obj draw" << w->objectNum << endl);
			w->draw();
			//Log("    obj end" << w->objectNum << endl);
			//Log(" pos" << w->objectNum << endl)
			//auto & w = grp[i];
			//w.->draw();
		}
		ThrowIfFailed(threadLocal.commandList->Close());
		// Execute the command list.
		ID3D12CommandList* ppCommandLists[] = { threadLocal.commandList.Get() };
		xapp().commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
		{
			unique_lock<mutex> lock(effect->multiRenderLock);
			effect->finished_rendering++;
			effect->render_ended.notify_one();
		}
	}
	effect->workerThreadsCreated--;
}