예제 #1
0
void initDescriptorSet(GR_DEVICE device, GR_QUEUE commandQueue, GR_DESCRIPTOR_SET& descriptorSet, GR_MEMORY_REF& descriptorMemRef, GR_MEMORY_REF& vertexDataMemRef) {
	// Create descriptor set for vertex shader inputs
	GR_DESCRIPTOR_SET_CREATE_INFO descriptorCreateInfo = {};
	descriptorCreateInfo.slots = 2;

	grCreateDescriptorSet(device, &descriptorCreateInfo, &descriptorSet);

	descriptorMemRef = allocateObjectMemory(device, descriptorSet);

	// Store vertex data in GPU memory
	GR_GPU_MEMORY vertexDataMemory = allocateMappableBuffer(device, sizeof(vertices));

	void* bufferPointer;
	grMapMemory(vertexDataMemory, 0, &bufferPointer);
	memcpy(bufferPointer, vertices, sizeof(vertices));
	grUnmapMemory(vertexDataMemory);

	vertexDataMemRef = {};
	vertexDataMemRef.mem = vertexDataMemory;

	// Create and submit command buffer that transitions vertex data memory to being shader accessible
	GR_CMD_BUFFER initDataCmdBuffer;
	grCreateCommandBuffer(device, &bufferCreateInfo, &initDataCmdBuffer);

	grBeginCommandBuffer(initDataCmdBuffer, 0);

		GR_MEMORY_STATE_TRANSITION dataTransition = {};
		dataTransition.mem = vertexDataMemory;
		dataTransition.oldState = GR_MEMORY_STATE_DATA_TRANSFER;
		dataTransition.newState = GR_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;
		dataTransition.offset = 0;
		dataTransition.regionSize = sizeof(vertices);

		grCmdPrepareMemoryRegions(initDataCmdBuffer, 1, &dataTransition);

	grEndCommandBuffer(initDataCmdBuffer);

	grQueueSubmit(commandQueue, 1, &initDataCmdBuffer, 1, &vertexDataMemRef, 0);

	// Attach views to the vertex data to the descriptor set
	grBeginDescriptorSetUpdate(descriptorSet);

	GR_MEMORY_VIEW_ATTACH_INFO memoryViewAttachInfo = {};
	memoryViewAttachInfo.mem = vertexDataMemory;
	memoryViewAttachInfo.offset = 0;
	memoryViewAttachInfo.stride = sizeof(float) * 4;
	memoryViewAttachInfo.range = sizeof(float) * 12;
	memoryViewAttachInfo.format.channelFormat = GR_CH_FMT_R32G32B32A32;
	memoryViewAttachInfo.format.numericFormat = GR_NUM_FMT_FLOAT;
	memoryViewAttachInfo.state = GR_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY;

	grAttachMemoryViewDescriptors(descriptorSet, 0, 1, &memoryViewAttachInfo);

	memoryViewAttachInfo.offset = sizeof(float) * 12;
	memoryViewAttachInfo.range = sizeof(float) * 12;

	grAttachMemoryViewDescriptors(descriptorSet, 1, 1, &memoryViewAttachInfo);

	grEndDescriptorSetUpdate(descriptorSet);
}
예제 #2
0
void createGraphicsPipeline(GR_DEVICE device, GR_PIPELINE& pipeline, GR_MEMORY_REF& pipelineMemRef) {
	// Load shaders
	GR_SHADER vertexShader = createShader(device, "shaders/vs.bin");
	GR_SHADER fragShader = createShader(device, "shaders/ps.bin");

	// Specify descriptor slots
	GR_DESCRIPTOR_SLOT_INFO vsDescriptorSlots[2];

	vsDescriptorSlots[0].slotObjectType = GR_SLOT_SHADER_RESOURCE;
	vsDescriptorSlots[0].shaderEntityIndex = 0;

	vsDescriptorSlots[1].slotObjectType = GR_SLOT_SHADER_RESOURCE;
	vsDescriptorSlots[1].shaderEntityIndex = 1;

	GR_DESCRIPTOR_SLOT_INFO psDescriptorSlots[2];

	psDescriptorSlots[0].slotObjectType = GR_SLOT_UNUSED;
	psDescriptorSlots[1].slotObjectType = GR_SLOT_UNUSED;

	// Create graphics pipeline
	GR_GRAPHICS_PIPELINE_CREATE_INFO pipelineCreateInfo = {};

	pipelineCreateInfo.vs.shader = vertexShader;
	pipelineCreateInfo.vs.dynamicMemoryViewMapping.slotObjectType = GR_SLOT_UNUSED;
	pipelineCreateInfo.vs.descriptorSetMapping[0].descriptorCount = 2;
	pipelineCreateInfo.vs.descriptorSetMapping[0].pDescriptorInfo = vsDescriptorSlots;

	pipelineCreateInfo.ps.shader = fragShader;
	pipelineCreateInfo.ps.dynamicMemoryViewMapping.slotObjectType = GR_SLOT_UNUSED;
	pipelineCreateInfo.ps.descriptorSetMapping[0].descriptorCount = 2;
	pipelineCreateInfo.ps.descriptorSetMapping[0].pDescriptorInfo = psDescriptorSlots;

	pipelineCreateInfo.iaState.topology = GR_TOPOLOGY_TRIANGLE_LIST;
	pipelineCreateInfo.iaState.disableVertexReuse = GR_FALSE;

	pipelineCreateInfo.rsState.depthClipEnable = GR_FALSE;

	pipelineCreateInfo.cbState.logicOp = GR_LOGIC_OP_COPY;
	pipelineCreateInfo.cbState.target[0].blendEnable = GR_TRUE;
	pipelineCreateInfo.cbState.target[0].channelWriteMask = 0xF; // RGBA bits
	pipelineCreateInfo.cbState.target[0].format.channelFormat = GR_CH_FMT_R8G8B8A8;
	pipelineCreateInfo.cbState.target[0].format.numericFormat = GR_NUM_FMT_UNORM;

	pipelineCreateInfo.dbState.format.channelFormat = GR_CH_FMT_R4G4B4A4;
	pipelineCreateInfo.dbState.format.numericFormat = GR_NUM_FMT_UNDEFINED;

	grCreateGraphicsPipeline(device, &pipelineCreateInfo, &pipeline);

	pipelineMemRef = allocateObjectMemory(device, pipeline);
}
예제 #3
0
파일: vm.c 프로젝트: mib/smalltalk-vm
void allocateAll() {
	allocateObjectMemory();
	allocateMethodLookupCache();
	allocateFileStreamTable();
}