mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
include custom vulkan shader in love source
This commit is contained in:
@@ -432,6 +432,37 @@ void main() {
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
static const char vulkan_vert[] = R"(
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 inPosition;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
|
||||||
|
float windowWidth = 800;
|
||||||
|
float windowHeight = 600;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(
|
||||||
|
2 * inPosition.x / windowWidth - 1,
|
||||||
|
2 * inPosition.y / windowHeight - 1,
|
||||||
|
0.0, 1.0);
|
||||||
|
fragColor = vec4(1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
static const char vulkan_pixel[] = R"(
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) in vec4 fragColor;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
outColor = fragColor;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
struct StageInfo
|
struct StageInfo
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
@@ -576,8 +607,14 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage,
|
|||||||
if (glsl1on3)
|
if (glsl1on3)
|
||||||
lang = LANGUAGE_GLSL3;
|
lang = LANGUAGE_GLSL3;
|
||||||
|
|
||||||
if (info.vulkan)
|
if (info.vulkan) {
|
||||||
lang = LANGUAGE_GLSL4;
|
if (stage == SHADERSTAGE_VERTEX) {
|
||||||
|
return love::graphics::glsl::vulkan_vert;
|
||||||
|
}
|
||||||
|
if (stage == SHADERSTAGE_PIXEL) {
|
||||||
|
return love::graphics::glsl::vulkan_pixel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glsl::StageInfo stageinfo = glsl::stageInfo[stage];
|
glsl::StageInfo stageinfo = glsl::stageInfo[stage];
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ namespace love {
|
|||||||
createSwapChain();
|
createSwapChain();
|
||||||
createImageViews();
|
createImageViews();
|
||||||
createRenderPass();
|
createRenderPass();
|
||||||
|
createDefaultShaders();
|
||||||
createGraphicsPipeline();
|
createGraphicsPipeline();
|
||||||
createFramebuffers();
|
createFramebuffers();
|
||||||
createCommandPool();
|
createCommandPool();
|
||||||
@@ -215,17 +216,6 @@ namespace love {
|
|||||||
batchedDrawState.indexBuffer = new StreamBuffer(device, physicalDevice, BUFFERUSAGE_INDEX, sizeof(uint16) * LOVE_UINT16_MAX);
|
batchedDrawState.indexBuffer = new StreamBuffer(device, physicalDevice, BUFFERUSAGE_INDEX, sizeof(uint16) * LOVE_UINT16_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < Shader::STANDARD_MAX_ENUM; i++) {
|
|
||||||
auto stype = (Shader::StandardShader)i;
|
|
||||||
|
|
||||||
if (!Shader::standardShaders[i]) {
|
|
||||||
std::vector<std::string> stages;
|
|
||||||
stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_VERTEX));
|
|
||||||
stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_PIXEL));
|
|
||||||
Shader::standardShaders[i] = newShader(stages, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -696,29 +686,22 @@ namespace love {
|
|||||||
return shaderModule;
|
return shaderModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Graphics::createDefaultShaders() {
|
||||||
|
for (int i = 0; i < Shader::STANDARD_MAX_ENUM; i++) {
|
||||||
|
auto stype = (Shader::StandardShader)i;
|
||||||
|
|
||||||
|
if (!Shader::standardShaders[i]) {
|
||||||
|
std::vector<std::string> stages;
|
||||||
|
stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_VERTEX));
|
||||||
|
stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_PIXEL));
|
||||||
|
Shader::standardShaders[i] = newShader(stages, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::createGraphicsPipeline() {
|
void Graphics::createGraphicsPipeline() {
|
||||||
// love::graphics::vulkan::Shader* shader = dynamic_cast<love::graphics::vulkan::Shader*>(getShader());
|
auto shader = reinterpret_cast<love::graphics::vulkan::Shader*>(love::graphics::vulkan::Shader::standardShaders[Shader::STANDARD_DEFAULT]);
|
||||||
// auto shaderStages = shader->getShaderStages();
|
auto shaderStages = shader->getShaderStages();
|
||||||
|
|
||||||
auto vertShaderCode = readFile("vert.spv");
|
|
||||||
auto fragShaderCode = readFile("frag.spv");
|
|
||||||
|
|
||||||
VkShaderModule vertShaderModule = createShaderModule(device, vertShaderCode);
|
|
||||||
VkShaderModule fragShaderModule = createShaderModule(device, fragShaderCode);
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo{};
|
|
||||||
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
|
||||||
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
|
||||||
vertShaderStageInfo.module = vertShaderModule;
|
|
||||||
vertShaderStageInfo.pName = "main";
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo fragShaderStageInfo{};
|
|
||||||
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
|
||||||
fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
|
||||||
fragShaderStageInfo.module = fragShaderModule;
|
|
||||||
fragShaderStageInfo.pName = "main";
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo };
|
|
||||||
|
|
||||||
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
|
||||||
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||||
@@ -812,10 +795,8 @@ namespace love {
|
|||||||
|
|
||||||
VkGraphicsPipelineCreateInfo pipelineInfo{};
|
VkGraphicsPipelineCreateInfo pipelineInfo{};
|
||||||
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||||
// pipelineInfo.stageCount = static_cast<uint32_t>(shaderStages.size());
|
pipelineInfo.stageCount = static_cast<uint32_t>(shaderStages.size());
|
||||||
// pipelineInfo.pStages = shaderStages.data();
|
pipelineInfo.pStages = shaderStages.data();
|
||||||
pipelineInfo.stageCount = 2;
|
|
||||||
pipelineInfo.pStages = shaderStages;
|
|
||||||
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
||||||
pipelineInfo.pInputAssemblyState = &inputAssembly;
|
pipelineInfo.pInputAssemblyState = &inputAssembly;
|
||||||
pipelineInfo.pViewportState = &viewportState;
|
pipelineInfo.pViewportState = &viewportState;
|
||||||
@@ -833,9 +814,6 @@ namespace love {
|
|||||||
if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) {
|
if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) {
|
||||||
throw love::Exception("failed to create graphics pipeline");
|
throw love::Exception("failed to create graphics pipeline");
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDestroyShaderModule(device, vertShaderModule, nullptr);
|
|
||||||
vkDestroyShaderModule(device, fragShaderModule, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::createFramebuffers() {
|
void Graphics::createFramebuffers() {
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ namespace love {
|
|||||||
void createSwapChain();
|
void createSwapChain();
|
||||||
void createImageViews();
|
void createImageViews();
|
||||||
void createRenderPass();
|
void createRenderPass();
|
||||||
|
void createDefaultShaders();
|
||||||
void createGraphicsPipeline();
|
void createGraphicsPipeline();
|
||||||
void createFramebuffers();
|
void createFramebuffers();
|
||||||
void createCommandPool();
|
void createCommandPool();
|
||||||
|
|||||||
Reference in New Issue
Block a user