diff --git a/example/Vulkan/RenderSurface.h b/example/Vulkan/RenderSurface.h index 750b4231..7665a4c3 100644 --- a/example/Vulkan/RenderSurface.h +++ b/example/Vulkan/RenderSurface.h @@ -32,6 +32,7 @@ public: virtual ~RenderSurface()=default; VkSurfaceKHR GetSurface () {return rsa->surface;} + VkDevice GetDevice () {return rsa->device;} const PhysicalDevice *GetPhysicalDevice ()const {return rsa->physical_device;} public: diff --git a/example/Vulkan/VKShader.cpp b/example/Vulkan/VKShader.cpp index b945dc9c..81790aca 100644 --- a/example/Vulkan/VKShader.cpp +++ b/example/Vulkan/VKShader.cpp @@ -1,4 +1,30 @@ #include"VKShader.h" VK_NAMESPACE_BEGIN + +VkShaderModule CreateShaderModule(VkDevice device,const uint32_t *spv_data,const uint32_t spv_size,const VkShaderStageFlagBits shader_stage_bit) +{ + VkPipelineShaderStageCreateInfo shader_stage; + shader_stage.sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stage.pNext=nullptr; + shader_stage.pSpecializationInfo=nullptr; + shader_stage.flags=0; + shader_stage.stage=shader_stage_bit; + shader_stage.pName="main"; + + VkShaderModuleCreateInfo moduleCreateInfo; + moduleCreateInfo.sType=VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + moduleCreateInfo.pNext=nullptr; + moduleCreateInfo.flags=0; + moduleCreateInfo.codeSize=spv_size; + moduleCreateInfo.pCode=spv_data; + + VkShaderModule shader_module; + + if(vkCreateShaderModule(device,&moduleCreateInfo,nullptr,&shader_module)==VK_SUCCESS) + return shader_module; + + return nullptr; +} + VK_NAMESPACE_END diff --git a/example/Vulkan/VKShader.h b/example/Vulkan/VKShader.h index 600dce11..a337f1f2 100644 --- a/example/Vulkan/VKShader.h +++ b/example/Vulkan/VKShader.h @@ -4,8 +4,18 @@ VK_NAMESPACE_BEGIN class Shader { + public: };//class Shader + +VkShaderModule CreateShaderModule(VkDevice device,const uint32_t *spv_data,const uint32_t spv_size,const VkShaderStageFlagBits shader_stage_bit); + +inline VkShaderModule CreateVertexShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_VERTEX_BIT); } +inline VkShaderModule CreateFragmentShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_FRAGMENT_BIT); } +inline VkShaderModule CreateGeometryShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_GEOMETRY_BIT); } +inline VkShaderModule CreateTessCtrlShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); } +inline VkShaderModule CreateTessEvalShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); } +inline VkShaderModule CreateComputeShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_COMPUTE_BIT); } VK_NAMESPACE_END diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index e63ae6d9..248f441c 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -1,10 +1,41 @@ #include"Window.h" #include"VKInstance.h" #include"RenderSurface.h" +#include"VKShader.h" + +#include +#include +#include using namespace hgl; using namespace hgl::graph; +VkShaderModule vs=nullptr; +VkShaderModule fs=nullptr; + +char *LoadFile(const char *filename,uint32_t &file_length) +{ + int fp=_open(filename,O_RDONLY); + + if(fp==-1)return(nullptr); + + file_length=_filelength(fp); + char *data=new char[file_length]; + + if(_read(fp,data,file_length)!=file_length) + { + delete[] data; + return(nullptr); + } + + _close(fp); + return data; +} + +bool LoadShader(VkDevice device) +{ +} + int main(int,char **) { Window *win=CreateRenderWindow(OS_TEXT("VulkanTest")); @@ -34,6 +65,9 @@ int main(int,char **) std::cout<<"auto select physical device: "<GetDeviceName()<GetDevice())) + return(-3); + vulkan::CommandBuffer *cmd_buf=render->CreateCommandBuffer(); vulkan::Buffer *ubo=render->CreateUBO(1024);