forked from baldurk/visor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shaders.cpp
87 lines (74 loc) · 2.99 KB
/
shaders.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "precompiled.h"
VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device,
const VkShaderModuleCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkShaderModule *pShaderModule)
{
VkShaderModule ret = new VkShaderModule_T;
uint32_t hash = hashSPV(pCreateInfo->pCode, pCreateInfo->codeSize / sizeof(uint32_t));
ret->func = GetPremadeShader(hash);
if(ret->func == NULL)
{
printf("Unrecognised/hacked shader! whoops!");
return VK_ERROR_DEVICE_LOST;
}
*pShaderModule = ret;
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
const VkAllocationCallbacks *pAllocator)
{
delete shaderModule;
}
VKAPI_ATTR VkResult VKAPI_CALL
vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
const VkGraphicsPipelineCreateInfo *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines)
{
for(uint32_t i = 0; i < createInfoCount; i++)
{
VkPipeline ret = new VkPipeline_T;
ret->topology = pCreateInfos[i].pInputAssemblyState->topology;
ret->frontFace = pCreateInfos[i].pRasterizationState->frontFace;
ret->cullMode = pCreateInfos[i].pRasterizationState->cullMode;
if(pCreateInfos[i].pDepthStencilState)
{
ret->depthCompareOp = pCreateInfos[i].pDepthStencilState->depthCompareOp;
ret->depthWriteEnable = pCreateInfos[i].pDepthStencilState->depthWriteEnable == VK_TRUE;
}
if(pCreateInfos[i].pColorBlendState && pCreateInfos[i].pColorBlendState->attachmentCount > 0)
{
ret->blend = pCreateInfos[i].pColorBlendState->pAttachments[0];
}
else
{
memset(&ret->blend, 0, sizeof(ret->blend));
}
for(uint32_t s = 0; s < pCreateInfos[i].stageCount; s++)
{
if(pCreateInfos[i].pStages[s].stage == VK_SHADER_STAGE_VERTEX_BIT)
ret->vs = (VertexShader)pCreateInfos[i].pStages[s].module->func;
else if(pCreateInfos[i].pStages[s].stage == VK_SHADER_STAGE_FRAGMENT_BIT)
ret->fs = (FragmentShader)pCreateInfos[i].pStages[s].module->func;
}
pPipelines[i] = ret;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL
vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
const VkComputePipelineCreateInfo *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines)
{
for(uint32_t i = 0; i < createInfoCount; i++)
{
VkPipeline ret = new VkPipeline_T;
pPipelines[i] = ret;
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline,
const VkAllocationCallbacks *pAllocator)
{
delete pipeline;
}