diff --git a/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java b/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java index dd2ee5c8a..f574b8087 100644 --- a/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java +++ b/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java @@ -18,6 +18,7 @@ import net.vulkanmod.vulkan.shader.descriptor.UBO; import net.vulkanmod.vulkan.shader.layout.AlignedStruct; import net.vulkanmod.vulkan.shader.layout.PushConstants; +import net.vulkanmod.vulkan.texture.SamplerManager; import net.vulkanmod.vulkan.texture.VTextureSelector; import net.vulkanmod.vulkan.texture.VulkanImage; import org.apache.commons.lang3.Validate; @@ -100,12 +101,13 @@ protected void createDescriptorSetLayout() { uboLayoutBinding.stageFlags(ubo.getStages()); } + final LongBuffer immutableSampler = stack.longs(SamplerManager.getTextureSampler((byte) 0)); //vertex stage samplers always use nearest Sampling for (ImageDescriptor imageDescriptor : this.imageDescriptors) { VkDescriptorSetLayoutBinding samplerLayoutBinding = bindings.get(imageDescriptor.getBinding()); samplerLayoutBinding.binding(imageDescriptor.getBinding()); samplerLayoutBinding.descriptorCount(1); samplerLayoutBinding.descriptorType(imageDescriptor.getType()); - samplerLayoutBinding.pImmutableSamplers(null); + samplerLayoutBinding.pImmutableSamplers(imageDescriptor.getStages()==VK_SHADER_STAGE_VERTEX_BIT ? immutableSampler : null); samplerLayoutBinding.stageFlags(imageDescriptor.getStages()); } @@ -670,7 +672,7 @@ public static int getStageFromString(String s) { return switch (s) { case "vertex" -> VK_SHADER_STAGE_VERTEX_BIT; case "fragment" -> VK_SHADER_STAGE_FRAGMENT_BIT; - case "all" -> VK_SHADER_STAGE_ALL_GRAPHICS; + case "all" -> VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; //VK_SHADER_STAGE_ALL_GRAPHICS includes tessellation/geometry stages, which are unused case "compute" -> VK_SHADER_STAGE_COMPUTE_BIT; default -> throw new RuntimeException("cannot identify type.."); diff --git a/src/main/java/net/vulkanmod/vulkan/shader/descriptor/ImageDescriptor.java b/src/main/java/net/vulkanmod/vulkan/shader/descriptor/ImageDescriptor.java index 40ad7b070..43cae4b7f 100644 --- a/src/main/java/net/vulkanmod/vulkan/shader/descriptor/ImageDescriptor.java +++ b/src/main/java/net/vulkanmod/vulkan/shader/descriptor/ImageDescriptor.java @@ -1,5 +1,6 @@ package net.vulkanmod.vulkan.shader.descriptor; +import net.vulkanmod.vulkan.shader.Pipeline; import net.vulkanmod.vulkan.texture.VTextureSelector; import net.vulkanmod.vulkan.texture.VulkanImage; @@ -14,6 +15,7 @@ public class ImageDescriptor implements Descriptor { public final int imageIdx; public final boolean isStorageImage; + private final int stage; public boolean useSampler; public boolean isReadOnlyLayout; private int layout; @@ -24,12 +26,19 @@ public ImageDescriptor(int binding, String type, String name, int imageIdx) { } public ImageDescriptor(int binding, String type, String name, int imageIdx, boolean isStorageImage) { + final int stage1 = switch (name) { + case "Sampler0", "DiffuseSampler", "SamplerProj" -> VK_SHADER_STAGE_FRAGMENT_BIT; + case "Sampler1", "Sampler2" -> VK_SHADER_STAGE_VERTEX_BIT; + default -> VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; + }; + this.binding = binding; this.qualifier = type; this.name = name; this.isStorageImage = isStorageImage; this.useSampler = !isStorageImage; this.imageIdx = imageIdx; + this.stage = stage1; descriptorType = isStorageImage ? VK_DESCRIPTOR_TYPE_STORAGE_IMAGE : VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; setLayout(isStorageImage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); @@ -47,7 +56,7 @@ public int getType() { @Override public int getStages() { - return VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_COMPUTE_BIT; + return stage; } public void setLayout(int layout) { diff --git a/src/main/java/net/vulkanmod/vulkan/texture/VTextureSelector.java b/src/main/java/net/vulkanmod/vulkan/texture/VTextureSelector.java index 0b3903d7f..2c7ac86bb 100644 --- a/src/main/java/net/vulkanmod/vulkan/texture/VTextureSelector.java +++ b/src/main/java/net/vulkanmod/vulkan/texture/VTextureSelector.java @@ -56,7 +56,7 @@ public static void uploadSubTexture(int mipLevel, int width, int height, int xOf public static int getTextureIdx(String name) { return switch (name) { case "Sampler0", "DiffuseSampler" -> 0; - case "Sampler1" -> 1; + case "Sampler1", "SamplerProj" -> 1; case "Sampler2" -> 2; case "Sampler3" -> 3; case "Sampler4" -> 4; diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_end_portal/rendertype_end_portal.json b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_end_portal/rendertype_end_portal.json index 8854d96e4..6a971c82b 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_end_portal/rendertype_end_portal.json +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_end_portal/rendertype_end_portal.json @@ -9,7 +9,7 @@ "attributes": [], "samplers": [ { "name": "Sampler0" }, - { "name": "Sampler1" } + { "name": "SamplerProj" } ], "uniforms": [ { "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] },