Hash :
00d99277
Author :
Date :
2025-03-19T17:22:24
[WGSL] Emit sampler types and texture lookup builtins The split texture/sampler WGSL variables will now have the correct types corresponding to their GLSL types. Texture builtins are translated as faithfully as possible. There are some issues with the translation: 1. Texture builtins using an implicit level-of-detail in a vertex shader are supposed to sample from the base mip level. Right now these are translated into WGSL functions that cannot be used in a vertex shader at all. 2. Some texture builtins that take integer samplers do not have corresponding WGSL versions, e.g. the sampling GLSL function texture() takes integer samplers but the mostly equivalent WGSL builtin, textureSample(), will only take float samplers. 3. A number of GLSL texture builtins are not supported in WGSL when uses on shadow samplers, e.g. anything with a bias parameter, an explicit LOD parameter, or explicit gradients, Bug: angleproject:389145696 Change-Id: Idfd75721f88181db9643235b954629ac477163e4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6372082 Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_TRANSLATOR_WGSL_UTILS_H_
#define COMPILER_TRANSLATOR_WGSL_UTILS_H_
#include "compiler/translator/Common.h"
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/Types.h"
namespace sh
{
// Can be used with TSymbol or TField or TFunc.
template <typename StringStreamType, typename Object>
void WriteNameOf(StringStreamType &output, const Object &namedObject)
{
WriteNameOf(output, namedObject.symbolType(), namedObject.name());
}
template <typename StringStreamType>
void WriteNameOf(StringStreamType &output, SymbolType symbolType, const ImmutableString &name);
enum class WgslAddressSpace
{
Uniform,
NonUniform
};
struct EmitTypeConfig
{
// If `addressSpace` is WgslAddressSpace::Uniform, all arrays with stride not a multiple of 16
// will need a wrapper struct for the array element type that is of size a multiple of 16, if
// the array element type that is not already a struct. This is to satisfy WGSL's uniform
// address space layout constraints.
WgslAddressSpace addressSpace = WgslAddressSpace::NonUniform;
};
template <typename StringStreamType>
void WriteWgslBareTypeName(StringStreamType &output,
const TType &type,
const EmitTypeConfig &config);
template <typename StringStreamType>
void WriteWgslType(StringStreamType &output, const TType &type, const EmitTypeConfig &config);
// GLSL's samplers are split into a separate sampler and texture in WGSL, so two different types
// will be emitted for a single sampler type.
enum class WgslSamplerTypeConfig
{
Sampler,
Texture
};
template <typename StringStreamType>
void WriteWgslSamplerType(StringStreamType &output,
const TType &type,
WgslSamplerTypeConfig samplerType);
// From the type, creates a legal WGSL name for a struct that wraps it.
ImmutableString MakeUniformWrapperStructName(const TType *type);
// Returns true if a `type` in the uniform address space is an array that needs its element type
// wrapped in a struct.
bool ElementTypeNeedsUniformWrapperStruct(bool inUniformAddressSpace, const TType *type);
using GlobalVars = TMap<ImmutableString, TIntermDeclaration *>;
GlobalVars FindGlobalVars(TIntermBlock *root);
} // namespace sh
#endif // COMPILER_TRANSLATOR_WGSL_UTILS_H_