summaryrefslogtreecommitdiffstats
path: root/tests/compute/generic-interface-method.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-11-07 19:09:40 -0500
committerTim Foley <tfoleyNV@users.noreply.github.com>2017-11-07 16:09:40 -0800
commit6e591ada0eb652c320bba4bd8a46cd579946df01 (patch)
tree768229fb26204b6b0a89201d9b14c32e9203c098 /tests/compute/generic-interface-method.slang
parent939688e963fde7a0485f210ef2674c27692021a4 (diff)
Support generic interface methods (#251)
* improve diagnostic messages and prevent fatal errors from crashing the compiler. * fix top level exception catching. * spelling fix * change wording of invalidSwizzleExpr diagnostic * add speculative GenericsApp expr parsing * add new test case of cascading generics call. * Fixing bugs in compiling cascaded generic function calls. Add implementation of DeclaredSubTypeWitness::SubstituteImpl() This is not needed by the type checker, but needed by IR specialization. When input source contains cascading generic function call, the arguments to `specialize` instruction is currently represented as a substitution. The arg values of this subsittution can be a `DeclaredSubTypeWitness` when a generic function uses one of its generic parameter to specialize another generic function. When the top level generics function is being specialized, this substitution argument, which is a `DeclaredSubTypeWitness`, needs to be substituted with the witness that used to specialize the top level function in the specialized specialize instruction as well. * add a test case for cascading generic function call. * parser bug fix * fixes #255 * add test case for issue #255 * Generate missing `specialize` instruction when calling a generic method from an interface constraint. When calling a generic method via an interface, we should be generating the following ir: ... f = lookup_interface_method(...) f_s = specailize(f, declRef) ... This commit fixes this `emitFuncRef` function to emit the needed `specialize` instruction. * fixes #260 This fix follows the second apporach in the disucssion. It generated mangled name for specialized functions by appending new substitution type names to the original mangled name. * Disabling removing and re-inserting specailized functions in getSpecalizeFunc() I am not sure why it is needed, it seems HLSL and GLSL backends are generating forward declarations anyways, so the order of functions in IRModule shouldn't matter. * cleanup and complete test cases. * fix warnings
Diffstat (limited to 'tests/compute/generic-interface-method.slang')
-rw-r--r--tests/compute/generic-interface-method.slang86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/compute/generic-interface-method.slang b/tests/compute/generic-interface-method.slang
new file mode 100644
index 000000000..e4fa8cff5
--- /dev/null
+++ b/tests/compute/generic-interface-method.slang
@@ -0,0 +1,86 @@
+//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+
+RWStructuredBuffer<float> outputBuffer;
+
+struct DisneyBRDFPattern
+{
+ float3 baseColor;
+ float3 normal;
+ float specular, metallic, roughness;
+ float opacity;
+ float3 emmissive;
+ float ambientOcclusion;
+};
+
+struct VertexPosition
+{
+ float3 pos;
+ float3 normal;
+ float2 uv;
+};
+
+struct CameraView
+{
+ float3 camPos;
+ float3 camDir;
+};
+
+interface IVertexInterpolant
+{
+ float4 getVertexColor(int index);
+ int getVertexColorCount();
+ float2 getUV(int index);
+ int getUVCount();
+}
+
+interface IDisneyBRDFPattern
+{
+ __generic<TVertexInterpolant:IVertexInterpolant>
+ DisneyBRDFPattern evalPattern(
+ CameraView cam,
+ VertexPosition vWorld,
+ VertexPosition vObject,
+ TVertexInterpolant interpolants);
+}
+
+struct StandardVertexInterpolant : IVertexInterpolant
+{
+ float4 getVertexColor(int index) { return float4(0.0); }
+ int getVertexColorCount() { return 0;}
+ float2 getUV(int index) { return float2(0.0); }
+ int getUVCount() {return 1; }
+};
+
+struct MaterialPattern1 : IDisneyBRDFPattern
+{
+ __generic<TVertexInterpolant:IVertexInterpolant>
+ DisneyBRDFPattern evalPattern(
+ CameraView cam,
+ VertexPosition vWorld,
+ VertexPosition vObject,
+ TVertexInterpolant interpolants)
+ {
+ DisneyBRDFPattern rs;
+ rs.baseColor = float3(0.5);
+ rs.opacity = 1.0;
+ return rs;
+ }
+};
+
+__generic<TVertexInterpolant:IVertexInterpolant, TPattern : IDisneyBRDFPattern>
+float test(TVertexInterpolant vertInterps, TPattern pattern)
+{
+ CameraView cam;
+ VertexPosition vW, vO;
+ DisneyBRDFPattern rs = pattern.evalPattern(cam, vW, vO, vertInterps);
+ return rs.baseColor.x;
+}
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ StandardVertexInterpolant vertInterp;
+ MaterialPattern1 mp1;
+ float outVal = test<StandardVertexInterpolant, MaterialPattern1>(vertInterp, mp1);
+ outputBuffer[dispatchThreadID.x] = outVal;
+} \ No newline at end of file