Fix depth image usage in MSL for separate image/samplers.
This commit is contained in:
parent
702e08671b
commit
a3ae861844
@ -0,0 +1,17 @@
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
fragment main0_out main0(depth2d<float> uDepth [[texture(0)]], texture2d<float> uColor [[texture(1)]], sampler uSamplerShadow [[sampler(0)]], sampler uSampler [[sampler(1)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.FragColor = uDepth.sample_compare(uSamplerShadow, float3(0.5).xy, 0.5) + uColor.sample(uSampler, float2(0.5)).x;
|
||||
return out;
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
float sample_depth_from_function(thread const depth2d<float> uT, thread const sampler uS)
|
||||
{
|
||||
return uT.sample_compare(uS, float3(0.5).xy, float3(0.5).z);
|
||||
}
|
||||
|
||||
float sample_color_from_function(thread const texture2d<float> uT, thread const sampler uS)
|
||||
{
|
||||
return uT.sample(uS, float2(0.5)).x;
|
||||
}
|
||||
|
||||
fragment main0_out main0(depth2d<float> uDepth [[texture(0)]], texture2d<float> uColor [[texture(1)]], sampler uSamplerShadow [[sampler(0)]], sampler uSampler [[sampler(1)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.FragColor = sample_depth_from_function(uDepth, uSamplerShadow) + sample_color_from_function(uColor, uSampler);
|
||||
return out;
|
||||
}
|
||||
|
22
shaders-msl/frag/sample-depth-separate-image-sampler.frag
Normal file
22
shaders-msl/frag/sample-depth-separate-image-sampler.frag
Normal file
@ -0,0 +1,22 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform texture2D uDepth;
|
||||
layout(set = 0, binding = 1) uniform texture2D uColor;
|
||||
layout(set = 0, binding = 2) uniform sampler uSampler;
|
||||
layout(set = 0, binding = 3) uniform samplerShadow uSamplerShadow;
|
||||
layout(location = 0) out float FragColor;
|
||||
|
||||
float sample_depth_from_function(texture2D uT, samplerShadow uS)
|
||||
{
|
||||
return texture(sampler2DShadow(uT, uS), vec3(0.5));
|
||||
}
|
||||
|
||||
float sample_color_from_function(texture2D uT, sampler uS)
|
||||
{
|
||||
return texture(sampler2D(uT, uS), vec2(0.5)).x;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = sample_depth_from_function(uDepth, uSamplerShadow) + sample_color_from_function(uColor, uSampler);
|
||||
}
|
@ -3781,10 +3781,10 @@ bool Compiler::CombinedImageSamplerUsageHandler::begin_function_scope(const uint
|
||||
|
||||
void Compiler::CombinedImageSamplerUsageHandler::add_hierarchy_to_comparison_images(uint32_t image)
|
||||
{
|
||||
// Traverse the variable dependency hierarchy and tag everything in its path with comparison samplers.
|
||||
// Traverse the variable dependency hierarchy and tag everything in its path with comparison images.
|
||||
comparison_images.insert(image);
|
||||
for (auto &img : dependency_hierarchy[image])
|
||||
add_hierarchy_to_comparison_samplers(img);
|
||||
add_hierarchy_to_comparison_images(img);
|
||||
}
|
||||
|
||||
void Compiler::CombinedImageSamplerUsageHandler::add_hierarchy_to_comparison_samplers(uint32_t sampler)
|
||||
|
@ -7419,7 +7419,9 @@ string CompilerGLSL::image_type_glsl(const SPIRType &type, uint32_t /* id */)
|
||||
require_extension("GL_EXT_texture_array");
|
||||
res += "Array";
|
||||
}
|
||||
if (type.image.depth)
|
||||
|
||||
// "Shadow" state in GLSL only exists for samplers and combined image samplers.
|
||||
if (((type.basetype == SPIRType::SampledImage) || (type.basetype == SPIRType::Sampler)) && type.image.depth)
|
||||
res += "Shadow";
|
||||
|
||||
return res;
|
||||
|
@ -3237,8 +3237,9 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
|
||||
|
||||
// Bypass pointers because we need the real image struct
|
||||
auto &img_type = get<SPIRType>(type.self).image;
|
||||
bool shadow_image = comparison_images.count(id) != 0;
|
||||
|
||||
if (img_type.depth)
|
||||
if (img_type.depth || shadow_image)
|
||||
{
|
||||
switch (img_type.dim)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user