Repository navigation
|
Hi all, Is there a way to create a Sampler2D from a Texture2D and a SamplerState for Vulkan? Thanks. |
Replies: 1 comment
|
There is no public constructor for it. With slangc 2026.19, For Vulkan you usually don't need one, because sampling the separate objects already builds the combined image in SPIR-V. If you really need a [[vk::binding(0)]] Texture2D tex;
[[vk::binding(1)]] SamplerState samp;
[[vk::binding(2)]] RWStructuredBuffer<float4> outBuf;
float4 useCombined(Sampler2D s, float2 uv) { return s.SampleLevel(uv, 0); }
[shader("compute")][numthreads(1,1,1)]
void main(uint3 id : SV_DispatchThreadID)
{
float2 uv = float2(0.5, 0.5);
outBuf[0] = tex.SampleLevel(samp, uv, 0);
Sampler2D combined = __makeCombinedTextureSampler(tex, samp);
outBuf[1] = useCombined(combined, uv);
}
Keep in mind it is a double underscore internal, not documented API, and it only works for SPIR-V. The same file fails on |
There is no public constructor for it. With slangc 2026.19,
Sampler2D combined = Sampler2D(tex, samp);fails witherror[E39999]: could not specialize generic for arguments of type (Texture2D<vector<float,4>>, SamplerState).For Vulkan you usually don't need one, because sampling the separate objects already builds the combined image in SPIR-V.
tex.Sample(samp, uv)/tex.SampleLevel(samp, uv, 0)go through__makeCombinedTextureSampler(this, s)on the spirv path (hlsl.meta.slang#L2421) and emitOpSampledImage.If you really need a
Sampler2Dvalue, for example to pass to a function that takes one, that internal helper (#L2374-L2380) can be called directly: