diff --git a/util/test/demos/vk/vk_descriptor_index.cpp b/util/test/demos/vk/vk_descriptor_index.cpp index 01ace54a1..07a250ba2 100644 --- a/util/test/demos/vk/vk_descriptor_index.cpp +++ b/util/test/demos/vk/vk_descriptor_index.cpp @@ -107,8 +107,12 @@ layout(binding = 0, std430) buffer outbuftype { layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; +layout(constant_id = 1) const int spec_canary = 0; + void main() { + if(spec_canary != 1337) return; + outbuf[push.bufidx].outrefs[0].binding = 0; outbuf[push.bufidx].outrefs[0].idx = push.idx1; outbuf[push.bufidx].outrefs[1].binding = 2; @@ -189,8 +193,12 @@ void add_parameterless() Color += 0.1f * texture(tex1[)EOSHADER" STRINGIZE(INDEX3) R"EOSHADER(], vertIn.uv.xy); } +layout(constant_id = 2) const int spec_canary = 0; + void main() { + if(spec_canary != 1338) { Color = vec4(1.0, 0.0, 0.0, 1.0); return; } + if(vertIn.uv.y < 0.2f) { // nonuniform dynamic index @@ -334,10 +342,27 @@ void main() CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; + VkPipelineShaderStageCreateInfo compshad = + CompileShaderModule(comp, ShaderLang::glsl, ShaderStage::comp, "main"); + + VkSpecializationMapEntry specmap[2] = { + {1, 0 * sizeof(uint32_t), sizeof(uint32_t)}, {2, 1 * sizeof(uint32_t), sizeof(uint32_t)}, + }; + + uint32_t specvals[2] = {1337, 1338}; + + VkSpecializationInfo spec = {}; + spec.mapEntryCount = ARRAY_COUNT(specmap); + spec.pMapEntries = specmap; + spec.dataSize = sizeof(specvals); + spec.pData = specvals; + + pipeCreateInfo.stages[1].pSpecializationInfo = &spec; + compshad.pSpecializationInfo = &spec; + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); - VkPipeline comppipe = createComputePipeline(vkh::ComputePipelineCreateInfo( - layout, CompileShaderModule(comp, ShaderLang::glsl, ShaderStage::comp, "main"))); + VkPipeline comppipe = createComputePipeline(vkh::ComputePipelineCreateInfo(layout, compshad)); float left = float(NONUNIFORMIDX - 1.0f); float middle = float(NONUNIFORMIDX); diff --git a/util/test/demos/vk/vk_mesh_zoo.cpp b/util/test/demos/vk/vk_mesh_zoo.cpp index 3ade7dc77..86219815e 100644 --- a/util/test/demos/vk/vk_mesh_zoo.cpp +++ b/util/test/demos/vk/vk_mesh_zoo.cpp @@ -43,8 +43,21 @@ layout(push_constant, std140) uniform pushbuf layout(location = 0) out vec2 vertOutCol2; layout(location = 1) out vec4 vertOutcol; +layout(constant_id = 1) const int spec_canary = 0; + void main() { + if(spec_canary != 1337) + { + gl_Position = vec4(-1, -1, -1, 1); + vertOutcol = vec4(0, 0, 0, 0); + vertOutCol2 = vec2(0, 0); +#if defined(USE_POINTS) + gl_PointSize = 0.0f; +#endif + return; + } + vec4 pos = vec4(Position.xy * scale.xy + offset.xy, Position.z, 1.0f); vertOutcol = Color; @@ -179,10 +192,25 @@ void main() pipeCreateInfo.depthStencilState.stencilTestEnable = VK_FALSE; pipeCreateInfo.depthStencilState.back = pipeCreateInfo.depthStencilState.front; + VkSpecializationMapEntry specmap[1] = { + {1, 0 * sizeof(uint32_t), sizeof(uint32_t)}, + }; + + uint32_t specvals[1] = {1337}; + + VkSpecializationInfo spec = {}; + spec.mapEntryCount = ARRAY_COUNT(specmap); + spec.pMapEntries = specmap; + spec.dataSize = sizeof(specvals); + spec.pData = specvals; + + pipeCreateInfo.stages[0].pSpecializationInfo = &spec; + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); pipeCreateInfo.stages[0] = CompileShaderModule(vertex, ShaderLang::glsl, ShaderStage::vert, "main", {std::make_pair("USE_POINTS", "1")}), + pipeCreateInfo.stages[0].pSpecializationInfo = &spec; pipeCreateInfo.inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; VkPipeline pointspipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_overlay_test.cpp b/util/test/demos/vk/vk_overlay_test.cpp index 1be54b4d9..fb9b7d8f1 100644 --- a/util/test/demos/vk/vk_overlay_test.cpp +++ b/util/test/demos/vk/vk_overlay_test.cpp @@ -50,8 +50,18 @@ layout(location = 2) in vec2 UV; layout(location = 0) out v2f vertOut; +layout(constant_id = 1) const int spec_canary = 0; + void main() { + if(spec_canary != 1337) + { + gl_Position = vertOut.pos = vec4(-1, -1, -1, 1); + vertOut.col = vec4(0, 0, 0, 0); + vertOut.uv = vec4(0, 0, 0, 0); + return; + } + vertOut.pos = vec4(Position.xyz, 1); gl_Position = vertOut.pos; vertOut.col = Color; @@ -66,8 +76,12 @@ layout(location = 0) in v2f vertIn; layout(location = 0, index = 0) out vec4 Color; +layout(constant_id = 2) const int spec_canary = 0; + void main() { + if(spec_canary != 1338) { Color = vec4(1.0, 0.0, 0.0, 1.0); return; } + Color = vertIn.col; } @@ -78,8 +92,12 @@ void main() layout(location = 0, index = 0) out vec4 Color; +layout(constant_id = 2) const int spec_canary = 0; + void main() { + if(spec_canary != 1338) { Color = vec4(1.0, 0.0, 0.0, 1.0); return; } + Color = vec4(1,1,1,1); } @@ -240,6 +258,21 @@ void main() CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; + VkSpecializationMapEntry specmap[2] = { + {1, 0 * sizeof(uint32_t), sizeof(uint32_t)}, {2, 1 * sizeof(uint32_t), sizeof(uint32_t)}, + }; + + uint32_t specvals[2] = {1337, 1338}; + + VkSpecializationInfo spec = {}; + spec.mapEntryCount = ARRAY_COUNT(specmap); + spec.pMapEntries = specmap; + spec.dataSize = sizeof(specvals); + spec.pData = specvals; + + pipeCreateInfo.stages[0].pSpecializationInfo = &spec; + pipeCreateInfo.stages[1].pSpecializationInfo = &spec; + pipeCreateInfo.rasterizationState.depthClampEnable = VK_FALSE; pipeCreateInfo.rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT; @@ -293,6 +326,7 @@ void main() pipeCreateInfo.stages[1] = CompileShaderModule(whitepixel, ShaderLang::glsl, ShaderStage::frag, "main"); + pipeCreateInfo.stages[1].pSpecializationInfo = &spec; pipeCreateInfo.multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; pipeCreateInfo.renderPass = subrp; pipeCreateInfo.depthStencilState.stencilTestEnable = VK_FALSE; diff --git a/util/test/demos/vk/vk_shader_editing.cpp b/util/test/demos/vk/vk_shader_editing.cpp index 0a6ee9bff..3336d4e48 100644 --- a/util/test/demos/vk/vk_shader_editing.cpp +++ b/util/test/demos/vk/vk_shader_editing.cpp @@ -46,8 +46,12 @@ void main() layout(location = 0, index = 0) out vec4 Color; +layout(constant_id = 1) const int spec_canary = 0; + void main() { + if(spec_canary != 1337) { Color = vec4(0.2, 0.0, 0.2, 1.0); return; } + #if 1 Color = vec4(0.0, 1.0, 0.0, 1.0); #else @@ -104,11 +108,26 @@ void main() CompileShaderModule(pixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; + VkSpecializationMapEntry specmap[1] = { + {1, 0 * sizeof(uint32_t), sizeof(uint32_t)}, + }; + + uint32_t specvals[1] = {1337}; + + VkSpecializationInfo spec = {}; + spec.mapEntryCount = ARRAY_COUNT(specmap); + spec.pMapEntries = specmap; + spec.dataSize = sizeof(specvals); + spec.pData = specvals; + + pipeCreateInfo.stages[1].pSpecializationInfo = &spec; + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); // use the same source but make a distinct shader module so we can edit it separately pipeCreateInfo.stages[1] = CompileShaderModule(pixel, ShaderLang::glsl, ShaderStage::frag, "main"); + pipeCreateInfo.stages[1].pSpecializationInfo = &spec; VkPipeline pipe2 = createGraphicsPipeline(pipeCreateInfo);