Add samples ImmutableSampler, InitTexture, InputAttachment (#315)
+ slightly adjust some other samples.
This commit is contained in:
committed by
Markus Tavenrath
parent
d4ddb0a2cd
commit
d965a74cc0
@@ -19,6 +19,13 @@ struct VertexPC
|
||||
float r, g, b, a; // Color
|
||||
};
|
||||
|
||||
struct VertexPT
|
||||
{
|
||||
float x, y, z, w; // Position data
|
||||
float u, v; // texture u,v
|
||||
};
|
||||
|
||||
|
||||
static const VertexPC coloredCubeData[] =
|
||||
{
|
||||
// red face
|
||||
@@ -65,3 +72,49 @@ static const VertexPC coloredCubeData[] =
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f },
|
||||
};
|
||||
|
||||
static const VertexPT texturedCubeData[] =
|
||||
{
|
||||
// left face
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f },
|
||||
// front face
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f },
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f },
|
||||
{ -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f },
|
||||
// top face
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f },
|
||||
{ -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f },
|
||||
// bottom face
|
||||
{ -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
{ -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
// right face
|
||||
{ 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
{ 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f },
|
||||
// back face
|
||||
{ -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f },
|
||||
{ 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f },
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "shaders.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "glslang/StandAlone/ResourceLimits.h"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
|
||||
namespace vk
|
||||
@@ -38,102 +39,6 @@ namespace vk
|
||||
}
|
||||
}
|
||||
|
||||
void init(TBuiltInResource & resource)
|
||||
{
|
||||
resource.maxLights = 32;
|
||||
resource.maxClipPlanes = 6;
|
||||
resource.maxTextureUnits = 32;
|
||||
resource.maxTextureCoords = 32;
|
||||
resource.maxVertexAttribs = 64;
|
||||
resource.maxVertexUniformComponents = 4096;
|
||||
resource.maxVaryingFloats = 64;
|
||||
resource.maxVertexTextureImageUnits = 32;
|
||||
resource.maxCombinedTextureImageUnits = 80;
|
||||
resource.maxTextureImageUnits = 32;
|
||||
resource.maxFragmentUniformComponents = 4096;
|
||||
resource.maxDrawBuffers = 32;
|
||||
resource.maxVertexUniformVectors = 128;
|
||||
resource.maxVaryingVectors = 8;
|
||||
resource.maxFragmentUniformVectors = 16;
|
||||
resource.maxVertexOutputVectors = 16;
|
||||
resource.maxFragmentInputVectors = 15;
|
||||
resource.minProgramTexelOffset = -8;
|
||||
resource.maxProgramTexelOffset = 7;
|
||||
resource.maxClipDistances = 8;
|
||||
resource.maxComputeWorkGroupCountX = 65535;
|
||||
resource.maxComputeWorkGroupCountY = 65535;
|
||||
resource.maxComputeWorkGroupCountZ = 65535;
|
||||
resource.maxComputeWorkGroupSizeX = 1024;
|
||||
resource.maxComputeWorkGroupSizeY = 1024;
|
||||
resource.maxComputeWorkGroupSizeZ = 64;
|
||||
resource.maxComputeUniformComponents = 1024;
|
||||
resource.maxComputeTextureImageUnits = 16;
|
||||
resource.maxComputeImageUniforms = 8;
|
||||
resource.maxComputeAtomicCounters = 8;
|
||||
resource.maxComputeAtomicCounterBuffers = 1;
|
||||
resource.maxVaryingComponents = 60;
|
||||
resource.maxVertexOutputComponents = 64;
|
||||
resource.maxGeometryInputComponents = 64;
|
||||
resource.maxGeometryOutputComponents = 128;
|
||||
resource.maxFragmentInputComponents = 128;
|
||||
resource.maxImageUnits = 8;
|
||||
resource.maxCombinedImageUnitsAndFragmentOutputs = 8;
|
||||
resource.maxCombinedShaderOutputResources = 8;
|
||||
resource.maxImageSamples = 0;
|
||||
resource.maxVertexImageUniforms = 0;
|
||||
resource.maxTessControlImageUniforms = 0;
|
||||
resource.maxTessEvaluationImageUniforms = 0;
|
||||
resource.maxGeometryImageUniforms = 0;
|
||||
resource.maxFragmentImageUniforms = 8;
|
||||
resource.maxCombinedImageUniforms = 8;
|
||||
resource.maxGeometryTextureImageUnits = 16;
|
||||
resource.maxGeometryOutputVertices = 256;
|
||||
resource.maxGeometryTotalOutputComponents = 1024;
|
||||
resource.maxGeometryUniformComponents = 1024;
|
||||
resource.maxGeometryVaryingComponents = 64;
|
||||
resource.maxTessControlInputComponents = 128;
|
||||
resource.maxTessControlOutputComponents = 128;
|
||||
resource.maxTessControlTextureImageUnits = 16;
|
||||
resource.maxTessControlUniformComponents = 1024;
|
||||
resource.maxTessControlTotalOutputComponents = 4096;
|
||||
resource.maxTessEvaluationInputComponents = 128;
|
||||
resource.maxTessEvaluationOutputComponents = 128;
|
||||
resource.maxTessEvaluationTextureImageUnits = 16;
|
||||
resource.maxTessEvaluationUniformComponents = 1024;
|
||||
resource.maxTessPatchComponents = 120;
|
||||
resource.maxPatchVertices = 32;
|
||||
resource.maxTessGenLevel = 64;
|
||||
resource.maxViewports = 16;
|
||||
resource.maxVertexAtomicCounters = 0;
|
||||
resource.maxTessControlAtomicCounters = 0;
|
||||
resource.maxTessEvaluationAtomicCounters = 0;
|
||||
resource.maxGeometryAtomicCounters = 0;
|
||||
resource.maxFragmentAtomicCounters = 8;
|
||||
resource.maxCombinedAtomicCounters = 8;
|
||||
resource.maxAtomicCounterBindings = 1;
|
||||
resource.maxVertexAtomicCounterBuffers = 0;
|
||||
resource.maxTessControlAtomicCounterBuffers = 0;
|
||||
resource.maxTessEvaluationAtomicCounterBuffers = 0;
|
||||
resource.maxGeometryAtomicCounterBuffers = 0;
|
||||
resource.maxFragmentAtomicCounterBuffers = 1;
|
||||
resource.maxCombinedAtomicCounterBuffers = 1;
|
||||
resource.maxAtomicCounterBufferSize = 16384;
|
||||
resource.maxTransformFeedbackBuffers = 4;
|
||||
resource.maxTransformFeedbackInterleavedComponents = 64;
|
||||
resource.maxCullDistances = 8;
|
||||
resource.maxCombinedClipAndCullDistances = 8;
|
||||
resource.maxSamples = 4;
|
||||
resource.limits.nonInductiveForLoops = 1;
|
||||
resource.limits.whileLoops = 1;
|
||||
resource.limits.doWhileLoops = 1;
|
||||
resource.limits.generalUniformIndexing = 1;
|
||||
resource.limits.generalAttributeMatrixVectorIndexing = 1;
|
||||
resource.limits.generalVaryingIndexing = 1;
|
||||
resource.limits.generalSamplerIndexing = 1;
|
||||
resource.limits.generalVariableIndexing = 1;
|
||||
resource.limits.generalConstantMatrixVectorIndexing = 1;
|
||||
}
|
||||
|
||||
bool GLSLtoSPV(const vk::ShaderStageFlagBits shaderType, std::string const& glslShader, std::vector<unsigned int> &spvShader)
|
||||
{
|
||||
EShLanguage stage = translateShaderStage(shaderType);
|
||||
@@ -144,13 +49,10 @@ namespace vk
|
||||
glslang::TShader shader(stage);
|
||||
shader.setStrings(shaderStrings, 1);
|
||||
|
||||
TBuiltInResource resource;
|
||||
init(resource);
|
||||
|
||||
// Enable SPIR-V and Vulkan rules when parsing GLSL
|
||||
EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
|
||||
|
||||
if (!shader.parse(&resource, 100, false, messages))
|
||||
if (!shader.parse(&glslang::DefaultTBuiltInResource, 100, false, messages))
|
||||
{
|
||||
puts(shader.getInfoLog());
|
||||
puts(shader.getInfoDebugLog());
|
||||
|
||||
@@ -52,6 +52,31 @@ void main()
|
||||
}
|
||||
)";
|
||||
|
||||
// vertex shader with (P)osition and (T)exCoord in and (T)exCoord out
|
||||
const std::string vertexShaderText_PT_T = R"(
|
||||
#version 400
|
||||
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
#extension GL_ARB_shading_language_420pack : enable
|
||||
|
||||
layout (std140, binding = 0) uniform buffer
|
||||
{
|
||||
mat4 mvp;
|
||||
} uniformBuffer;
|
||||
|
||||
layout (location = 0) in vec4 pos;
|
||||
layout (location = 1) in vec2 inTexCoord;
|
||||
|
||||
layout (location = 0) out vec2 outTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
outTexCoord = inTexCoord;
|
||||
gl_Position = uniformBuffer.mvp * pos;
|
||||
}
|
||||
)";
|
||||
|
||||
|
||||
// fragment shader with (C)olor in and (C)olor out
|
||||
const std::string fragmentShaderText_C_C = R"(
|
||||
#version 400
|
||||
@@ -69,3 +94,22 @@ void main()
|
||||
}
|
||||
)";
|
||||
|
||||
// fragment shader with (T)exCoord in and (C)olor out
|
||||
const std::string fragmentShaderText_T_C = R"(
|
||||
#version 400
|
||||
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
#extension GL_ARB_shading_language_420pack : enable
|
||||
|
||||
layout (binding = 1) uniform sampler2D tex;
|
||||
|
||||
layout (location = 0) in vec2 inTexCoord;
|
||||
|
||||
layout (location = 0) out vec4 outColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = texture(tex, inTexCoord);
|
||||
}
|
||||
)";
|
||||
|
||||
|
||||
@@ -130,13 +130,20 @@ namespace vk
|
||||
vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main")
|
||||
};
|
||||
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription(0, vertexStride);
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo;
|
||||
if (0 < vertexStride)
|
||||
{
|
||||
vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32A32Sfloat, 0),
|
||||
vk::VertexInputAttributeDescription(1, 0, vk::Format::eR32G32B32A32Sfloat, 16)
|
||||
};
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(vk::PipelineVertexInputStateCreateFlags(), 1, &vertexInputBindingDescription, 2, vertexInputAttributeDescriptions);
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription(0, vertexStride);
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
|
||||
{
|
||||
vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32A32Sfloat, 0),
|
||||
vk::VertexInputAttributeDescription(1, 0, vk::Format::eR32G32B32A32Sfloat, 16)
|
||||
};
|
||||
pipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = 1;
|
||||
pipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = &vertexInputBindingDescription;
|
||||
pipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = 2;
|
||||
pipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = vertexInputAttributeDescriptions;
|
||||
}
|
||||
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user