Skip to content

Commit

Permalink
Refactor _Texture to constrain on texel types. (#6115)
Browse files Browse the repository at this point in the history
* Refactor _Texture to constrain on texel types.

* Fix tests.

* Fix.

* Disable glsl texture test because rhi can't run it correctly.
  • Loading branch information
csyonghe authored Jan 17, 2025
1 parent 3ff2578 commit fc77070
Show file tree
Hide file tree
Showing 16 changed files with 1,109 additions and 1,005 deletions.
513 changes: 258 additions & 255 deletions source/slang/glsl.meta.slang

Large diffs are not rendered by default.

298 changes: 193 additions & 105 deletions source/slang/hlsl.meta.slang

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions source/slang/slang-check-inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,10 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
info.facets = FacetList(directFacet);
return info;
}
else if (auto modifiedType = as<ModifiedType>(type))
{
return _calcInheritanceInfo(modifiedType->getBase(), circularityInfo);
}
else
{
// As a fallback, any type not covered by the above cases will
Expand Down
5 changes: 4 additions & 1 deletion source/slang/slang-emit-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,10 @@ void CPPSourceEmitter::emitGlobalRTTISymbolPrefix()

void CPPSourceEmitter::emitWitnessTable(IRWitnessTable* witnessTable)
{
auto interfaceType = cast<IRInterfaceType>(witnessTable->getConformanceType());
auto interfaceType = as<IRInterfaceType>(witnessTable->getConformanceType());

if (!interfaceType)
return;

// Ignore witness tables for builtin interface types.
if (isBuiltin(interfaceType))
Expand Down
2 changes: 2 additions & 0 deletions source/slang/slang-ir-peephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ struct PeepholeContext : InstPassBase
case kIROp_VectorReshape:
{
auto fromType = as<IRVectorType>(inst->getOperand(0)->getDataType());
if (!fromType)
break;
auto resultType = as<IRVectorType>(inst->getDataType());
if (!resultType)
{
Expand Down
7 changes: 7 additions & 0 deletions tests/diagnostics/illegal-texel-type.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv

// CHECK: ([[# @LINE+1]]): error 38029
Texture2D<float4x4> t1;

// CHECK: ([[# @LINE+1]]): error 38029
RWBuffer<Sampler1D> t2;
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ buffer MyBlockName

uniform sampler1D uniform_sampler1D;

__generic<T : __BuiltinFloatingPointType, let N : int>
bool textureFuncs(Sampler1D<vector<T,N>> gsampler1D)
__generic<T : ITexelElement>
bool textureFuncs(Sampler1D<T> gsampler1D)
{
typealias gvec4 = vector<T,4>;
typealias gvec4 = vector<T.Element,4>;

constexpr ivec2 ivec2_0 = ivec2(0);

Expand All @@ -61,32 +61,32 @@ bool textureFuncs(Sampler1D<vector<T,N>> gsampler1D)
&& int(0) == textureSize(gsampler1D, int(0))
&& vec2(0) == textureQueryLod(gsampler1D, float(0))
&& int(0) == textureQueryLevels(gsampler1D)
&& gvec4(T(0)) == texture(gsampler1D, float(0))
&& gvec4(T(0)) == texture(gsampler1D, float(0), float(0))
&& gvec4(T(0)) == textureProj(gsampler1D, vec2(0))
&& gvec4(T(0)) == textureProj(gsampler1D, vec2(0), float(0))
&& gvec4(T(0)) == textureProj(gsampler1D, vec4(0))
&& gvec4(T(0)) == textureProj(gsampler1D, vec4(0), float(0))
&& gvec4(T(0)) == textureLod(gsampler1D, float(0), float(0))
&& gvec4(T(0)) == textureOffset(gsampler1D, float(0), __LINE__)
&& gvec4(T(0)) == textureOffset(gsampler1D, float(0), __LINE__, float(0))
&& gvec4(T(0)) == texelFetch(gsampler1D, int(0), int(0))
&& gvec4(T(0)) == texelFetchOffset(gsampler1D, int(0), int(0), __LINE__)
&& gvec4(T(0)) == textureProjOffset(gsampler1D, vec2(0), __LINE__)
&& gvec4(T(0)) == textureProjOffset(gsampler1D, vec2(0), __LINE__, float(0))
&& gvec4(T(0)) == textureProjOffset(gsampler1D, vec4(0), __LINE__)
&& gvec4(T(0)) == textureProjOffset(gsampler1D, vec4(0), __LINE__,float(0))
&& gvec4(T(0)) == textureLodOffset(gsampler1D, float(0), float(0), __LINE__)
&& gvec4(T(0)) == textureProjLod(gsampler1D, vec2(0), float(0))
&& gvec4(T(0)) == textureProjLod(gsampler1D, vec4(0), float(0))
&& gvec4(T(0)) == textureProjLodOffset(gsampler1D, vec2(0), float(0), __LINE__)
&& gvec4(T(0)) == textureProjLodOffset(gsampler1D, vec4(0), float(0), __LINE__)
&& gvec4(T(0)) == textureGrad(gsampler1D, float(0), float(0), float(0))
&& gvec4(T(0)) == textureGradOffset(gsampler1D, float(0), float(0), float(0), __LINE__)
&& gvec4(T(0)) == textureProjGrad(gsampler1D, vec2(0), float(0), float(0))
&& gvec4(T(0)) == textureProjGrad(gsampler1D, vec4(0), float(0), float(0))
&& gvec4(T(0)) == textureProjGradOffset(gsampler1D, vec2(0), float(0), float(0), __LINE__)
&& gvec4(T(0)) == textureProjGradOffset(gsampler1D, vec4(0), float(0), float(0), __LINE__)
&& gvec4(T.Element(0)) == texture(gsampler1D, float(0))
&& gvec4(T.Element(0)) == texture(gsampler1D, float(0), float(0))
&& gvec4(T.Element(0)) == textureProj(gsampler1D, vec2(0))
&& gvec4(T.Element(0)) == textureProj(gsampler1D, vec2(0), float(0))
&& gvec4(T.Element(0)) == textureProj(gsampler1D, vec4(0))
&& gvec4(T.Element(0)) == textureProj(gsampler1D, vec4(0), float(0))
&& gvec4(T.Element(0)) == textureLod(gsampler1D, float(0), float(0))
&& gvec4(T.Element(0)) == textureOffset(gsampler1D, float(0), __LINE__)
&& gvec4(T.Element(0)) == textureOffset(gsampler1D, float(0), __LINE__, float(0))
&& gvec4(T.Element(0)) == texelFetch(gsampler1D, int(0), int(0))
&& gvec4(T.Element(0)) == texelFetchOffset(gsampler1D, int(0), int(0), __LINE__)
&& gvec4(T.Element(0)) == textureProjOffset(gsampler1D, vec2(0), __LINE__)
&& gvec4(T.Element(0)) == textureProjOffset(gsampler1D, vec2(0), __LINE__, float(0))
&& gvec4(T.Element(0)) == textureProjOffset(gsampler1D, vec4(0), __LINE__)
&& gvec4(T.Element(0)) == textureProjOffset(gsampler1D, vec4(0), __LINE__,float(0))
&& gvec4(T.Element(0)) == textureLodOffset(gsampler1D, float(0), float(0), __LINE__)
&& gvec4(T.Element(0)) == textureProjLod(gsampler1D, vec2(0), float(0))
&& gvec4(T.Element(0)) == textureProjLod(gsampler1D, vec4(0), float(0))
&& gvec4(T.Element(0)) == textureProjLodOffset(gsampler1D, vec2(0), float(0), __LINE__)
&& gvec4(T.Element(0)) == textureProjLodOffset(gsampler1D, vec4(0), float(0), __LINE__)
&& gvec4(T.Element(0)) == textureGrad(gsampler1D, float(0), float(0), float(0))
&& gvec4(T.Element(0)) == textureGradOffset(gsampler1D, float(0), float(0), float(0), __LINE__)
&& gvec4(T.Element(0)) == textureProjGrad(gsampler1D, vec2(0), float(0), float(0))
&& gvec4(T.Element(0)) == textureProjGrad(gsampler1D, vec4(0), float(0), float(0))
&& gvec4(T.Element(0)) == textureProjGradOffset(gsampler1D, vec2(0), float(0), float(0), __LINE__)
&& gvec4(T.Element(0)) == textureProjGradOffset(gsampler1D, vec4(0), float(0), float(0), __LINE__)
&& vec4(0) == texture1D(uniform_sampler1D, float(0))
&& vec4(0) == texture1D(uniform_sampler1D, float(0), float(0))
&& vec4(0) == texture1DProj(uniform_sampler1D, vec2(0))
Expand Down
Loading

0 comments on commit fc77070

Please sign in to comment.