void VulkanCreationInfo::ShaderModule::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, const VkShaderModuleCreateInfo* pCreateInfo) { const uint32_t SPIRVMagic = 0x07230203; if(pCreateInfo->codeSize < 4 || memcmp(pCreateInfo->pCode, &SPIRVMagic, sizeof(SPIRVMagic))) { RDCWARN("Shader not provided with SPIR-V"); } else { static const unsigned int MagicNumber = 0x07230203; // SPIR-V magic number // is the SPIR-V version 0? assume GLSL if(pCreateInfo->pCode[0] == MagicNumber && pCreateInfo->pCode[1] == 0) { // GLSL - compile to SPIR-V ourselves const char *src = (const char *)(pCreateInfo->pCode+3); vector<string> srcs; srcs.push_back(src); vector<uint32_t> spirv_code; string ret = CompileSPIRV((SPIRVShaderStage)StageIndex((VkShaderStageFlagBits)pCreateInfo->pCode[2]), srcs, spirv_code); ParseSPIRV(&spirv_code[0], spirv_code.size(), spirv); } else { RDCASSERT(pCreateInfo->codeSize % sizeof(uint32_t) == 0); ParseSPIRV((uint32_t *)pCreateInfo->pCode, pCreateInfo->codeSize/sizeof(uint32_t), spirv); } } }
void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, const VkGraphicsPipelineCreateInfo* pCreateInfo) { flags = pCreateInfo->flags; layout = resourceMan->GetNonDispWrapper(pCreateInfo->layout)->id; renderpass = resourceMan->GetNonDispWrapper(pCreateInfo->renderPass)->id; subpass = pCreateInfo->subpass; // need to figure out which states are valid to be NULL // VkPipelineShaderStageCreateInfo for(uint32_t i=0; i < pCreateInfo->stageCount; i++) { ResourceId id = resourceMan->GetNonDispWrapper(pCreateInfo->pStages[i].module)->id; // convert shader bit to shader index int stageIndex = StageIndex(pCreateInfo->pStages[i].stage); Shader &shad = shaders[stageIndex]; shad.module = id; shad.entryPoint = pCreateInfo->pStages[i].pName; ShaderModule::Reflection &reflData = info.m_ShaderModule[id].m_Reflections[shad.entryPoint]; if(reflData.entryPoint.empty()) { reflData.entryPoint = shad.entryPoint; info.m_ShaderModule[id].spirv.MakeReflection(reflData.entryPoint, &reflData.refl, &reflData.mapping); } if(pCreateInfo->pStages[i].pSpecializationInfo) { shad.specdata.resize(pCreateInfo->pStages[i].pSpecializationInfo->dataSize); memcpy(&shad.specdata[0], pCreateInfo->pStages[i].pSpecializationInfo->pData, shad.specdata.size()); const VkSpecializationMapEntry *maps = pCreateInfo->pStages[i].pSpecializationInfo->pMapEntries; for(uint32_t s=0; s < pCreateInfo->pStages[i].pSpecializationInfo->mapEntryCount; s++) { Shader::SpecInfo spec; spec.specID = maps[s].constantID; spec.data = &shad.specdata[maps[s].offset]; spec.size = maps[s].size; // ignore maps[s].size, assume it's enough for the type shad.specialization.push_back(spec); } } shad.refl = &reflData.refl; shad.mapping = &reflData.mapping; } if(pCreateInfo->pVertexInputState) { vertexBindings.resize(pCreateInfo->pVertexInputState->vertexBindingDescriptionCount); for(uint32_t i=0; i < pCreateInfo->pVertexInputState->vertexBindingDescriptionCount; i++) { vertexBindings[i].vbufferBinding = pCreateInfo->pVertexInputState->pVertexBindingDescriptions[i].binding; vertexBindings[i].bytestride = pCreateInfo->pVertexInputState->pVertexBindingDescriptions[i].stride; vertexBindings[i].perInstance = pCreateInfo->pVertexInputState->pVertexBindingDescriptions[i].inputRate == VK_VERTEX_INPUT_RATE_INSTANCE; } vertexAttrs.resize(pCreateInfo->pVertexInputState->vertexAttributeDescriptionCount); for(uint32_t i=0; i < pCreateInfo->pVertexInputState->vertexAttributeDescriptionCount; i++) { vertexAttrs[i].binding = pCreateInfo->pVertexInputState->pVertexAttributeDescriptions[i].binding; vertexAttrs[i].location = pCreateInfo->pVertexInputState->pVertexAttributeDescriptions[i].location; vertexAttrs[i].format = pCreateInfo->pVertexInputState->pVertexAttributeDescriptions[i].format; vertexAttrs[i].byteoffset = pCreateInfo->pVertexInputState->pVertexAttributeDescriptions[i].offset; } } topology = pCreateInfo->pInputAssemblyState->topology; primitiveRestartEnable = pCreateInfo->pInputAssemblyState->primitiveRestartEnable ? true : false; if(pCreateInfo->pTessellationState) patchControlPoints = pCreateInfo->pTessellationState->patchControlPoints; else patchControlPoints = 0; if(pCreateInfo->pViewportState) viewportCount = pCreateInfo->pViewportState->viewportCount; else viewportCount = 0; viewports.resize(viewportCount); scissors.resize(viewportCount); for(size_t i=0; i < viewports.size(); i++) { if(pCreateInfo->pViewportState->pViewports) viewports[i] = pCreateInfo->pViewportState->pViewports[i]; if(pCreateInfo->pViewportState->pScissors) scissors[i] = pCreateInfo->pViewportState->pScissors[i]; } // VkPipelineRasterStateCreateInfo depthClampEnable = pCreateInfo->pRasterizationState->depthClampEnable ? true : false; rasterizerDiscardEnable = pCreateInfo->pRasterizationState->rasterizerDiscardEnable ? true : false; polygonMode = pCreateInfo->pRasterizationState->polygonMode; cullMode = pCreateInfo->pRasterizationState->cullMode; frontFace = pCreateInfo->pRasterizationState->frontFace; depthBiasEnable = pCreateInfo->pRasterizationState->depthBiasEnable ? true : false; depthBiasConstantFactor = pCreateInfo->pRasterizationState->depthBiasConstantFactor; depthBiasClamp = pCreateInfo->pRasterizationState->depthBiasClamp; depthBiasSlopeFactor = pCreateInfo->pRasterizationState->depthBiasSlopeFactor; lineWidth = pCreateInfo->pRasterizationState->lineWidth; // VkPipelineMultisampleStateCreateInfo if(pCreateInfo->pMultisampleState) { rasterizationSamples = pCreateInfo->pMultisampleState->rasterizationSamples; sampleShadingEnable = pCreateInfo->pMultisampleState->sampleShadingEnable ? true : false; minSampleShading = pCreateInfo->pMultisampleState->minSampleShading; sampleMask = pCreateInfo->pMultisampleState->pSampleMask ? *pCreateInfo->pMultisampleState->pSampleMask : ~0U; alphaToCoverageEnable = pCreateInfo->pMultisampleState->alphaToCoverageEnable ? true : false; alphaToOneEnable = pCreateInfo->pMultisampleState->alphaToOneEnable ? true : false; } else { rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; sampleShadingEnable = false; minSampleShading = 1.0f; sampleMask = ~0U; alphaToCoverageEnable = false; alphaToOneEnable = false; } // VkPipelineDepthStencilStateCreateInfo if(pCreateInfo->pDepthStencilState) { depthTestEnable = pCreateInfo->pDepthStencilState->depthTestEnable ? true : false; depthWriteEnable = pCreateInfo->pDepthStencilState->depthWriteEnable ? true : false; depthCompareOp = pCreateInfo->pDepthStencilState->depthCompareOp; depthBoundsEnable = pCreateInfo->pDepthStencilState->depthBoundsTestEnable ? true : false; stencilTestEnable = pCreateInfo->pDepthStencilState->stencilTestEnable ? true : false; front = pCreateInfo->pDepthStencilState->front; back = pCreateInfo->pDepthStencilState->back; minDepthBounds = pCreateInfo->pDepthStencilState->minDepthBounds; maxDepthBounds = pCreateInfo->pDepthStencilState->maxDepthBounds; } else { depthTestEnable = false; depthWriteEnable = false; depthCompareOp = VK_COMPARE_OP_ALWAYS; depthBoundsEnable = false; stencilTestEnable = false; front.failOp = VK_STENCIL_OP_KEEP; front.passOp = VK_STENCIL_OP_KEEP; front.depthFailOp = VK_STENCIL_OP_KEEP; front.compareOp = VK_COMPARE_OP_ALWAYS; front.compareMask = 0xff; front.writeMask = 0xff; front.reference = 0; back = front; minDepthBounds = 0.0f; maxDepthBounds = 1.0f; } // VkPipelineColorBlendStateCreateInfo if(pCreateInfo->pColorBlendState) { logicOpEnable = pCreateInfo->pColorBlendState->logicOpEnable ? true : false; logicOp = pCreateInfo->pColorBlendState->logicOp; memcpy(blendConst, pCreateInfo->pColorBlendState->blendConstants, sizeof(blendConst)); attachments.resize(pCreateInfo->pColorBlendState->attachmentCount); for(uint32_t i=0; i < pCreateInfo->pColorBlendState->attachmentCount; i++) { attachments[i].blendEnable = pCreateInfo->pColorBlendState->pAttachments[i].blendEnable ? true : false; attachments[i].blend.Source = pCreateInfo->pColorBlendState->pAttachments[i].srcColorBlendFactor; attachments[i].blend.Destination = pCreateInfo->pColorBlendState->pAttachments[i].dstColorBlendFactor; attachments[i].blend.Operation = pCreateInfo->pColorBlendState->pAttachments[i].colorBlendOp; attachments[i].alphaBlend.Source = pCreateInfo->pColorBlendState->pAttachments[i].srcAlphaBlendFactor; attachments[i].alphaBlend.Destination = pCreateInfo->pColorBlendState->pAttachments[i].dstAlphaBlendFactor; attachments[i].alphaBlend.Operation = pCreateInfo->pColorBlendState->pAttachments[i].alphaBlendOp; attachments[i].channelWriteMask = (uint8_t)pCreateInfo->pColorBlendState->pAttachments[i].colorWriteMask; } } else { logicOpEnable = false; logicOp = VK_LOGIC_OP_NO_OP; RDCEraseEl(blendConst); attachments.clear(); } RDCEraseEl(dynamicStates); if(pCreateInfo->pDynamicState) { for(uint32_t i=0; i < pCreateInfo->pDynamicState->dynamicStateCount; i++) dynamicStates[ pCreateInfo->pDynamicState->pDynamicStates[i] ] = true; } }
void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, const VkComputePipelineCreateInfo *pCreateInfo) { flags = pCreateInfo->flags; layout = GetResID(pCreateInfo->layout); // need to figure out which states are valid to be NULL // VkPipelineShaderStageCreateInfo { ResourceId id = GetResID(pCreateInfo->stage.module); Shader &shad = shaders[5]; // 5 is the compute shader's index (VS, TCS, TES, GS, FS, CS) shad.module = id; shad.entryPoint = pCreateInfo->stage.pName; ShaderModule::Reflection &reflData = info.m_ShaderModule[id].m_Reflections[shad.entryPoint]; if(reflData.entryPoint.empty()) { reflData.entryPoint = shad.entryPoint; reflData.stage = StageIndex(pCreateInfo->stage.stage); SPVModule &spv = info.m_ShaderModule[id].spirv; spv.MakeReflection(ShaderStage::Compute, shad.entryPoint, reflData.refl, reflData.mapping, reflData.patchData); reflData.refl.resourceId = resourceMan->GetOriginalID(id); if(!spv.spirv.empty()) { const vector<uint32_t> &spirv = spv.spirv; reflData.refl.encoding = ShaderEncoding::SPIRV; reflData.refl.rawBytes.assign((byte *)spirv.data(), spirv.size() * sizeof(uint32_t)); } } if(pCreateInfo->stage.pSpecializationInfo) { shad.specdata.resize(pCreateInfo->stage.pSpecializationInfo->dataSize); memcpy(&shad.specdata[0], pCreateInfo->stage.pSpecializationInfo->pData, shad.specdata.size()); const VkSpecializationMapEntry *maps = pCreateInfo->stage.pSpecializationInfo->pMapEntries; for(uint32_t s = 0; s < pCreateInfo->stage.pSpecializationInfo->mapEntryCount; s++) { Shader::SpecInfo spec; spec.specID = maps[s].constantID; spec.data = &shad.specdata[maps[s].offset]; spec.size = maps[s].size; shad.specialization.push_back(spec); } } shad.refl = &reflData.refl; shad.mapping = &reflData.mapping; shad.patchData = &reflData.patchData; } topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; primitiveRestartEnable = false; patchControlPoints = 0; viewportCount = 0; // VkPipelineRasterStateCreateInfo depthClampEnable = false; rasterizerDiscardEnable = false; polygonMode = VK_POLYGON_MODE_FILL; cullMode = VK_CULL_MODE_NONE; frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; // VkPipelineMultisampleStateCreateInfo rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; sampleShadingEnable = false; minSampleShading = 1.0f; sampleMask = ~0U; // VkPipelineDepthStencilStateCreateInfo depthTestEnable = false; depthWriteEnable = false; depthCompareOp = VK_COMPARE_OP_ALWAYS; depthBoundsEnable = false; stencilTestEnable = false; RDCEraseEl(front); RDCEraseEl(back); // VkPipelineColorBlendStateCreateInfo alphaToCoverageEnable = false; logicOpEnable = false; logicOp = VK_LOGIC_OP_NO_OP; }