1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2025-01-18 10:52:14 +01:00

added shader module and pipeline handling

This commit is contained in:
Unknown 2018-09-23 20:55:30 +01:00
parent 68a41c6a40
commit 19cecd25b8
4 changed files with 401 additions and 44 deletions

View File

@ -419,44 +419,80 @@ VkResult vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCrea
rp->subpasses[c].colorAttachmentCount = pCreateInfo->pSubpasses[c].colorAttachmentCount;
rp->subpasses[c].preserveAttachmentCount = pCreateInfo->pSubpasses[c].preserveAttachmentCount;
rp->subpasses[c].pInputAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].inputAttachmentCount);
if(!rp->subpasses[c].pInputAttachments)
if(rp->subpasses[c].inputAttachmentCount)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
rp->subpasses[c].pInputAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].inputAttachmentCount);
if(!rp->subpasses[c].pInputAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(rp->subpasses[c].pInputAttachments, pCreateInfo->pSubpasses[c].pInputAttachments, sizeof(VkAttachmentReference)*rp->subpasses[c].inputAttachmentCount);
}
else
{
rp->subpasses[c].pInputAttachments = 0;
}
memcpy(rp->subpasses[c].pInputAttachments, pCreateInfo->pSubpasses[c].pInputAttachments, sizeof(VkAttachmentReference)*rp->subpasses[c].inputAttachmentCount);
rp->subpasses[c].pColorAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
if(!rp->subpasses[c].pColorAttachments)
if(rp->subpasses[c].colorAttachmentCount)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
rp->subpasses[c].pColorAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
if(!rp->subpasses[c].pColorAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(rp->subpasses[c].pColorAttachments, pCreateInfo->pSubpasses[c].pColorAttachments, sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
}
else
{
rp->subpasses[c].pColorAttachments = 0;
}
rp->subpasses[c].pResolveAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
if(!rp->subpasses[c].pResolveAttachments)
if(rp->subpasses[c].colorAttachmentCount && pCreateInfo->pSubpasses[c].pResolveAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
rp->subpasses[c].pResolveAttachments = malloc(sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
if(!rp->subpasses[c].pResolveAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(rp->subpasses[c].pResolveAttachments, pCreateInfo->pSubpasses[c].pResolveAttachments, sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
}
else
{
rp->subpasses[c].pResolveAttachments = 0;
}
memcpy(rp->subpasses[c].pColorAttachments, pCreateInfo->pSubpasses[c].pColorAttachments, sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
memcpy(rp->subpasses[c].pResolveAttachments, pCreateInfo->pSubpasses[c].pResolveAttachments, sizeof(VkAttachmentReference)*rp->subpasses[c].colorAttachmentCount);
rp->subpasses[c].pDepthStencilAttachment = malloc(sizeof(VkAttachmentReference));
if(!rp->subpasses[c].pDepthStencilAttachment)
if(pCreateInfo->pSubpasses[c].pDepthStencilAttachment)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
rp->subpasses[c].pDepthStencilAttachment = malloc(sizeof(VkAttachmentReference));
if(!rp->subpasses[c].pDepthStencilAttachment)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(rp->subpasses[c].pDepthStencilAttachment, pCreateInfo->pSubpasses[c].pDepthStencilAttachment, sizeof(VkAttachmentReference));
}
else
{
rp->subpasses[c].pDepthStencilAttachment = 0;
}
memcpy(rp->subpasses[c].pDepthStencilAttachment, pCreateInfo->pSubpasses[c].pDepthStencilAttachment, sizeof(VkAttachmentReference));
rp->subpasses[c].pPreserveAttachments = malloc(sizeof(uint32_t)*rp->subpasses[c].preserveAttachmentCount);
if(!rp->subpasses[c].pPreserveAttachments)
if(rp->subpasses[c].preserveAttachmentCount)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
rp->subpasses[c].pPreserveAttachments = malloc(sizeof(uint32_t)*rp->subpasses[c].preserveAttachmentCount);
if(!rp->subpasses[c].pPreserveAttachments)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(rp->subpasses[c].pPreserveAttachments, pCreateInfo->pSubpasses[c].pPreserveAttachments, sizeof(uint32_t)*rp->subpasses[c].preserveAttachmentCount);
memcpy(rp->subpasses[c].pPreserveAttachments, pCreateInfo->pSubpasses[c].pPreserveAttachments, sizeof(uint32_t)*rp->subpasses[c].preserveAttachmentCount);
}
else
{
rp->subpasses[c].pPreserveAttachments = 0;
}
}
rp->numSubpassDependencies = pCreateInfo->dependencyCount;
@ -546,12 +582,14 @@ VkResult vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCr
}
VkResult vkCreateShaderModuleFromRpiAssemblyKHR(VkDevice device, uint32_t numBytes, char* byteStream, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
VkResult vkCreateShaderModuleFromRpiAssemblyKHR(VkDevice device, VkRpiShaderModuleAssemblyCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
{
assert(device);
assert(numBytes > 0);
assert(byteStream);
assert(pCreateInfo);
assert(pShaderModule);
assert(pCreateInfo->byteStreamArray);
assert(pCreateInfo->numBytesArray);
assert(pCreateInfo->arraySize > 0);
assert(pAllocator == 0); //TODO
@ -562,8 +600,29 @@ VkResult vkCreateShaderModuleFromRpiAssemblyKHR(VkDevice device, uint32_t numByt
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
uint32_t size = numBytes;
shader->bo = vc4_bo_alloc_shader(controlFd, byteStream, &size);
shader->bos = malloc(sizeof(uint32_t)*pCreateInfo->arraySize);
if(!shader->bos)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
shader->assemblyTypes = malloc(sizeof(VkRpiAssemblyTypeKHR)*pCreateInfo->arraySize);
if(!shader->assemblyTypes)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(shader->assemblyTypes, pCreateInfo->assemblyTypes, sizeof(VkRpiAssemblyTypeKHR)*pCreateInfo->arraySize);
shader->numBos = pCreateInfo->arraySize;
for(int c = 0; c < pCreateInfo->arraySize; ++c)
{
uint32_t size = pCreateInfo->numBytesArray[c];
shader->bos[c] = vc4_bo_alloc_shader(controlFd, pCreateInfo->byteStreamArray[c], &size);
}
*pShaderModule = shader;
@ -578,11 +637,165 @@ VkResult vkCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* p
return VK_SUCCESS;
}
uint32_t ulog2(uint32_t v)
{
uint32_t ret = 0;
while(v >>= 1) ret++;
return ret;
}
/*
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateGraphicsPipelines
*/
VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
{
assert(device);
assert(createInfoCount > 0);
assert(pCreateInfos);
assert(pPipelines);
assert(pipelineCache == 0); //TODO not supported right now
assert(pAllocator == 0); //TODO
for(int c = 0; c < createInfoCount; ++c)
{
_pipeline* pip = malloc(sizeof(_pipeline));
if(!pip)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
for(int d = 0; d < pCreateInfos->stageCount; ++d)
{
uint32_t idx = ulog2(pCreateInfos->pStages[d].stage);
pip->modules[idx] = pCreateInfos->pStages[d].module;
pip->names[idx] = malloc(strlen(pCreateInfos->pStages[d].pName)+1);
if(!pip->names[idx])
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(pip->names[idx], pCreateInfos->pStages[d].pName, strlen(pCreateInfos->pStages[d].pName)+1);
}
pip->vertexAttributeDescriptionCount = pCreateInfos->pVertexInputState->vertexAttributeDescriptionCount;
pip->vertexAttributeDescriptions = malloc(sizeof(VkVertexInputAttributeDescription) * pip->vertexAttributeDescriptionCount);
if(!pip->vertexAttributeDescriptions)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(pip->vertexAttributeDescriptions, pCreateInfos->pVertexInputState->pVertexAttributeDescriptions, sizeof(VkVertexInputAttributeDescription) * pip->vertexAttributeDescriptionCount);
pip->vertexBindingDescriptionCount = pCreateInfos->pVertexInputState->vertexBindingDescriptionCount;
pip->vertexBindingDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * pip->vertexBindingDescriptionCount);
if(!pip->vertexBindingDescriptions)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(pip->vertexBindingDescriptions, pCreateInfos->pVertexInputState->pVertexBindingDescriptions, sizeof(VkVertexInputBindingDescription) * pip->vertexBindingDescriptionCount);
pip->topology = pCreateInfos->pInputAssemblyState->topology;
pip->primitiveRestartEnable = pCreateInfos->pInputAssemblyState->primitiveRestartEnable;
//TODO tessellation ignored
pip->viewportCount = pCreateInfos->pViewportState->viewportCount;
pip->viewports = malloc(sizeof(VkViewport) * pip->viewportCount);
if(!pip->viewports)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(pip->viewports, pCreateInfos->pViewportState->pViewports, sizeof(VkViewport) * pip->viewportCount);
pip->scissorCount = pCreateInfos->pViewportState->scissorCount;
pip->scissors = malloc(sizeof(VkRect2D) * pip->viewportCount);
if(!pip->scissors)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(pip->scissors, pCreateInfos->pViewportState->pScissors, sizeof(VkRect2D) * pip->scissorCount);
pip->depthClampEnable = pCreateInfos->pRasterizationState->depthClampEnable;
pip->rasterizerDiscardEnable = pCreateInfos->pRasterizationState->rasterizerDiscardEnable;
pip->polygonMode = pCreateInfos->pRasterizationState->polygonMode;
pip->cullMode = pCreateInfos->pRasterizationState->cullMode;
pip->frontFace = pCreateInfos->pRasterizationState->frontFace;
pip->depthBiasEnable = pCreateInfos->pRasterizationState->depthBiasEnable;
pip->depthBiasConstantFactor = pCreateInfos->pRasterizationState->depthBiasConstantFactor;
pip->depthBiasClamp = pCreateInfos->pRasterizationState->depthBiasClamp;
pip->depthBiasSlopeFactor = pCreateInfos->pRasterizationState->depthBiasSlopeFactor;
pip->lineWidth = pCreateInfos->pRasterizationState->lineWidth;
pip->rasterizationSamples = pCreateInfos->pMultisampleState->rasterizationSamples;
pip->sampleShadingEnable = pCreateInfos->pMultisampleState->sampleShadingEnable;
pip->minSampleShading = pCreateInfos->pMultisampleState->minSampleShading;
if(pCreateInfos->pMultisampleState->pSampleMask)
{
pip->sampleMask = *pCreateInfos->pMultisampleState->pSampleMask;
}
else
{
pip->sampleMask = 0;
}
pip->alphaToCoverageEnable = pCreateInfos->pMultisampleState->alphaToCoverageEnable;
pip->alphaToOneEnable = pCreateInfos->pMultisampleState->alphaToOneEnable;
pip->depthTestEnable = pCreateInfos->pDepthStencilState->depthTestEnable;
pip->depthWriteEnable = pCreateInfos->pDepthStencilState->depthWriteEnable;
pip->depthCompareOp = pCreateInfos->pDepthStencilState->depthCompareOp;
pip->depthBoundsTestEnable = pCreateInfos->pDepthStencilState->depthBoundsTestEnable;
pip->stencilTestEnable = pCreateInfos->pDepthStencilState->stencilTestEnable;
pip->front = pCreateInfos->pDepthStencilState->front;
pip->back = pCreateInfos->pDepthStencilState->back;
pip->minDepthBounds = pCreateInfos->pDepthStencilState->minDepthBounds;
pip->maxDepthBounds = pCreateInfos->pDepthStencilState->maxDepthBounds;
pip->logicOpEnable = pCreateInfos->pColorBlendState->logicOpEnable;
pip->logicOp = pCreateInfos->pColorBlendState->logicOp;
pip->attachmentCount = pCreateInfos->pColorBlendState->attachmentCount;
pip->attachmentBlendStates = malloc(sizeof(VkPipelineColorBlendAttachmentState) * pip->attachmentCount);
if(!pip->attachmentBlendStates)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(pip->attachmentBlendStates, pCreateInfos->pColorBlendState->pAttachments, sizeof(VkPipelineColorBlendAttachmentState) * pip->attachmentCount);
memcpy(pip->blendConstants, pCreateInfos->pColorBlendState, sizeof(float)*4);
if(pCreateInfos->pDynamicState)
{
pip->dynamicStateCount = pCreateInfos->pDynamicState->dynamicStateCount;
pip->dynamicStates = malloc(sizeof(VkDynamicState)*pip->dynamicStateCount);
if(!pip->dynamicStates)
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy(pip->dynamicStates, pCreateInfos->pDynamicState->pDynamicStates, sizeof(VkDynamicState)*pip->dynamicStateCount);
}
else
{
pip->dynamicStateCount = 0;
pip->dynamicStates = 0;
}
pip->layout = pCreateInfos->layout;
pip->renderPass = pCreateInfos->renderPass;
pip->subpass = pCreateInfos->subpass;
//TODO derivative pipelines ignored
pPipelines[c] = pip;
}
return VK_SUCCESS;
}

View File

@ -198,9 +198,62 @@ typedef struct VkFramebuffer_T
typedef struct VkShaderModule_T
{
uint32_t bo;
uint32_t* bos;
VkRpiAssemblyTypeKHR* assemblyTypes;
uint32_t numBos;
} _shaderModule;
typedef struct VkPipeline_T
{
VkShaderModule modules[6];
char* names[6];
uint32_t vertexBindingDescriptionCount;
VkVertexInputBindingDescription* vertexBindingDescriptions;
uint32_t vertexAttributeDescriptionCount;
VkVertexInputAttributeDescription* vertexAttributeDescriptions;
VkPrimitiveTopology topology;
VkBool32 primitiveRestartEnable;
uint32_t viewportCount;
VkViewport* viewports;
uint32_t scissorCount;
VkRect2D* scissors;
VkBool32 depthClampEnable;
VkBool32 rasterizerDiscardEnable;
VkPolygonMode polygonMode;
VkCullModeFlags cullMode;
VkFrontFace frontFace;
VkBool32 depthBiasEnable;
float depthBiasConstantFactor;
float depthBiasClamp;
float depthBiasSlopeFactor;
float lineWidth;
VkSampleCountFlagBits rasterizationSamples;
VkBool32 sampleShadingEnable;
float minSampleShading;
VkSampleMask sampleMask;
VkBool32 alphaToCoverageEnable;
VkBool32 alphaToOneEnable;
VkBool32 depthTestEnable;
VkBool32 depthWriteEnable;
VkCompareOp depthCompareOp;
VkBool32 depthBoundsTestEnable;
VkBool32 stencilTestEnable;
VkStencilOpState front;
VkStencilOpState back;
float minDepthBounds;
float maxDepthBounds;
VkBool32 logicOpEnable;
VkLogicOp logicOp;
uint32_t attachmentCount;
VkPipelineColorBlendAttachmentState* attachmentBlendStates;
float blendConstants[4];
uint32_t dynamicStateCount;
VkDynamicState* dynamicStates;
VkPipelineLayout layout;
_renderpass* renderPass;
uint32_t subpass;
} _pipeline;
void getPaddedTextureDimensionsT(uint32_t width, uint32_t height, uint32_t bpp, uint32_t* paddedWidth, uint32_t* paddedHeight);
uint32_t getFormatBpp(VkFormat f);
uint32_t packVec4IntoABGR8(const float rgba[4]);

View File

@ -13,6 +13,14 @@ typedef enum VkRpiSurfaceCreateFlagsKHR {
VK_RPI_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VkRpiSurfaceCreateFlagsKHR;
typedef enum VkRpiAssemblyTypeKHR {
VK_RPI_ASSEMBLY_TYPE_COORDINATE = 0,
VK_RPI_ASSEMBLY_TYPE_VERTEX = 1,
VK_RPI_ASSEMBLY_TYPE_FRAGMENT = 2,
VK_RPI_ASSEMBLY_TYPE_COMPUTE = 3,
VK_RPI_ASSEMBLY_TYPE_MAX,
} VkRpiAssemblyTypeKHR;
typedef struct VkRpiSurfaceCreateInfoKHR {
VkStructureType sType;
const void* pNext;
@ -20,6 +28,15 @@ typedef struct VkRpiSurfaceCreateInfoKHR {
//maybe include some other stuff dunno
} VkRpiSurfaceCreateInfoKHR;
typedef struct VkRpiShaderModuleAssemblyCreateInfoKHR {
VkStructureType sType;
const void* pNext;
char** byteStreamArray;
uint32_t* numBytesArray;
VkRpiAssemblyTypeKHR* assemblyTypes;
uint32_t arraySize;
} VkRpiShaderModuleAssemblyCreateInfoKHR;
//extension name something like: VK_KHR_rpi_surface
//extension that allows developers to create a surface to render to on Raspbian Stretch Lite
VkResult vkCreateRpiSurfaceKHR(
@ -31,9 +48,8 @@ VkResult vkCreateRpiSurfaceKHR(
//extension that allows developers to submit QPU assembly directly and thus hand optimise code
VkResult vkCreateShaderModuleFromRpiAssemblyKHR(
VkDevice device,
uint32_t numBytes,
char* byteStream,
const VkAllocationCallbacks* pAllocator,
VkRpiShaderModuleAssemblyCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);

View File

@ -31,6 +31,37 @@ const char* vertShader =
"attribute vec2 vertex;\n"
"void main(){ gl_Position = vec4(vertex, 0, 1); }\n";
const char fragBytes[] =
{
00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x10, 00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x10,
0x80, 0x7d, 0x82, 0x15, 0xa7, 0xb, 0x2, 0x10, 00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x30,
00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x10, 00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x50
};
const char vertBytes[] =
{
0x80, 0x1f, 0x82, 0x2, 0x27, 0x10, 0x2, 0xd0, 00, 0x1a, 0x20, 00, 0x67, 0x4c, 0x2, 0xe0,
0x37, 00, 0xc2, 0x20, 0xe0, 0x49, 00, 0x10, 0x7, 00, 0x9c, 0x20, 0xe1, 0x49, 00, 0x10,
0x77, 0x2, 0xc2, 0x27, 0x22, 0x40, 0x12, 0x10, 0x17, 00, 0x9c, 0x20, 0xe3, 0x49, 00, 0x10,
0xc0, 0x76, 0x9e, 0x7, 0x27, 00, 0x22, 0x10, 00, 0x1a, 00, 00, 0x67, 0x5c, 0x2, 0xe0,
0x80, 0x7d, 0x2, 0x15, 0x27, 0xc, 0x2, 0x10, 0x80, 0x7d, 0x82, 0x15, 0x27, 0xc, 0x2, 0x10,
0xc0, 0xf, 0x9c, 0x15, 0x27, 0xc, 0x2, 0x10, 00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x30,
00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x10, 00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x10,
};
const char coordinateBytes[] =
{
00, 0x1a, 0x20, 00, 0x67, 0x4c, 0x2, 0xe0, 0x80, 0x7d, 0xc2, 0x15, 0xa7, 0x8, 0x2, 0x10,
00, 0x1a, 00, 00, 0x67, 0x5c, 0x2, 0xe0, 0x92, 0x7d, 0xc2, 0x95, 0xf0, 0x48, 0x2, 0x10,
0xde, 0x76, 0x82, 0x35, 0x21, 0x4c, 0x2, 0x10, 0x80, 0x1f, 0x82, 0x2, 0xe7, 0x8, 0x2, 0xd0,
0x16, 0x70, 0x82, 0x20, 0xe2, 0x49, 00, 0x10, 0x13, 0x70, 0x9e, 0x20, 0xe0, 0x49, 00, 0x10,
0xb, 0x70, 0x9e, 0x27, 0x21, 0x40, 0x12, 0x10, 0x40, 0x72, 0x9e, 0x7, 0x27, 00, 0x22, 0x10,
0xc0, 0xf, 0x9c, 0x15, 0x27, 0xc, 0x2, 0xd0, 0xc0, 0xf, 0x9e, 0x15, 0x27, 0xc, 0x2, 0xd0,
0x80, 0x7d, 0x2, 0x15, 0x27, 0xc, 0x2, 0x10, 0x80, 0x7d, 0x82, 0x15, 0x27, 0xc, 0x2, 0x10,
0xc0, 0x76, 0x9e, 0x15, 0x27, 0xc, 0x2, 0x10, 00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x30,
00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x10, 00, 0x70, 0x9e, 00, 0xe7, 0x9, 00, 0x10,
};
// Note: support swap chain recreation (not only required for resized windows!)
// Note: window resize may not result in Vulkan telling that the swap chain should be recreated, should be handled explicitly!
void run();
@ -796,14 +827,14 @@ VkShaderModule VulkanCreateShaderModule(VkDevice& device, char* byteStream, uint
{
VkShaderModule shaderModule;
/*VkShaderModuleCreateInfo shaderCreateInfo = {};
VkShaderModuleCreateInfo shaderCreateInfo = {};
shaderCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
shaderCreateInfo.codeSize = codeSize;
shaderCreateInfo.pCode = (const uint32_t*)code;
shaderCreateInfo.codeSize = byteStreamSize;
shaderCreateInfo.pCode = (const uint32_t*)byteStream;
VkResult res = vkCreateShaderModule(device, &shaderCreateInfo, NULL, &shaderModule);*/
VkResult res = vkCreateShaderModule(device, &shaderCreateInfo, NULL, &shaderModule);
VkResult res = vkCreateShaderModuleFromRpiAssemblyKHR(device, byteStreamSize, byteStream, NULL, &shaderModule);
//VkResult res = vkCreateShaderModuleFromRpiAssemblyKHR(device, byteStreamSize, byteStream, NULL, &shaderModule);
printf("Created shader\n");
@ -812,20 +843,64 @@ VkShaderModule VulkanCreateShaderModule(VkDevice& device, char* byteStream, uint
void CreateShaders()
{
char* vptr = (char*)malloc(strlen(vertShader) + 1);
memcpy(vptr, vertShader, strlen(vertShader) + 1);
//char* vptr = (char*)malloc(strlen(vertShader) + 1);
//memcpy(vptr, vertShader, strlen(vertShader) + 1);
char* fptr = (char*)malloc(strlen(fragShader) + 1);
memcpy(fptr, fragShader, strlen(fragShader) + 1);
//char* fptr = (char*)malloc(strlen(fragShader) + 1);
//memcpy(fptr, fragShader, strlen(fragShader) + 1);
vsModule = VulkanCreateShaderModule(device, vptr, strlen(vptr));
char* vptr = (char*)malloc(sizeof(vertBytes));
memcpy(vptr, vertBytes, sizeof(vertBytes));
char* fptr = (char*)malloc(sizeof(fragBytes));
memcpy(fptr, fragBytes, sizeof(fragBytes));
char* cptr = (char*)malloc(sizeof(coordinateBytes));
memcpy(cptr, coordinateBytes, sizeof(coordinateBytes));
VkRpiAssemblyTypeKHR types[] =
{
VK_RPI_ASSEMBLY_TYPE_COORDINATE, VK_RPI_ASSEMBLY_TYPE_VERTEX
};
VkRpiAssemblyTypeKHR fragtypes[] =
{
VK_RPI_ASSEMBLY_TYPE_FRAGMENT
};
char* streams[] =
{
cptr, vptr
};
uint32_t numbytes[] =
{
sizeof(coordinateBytes), sizeof(vertBytes)
};
uint32_t fragsize = sizeof(fragBytes);
VkRpiShaderModuleAssemblyCreateInfoKHR vertexShaderModuleCreateInfo;
vertexShaderModuleCreateInfo.arraySize = 2;
vertexShaderModuleCreateInfo.assemblyTypes = types;
vertexShaderModuleCreateInfo.byteStreamArray = streams;
vertexShaderModuleCreateInfo.numBytesArray = numbytes;
VkRpiShaderModuleAssemblyCreateInfoKHR fragShaderModuleCreateInfo;
fragShaderModuleCreateInfo.arraySize = 1;
fragShaderModuleCreateInfo.assemblyTypes = fragtypes;
fragShaderModuleCreateInfo.byteStreamArray = &fptr;
fragShaderModuleCreateInfo.numBytesArray = &fragsize;
VkResult res = vkCreateShaderModuleFromRpiAssemblyKHR(device, &vertexShaderModuleCreateInfo, 0, &vsModule);
assert(vsModule);
fsModule = VulkanCreateShaderModule(device, fptr, strlen(fptr));
res = vkCreateShaderModuleFromRpiAssemblyKHR(device, &fragShaderModuleCreateInfo, 0, &fsModule);
assert(fsModule);
free(vptr);
free(fptr);
free(cptr);
}