@@ -529,13 +529,14 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
529
529
530
530
[__readNone]
531
531
[ForceInline]
532
- [require(glsl_hlsl_spirv , texture_querylod)]
532
+ [require(glsl_hlsl_metal_spirv , texture_querylod)]
533
533
float CalculateLevelOfDetail(TextureCoord location)
534
534
{
535
535
__requireComputeDerivative();
536
536
__target_switch
537
537
{
538
538
case hlsl:
539
+ case metal:
539
540
{
540
541
return __getTexture().CalculateLevelOfDetail(__getSampler(), location);
541
542
}
@@ -551,13 +552,14 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
551
552
552
553
[__readNone]
553
554
[ForceInline]
554
- [require(glsl_hlsl_spirv , texture_querylod)]
555
+ [require(glsl_hlsl_metal_spirv , texture_querylod)]
555
556
float CalculateLevelOfDetailUnclamped(TextureCoord location)
556
557
{
557
558
__requireComputeDerivative();
558
559
__target_switch
559
560
{
560
561
case hlsl:
562
+ case metal:
561
563
{
562
564
return __getTexture().CalculateLevelOfDetailUnclamped(__getSampler(), location);
563
565
}
@@ -573,14 +575,15 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
573
575
574
576
[__readNone]
575
577
[ForceInline]
576
- [require(cpp_cuda_glsl_hlsl_spirv , texture_sm_4_1_fragment)]
578
+ [require(cpp_cuda_glsl_hlsl_metal_spirv , texture_sm_4_1_fragment)]
577
579
T Sample(vector<float, Shape.dimensions+isArray> location)
578
580
{
579
581
__requireComputeDerivative();
580
582
__target_switch
581
583
{
582
584
case cpp:
583
585
case hlsl:
586
+ case metal:
584
587
return __getTexture().Sample(__getSampler(), location);
585
588
case glsl:
586
589
__intrinsic_asm "$ctexture($0, $1)$z";
@@ -622,17 +625,42 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
622
625
}
623
626
}
624
627
628
+ [__readNone]
629
+ [ForceInline]
630
+ [require(cpp_glsl_hlsl_metal_spirv, texture_sm_4_1_fragment)]
631
+ T Sample(vector<float, Shape.dimensions+isArray> location, constexpr vector<int, Shape.planeDimensions> offset)
632
+ {
633
+ __requireComputeDerivative();
634
+ __target_switch
635
+ {
636
+ case cpp:
637
+ case hlsl:
638
+ case metal:
639
+ return __getTexture().Sample(__getSampler(), location, offset);
640
+ case glsl:
641
+ __intrinsic_asm "$ctextureOffsetClampARB($0, $1, $2)$z";
642
+ case spirv:
643
+ return spirv_asm
644
+ {
645
+ OpCapability MinLod;
646
+ %sampled : __sampledType(T) = OpImageSampleImplicitLod $this $location None|ConstOffset $offset;
647
+ __truncate $$T result __sampledType(T) %sampled;
648
+ };
649
+ }
650
+ }
651
+
625
652
[__readNone]
626
653
[ForceInline]
627
654
__glsl_extension(GL_ARB_sparse_texture_clamp)
628
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1_fragment)]
655
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1_fragment)]
629
656
T Sample(vector<float, Shape.dimensions+isArray> location, vector<int, Shape.planeDimensions> offset, float clamp)
630
657
{
631
658
__requireComputeDerivative();
632
659
__target_switch
633
660
{
634
661
case cpp:
635
662
case hlsl:
663
+ case metal:
636
664
return __getTexture().Sample(__getSampler(), location, offset, clamp);
637
665
case glsl:
638
666
__intrinsic_asm "$ctextureOffsetClampARB($0, $1, $2, $3)$z";
@@ -648,7 +676,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
648
676
649
677
[__readNone]
650
678
[ForceInline]
651
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1_fragment)]
679
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1_fragment)]
652
680
T Sample(vector<float, Shape.dimensions+isArray> location, vector<int, Shape.planeDimensions> offset, float clamp, out uint status)
653
681
{
654
682
__target_switch
@@ -662,14 +690,15 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
662
690
663
691
[__readNone]
664
692
[ForceInline]
665
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1_fragment)]
693
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1_fragment)]
666
694
T SampleBias(vector<float, Shape.dimensions+isArray> location, float bias)
667
695
{
668
696
__requireComputeDerivative();
669
697
__target_switch
670
698
{
671
699
case cpp:
672
700
case hlsl:
701
+ case metal:
673
702
return __getTexture().SampleBias(__getSampler(), location, bias);
674
703
case glsl:
675
704
__intrinsic_asm "$ctexture($0, $1, $2)$z";
@@ -685,14 +714,15 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
685
714
686
715
[__readNone]
687
716
[ForceInline]
688
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1_fragment)]
717
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1_fragment)]
689
718
T SampleBias(vector<float, Shape.dimensions+isArray> location, float bias, constexpr vector<int, Shape.planeDimensions> offset)
690
719
{
691
720
__requireComputeDerivative();
692
721
__target_switch
693
722
{
694
723
case cpp:
695
724
case hlsl:
725
+ case metal:
696
726
return __getTexture().SampleBias(__getSampler(), location, bias, offset);
697
727
case glsl:
698
728
__intrinsic_asm "$ctextureOffset($0, $1, $3, $2)$z";
@@ -707,7 +737,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
707
737
708
738
[__readNone]
709
739
[ForceInline]
710
- [require(glsl_hlsl_spirv , texture_shadowlod)]
740
+ [require(glsl_hlsl_metal_spirv , texture_shadowlod)]
711
741
float SampleCmp(vector<float, Shape.dimensions+isArray> location, float compareValue)
712
742
{
713
743
__target_switch
@@ -726,6 +756,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
726
756
return __glsl_texture(this, __makeVector(location, compareValue));
727
757
}
728
758
case hlsl:
759
+ case metal:
729
760
return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue);
730
761
case spirv:
731
762
return spirv_asm
@@ -737,7 +768,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
737
768
738
769
[__readNone]
739
770
[ForceInline]
740
- [require(glsl_hlsl_spirv , texture_shadowlod)]
771
+ [require(glsl_hlsl_metal_spirv , texture_shadowlod)]
741
772
float SampleCmpLevelZero(vector<float, Shape.dimensions+isArray> location, float compareValue)
742
773
{
743
774
__target_switch
@@ -752,6 +783,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
752
783
return __glsl_texture_level_zero(this, __makeVector(location, compareValue));
753
784
}
754
785
case hlsl:
786
+ case metal:
755
787
return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue);
756
788
case spirv:
757
789
const float zeroFloat = 0.0f;
@@ -764,7 +796,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
764
796
765
797
[__readNone]
766
798
[ForceInline]
767
- [require(glsl_hlsl_spirv , texture_shadowlod)]
799
+ [require(glsl_hlsl_metal_spirv , texture_shadowlod)]
768
800
float SampleCmp(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)
769
801
{
770
802
__target_switch
@@ -779,6 +811,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
779
811
return __glsl_texture_offset(this, __makeVector(location, compareValue), offset);
780
812
}
781
813
case hlsl:
814
+ case metal:
782
815
return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset);
783
816
case spirv:
784
817
return spirv_asm
@@ -790,7 +823,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
790
823
791
824
[__readNone]
792
825
[ForceInline]
793
- [require(glsl_hlsl_spirv , texture_shadowlod)]
826
+ [require(glsl_hlsl_metal_spirv , texture_shadowlod)]
794
827
float SampleCmpLevelZero(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)
795
828
{
796
829
__target_switch
@@ -805,6 +838,7 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
805
838
return __glsl_texture_offset_level_zero(this, __makeVector(location, compareValue), offset);
806
839
}
807
840
case hlsl:
841
+ case metal:
808
842
return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);
809
843
case spirv:
810
844
const float zeroFloat = 0.0f;
@@ -817,13 +851,14 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
817
851
818
852
[__readNone]
819
853
[ForceInline]
820
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1)]
854
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1)]
821
855
T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY)
822
856
{
823
857
__target_switch
824
858
{
825
859
case cpp:
826
860
case hlsl:
861
+ case metal:
827
862
return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY);
828
863
829
864
case glsl:
@@ -839,13 +874,14 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
839
874
840
875
[__readNone]
841
876
[ForceInline]
842
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1)]
877
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1)]
843
878
T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset)
844
879
{
845
880
__target_switch
846
881
{
847
882
case cpp:
848
883
case hlsl:
884
+ case metal:
849
885
return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset);
850
886
case glsl:
851
887
__intrinsic_asm "$ctextureGradOffset($0, $1, $2, $3, $4)$z";
@@ -861,13 +897,14 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
861
897
[__readNone]
862
898
[ForceInline]
863
899
__glsl_extension(GL_ARB_sparse_texture_clamp)
864
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1)]
900
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1)]
865
901
T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset, float lodClamp)
866
902
{
867
903
__target_switch
868
904
{
869
905
case cpp:
870
906
case hlsl:
907
+ case metal:
871
908
return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp);
872
909
case glsl:
873
910
__intrinsic_asm "$ctextureGradOffsetClampARB($0, $1, $2, $3, $4, $5)$z";
@@ -883,13 +920,14 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
883
920
884
921
[__readNone]
885
922
[ForceInline]
886
- [require(cpp_cuda_glsl_hlsl_spirv , texture_sm_4_1)]
923
+ [require(cpp_cuda_glsl_hlsl_metal_spirv , texture_sm_4_1)]
887
924
T SampleLevel(vector<float, Shape.dimensions+isArray> location, float level)
888
925
{
889
926
__target_switch
890
927
{
891
928
case cpp:
892
929
case hlsl:
930
+ case metal:
893
931
return __getTexture().SampleLevel(__getSampler(), location, level);
894
932
case glsl:
895
933
__intrinsic_asm "$ctextureLod($0, $1, $2)$z";
@@ -935,13 +973,14 @@ extension __TextureImpl<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
935
973
936
974
[__readNone]
937
975
[ForceInline]
938
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1)]
976
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1)]
939
977
T SampleLevel(vector<float, Shape.dimensions+isArray> location, float level, constexpr vector<int, Shape.planeDimensions> offset)
940
978
{
941
979
__target_switch
942
980
{
943
981
case cpp:
944
982
case hlsl:
983
+ case metal:
945
984
return __getTexture().SampleLevel(__getSampler(), location, level, offset);
946
985
947
986
case glsl:
@@ -2109,15 +2148,29 @@ for (int isScalarTexture = 0; isScalarTexture <= 1; isScalarTexture++) {
2109
2148
}}}}
2110
2149
{ // begin extension for gather
2111
2150
${{{{
2151
+ if (isCombined)
2152
+ {
2153
+ }}}}
2154
+ __intrinsic_op($(kIROp_CombinedTextureSamplerGetTexture))
2155
+ __TextureImpl<T, Shape, isArray, isMS, sampleCount, 0, isShadow, 0, format> __getTexture();
2156
+
2157
+ __intrinsic_op($(kIROp_CombinedTextureSamplerGetSampler))
2158
+ SamplerState __getSampler();
2159
+
2160
+ __intrinsic_op($(kIROp_CombinedTextureSamplerGetSampler))
2161
+ SamplerComparisonState __getComparisonSampler();
2162
+ ${{{{
2163
+ }
2164
+
2112
2165
// Gather component
2113
2166
const char* samplerStateParam = isCombined ? "" : " s,";
2114
- const char* metalSupport = isCombined ? "" : "metal_";
2115
- const char* caseMetal = isCombined ? "" : "case metal:";
2167
+ const char* getTexture = isCombined ? "__getTexture()" : "this";
2116
2168
for (int isCmp = 0; isCmp < 2; ++isCmp) {
2117
2169
const char* cmp = isCmp ? "Cmp" : "";
2118
2170
const char* cmpParam = isCmp ? ", T compareValue" : "";
2119
2171
const char* compareArg = isCmp ? ", compareValue" : "";
2120
2172
const char* samplerStateType = isCombined ? "" : (isCmp ? "SamplerComparisonState" : "SamplerState");
2173
+ const char* getSampler = isCombined ? (isCmp ? " __getComparisonSampler()," : " __getSampler(),") : samplerStateParam;
2121
2174
const char* componentNames[] = { "", "Red", "Green", "Blue", "Alpha"};
2122
2175
const char* glslComponentNames[] = { ", 0", ", 1", ", 2", ", 3" };
2123
2176
@@ -2126,26 +2179,28 @@ ${{{{
2126
2179
auto glslComponent = (isCmp ? "" :glslComponentNames[componentId == 0 ? 0 : componentId - 1]);
2127
2180
}}}}
2128
2181
[ForceInline]
2129
- [require(glsl_hlsl_$(metalSupport)spirv , texture_gather)]
2182
+ [require(glsl_hlsl_metal_spirv , texture_gather)]
2130
2183
vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam))
2131
2184
{
2132
2185
__target_switch
2133
2186
{
2134
2187
case hlsl: __intrinsic_asm ".Gather$(cmp)$(componentName)";
2135
- $(caseMetal)
2188
+ case metal:
2189
+ return __texture_gather$(cmp)<T>($(getTexture),$(getSampler) location $(compareArg) $(glslComponent));
2136
2190
case glsl:
2137
2191
case spirv:
2138
2192
return __texture_gather$(cmp)<T>(this,$(samplerStateParam) location $(compareArg) $(glslComponent));
2139
2193
}
2140
2194
}
2141
2195
[ForceInline]
2142
- [require(glsl_hlsl_$(metalSupport)spirv , texture_gather)]
2196
+ [require(glsl_hlsl_metal_spirv , texture_gather)]
2143
2197
vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam), constexpr vector<int, Shape.planeDimensions> offset)
2144
2198
{
2145
2199
__target_switch
2146
2200
{
2147
2201
case hlsl: __intrinsic_asm ".Gather$(cmp)$(componentName)";
2148
- $(caseMetal)
2202
+ case metal:
2203
+ return __texture_gather$(cmp)_offset<T>($(getTexture),$(getSampler) location $(compareArg), offset $(glslComponent));
2149
2204
case glsl:
2150
2205
case spirv:
2151
2206
return __texture_gather$(cmp)_offset<T>(this,$(samplerStateParam) location $(compareArg), offset $(glslComponent));
@@ -2347,14 +2402,16 @@ extension __TextureImpl<T,Shape,isArray,0,sampleCount,0,isShadow,isCombined,form
2347
2402
__glsl_extension(GL_EXT_samplerless_texture_functions)
2348
2403
[__readNone]
2349
2404
[ForceInline]
2350
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1_samplerless)]
2405
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1_samplerless)]
2351
2406
get
2352
2407
{
2353
2408
__target_switch
2354
2409
{
2355
2410
case cpp:
2356
2411
case hlsl:
2357
2412
__intrinsic_asm ".operator[]";
2413
+ case metal:
2414
+ return Load(__makeVector(location, 0));
2358
2415
case glsl:
2359
2416
return __glsl_load(location);
2360
2417
case spirv:
@@ -2511,14 +2568,15 @@ extension __TextureImpl<T,Shape,isArray,1,sampleCount,0,isShadow,isCombined,form
2511
2568
__glsl_extension(GL_EXT_samplerless_texture_functions)
2512
2569
[__readNone]
2513
2570
[ForceInline]
2514
- [require(cpp_glsl_hlsl_spirv , texture_sm_4_1_samplerless)]
2571
+ [require(cpp_glsl_hlsl_metal_spirv , texture_sm_4_1_samplerless)]
2515
2572
get
2516
2573
{
2517
2574
__target_switch
2518
2575
{
2519
2576
case cpp:
2520
2577
case hlsl:
2521
2578
__intrinsic_asm "($0).sample[$2][$1]";
2579
+ case metal:
2522
2580
case glsl:
2523
2581
case spirv:
2524
2582
return Load(location, sampleIndex);
0 commit comments