Browse Source

Add ObjectToWorld/WorldToObject 3x4 and 4x3 intrinsics

- left original ObjectToWorld/WorldToObject for prototype compat.
Tex Riddell 7 years ago
parent
commit
f805234c9b

+ 4 - 0
include/dxc/HlslIntrinsicOp.h

@@ -57,6 +57,8 @@ import hctdb_instrhelp
   IOP_ObjectRayDirection,
   IOP_ObjectRayOrigin,
   IOP_ObjectToWorld,
+  IOP_ObjectToWorld3x4,
+  IOP_ObjectToWorld4x3,
   IOP_PrimitiveIndex,
   IOP_Process2DQuadTessFactorsAvg,
   IOP_Process2DQuadTessFactorsMax,
@@ -100,6 +102,8 @@ import hctdb_instrhelp
   IOP_WorldRayDirection,
   IOP_WorldRayOrigin,
   IOP_WorldToObject,
+  IOP_WorldToObject3x4,
+  IOP_WorldToObject4x3,
   IOP_abort,
   IOP_abs,
   IOP_acos,

+ 22 - 3
lib/HLSL/HLOperationLower.cpp

@@ -4358,7 +4358,7 @@ Value *TranslateNoArgVectorOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode o
   return retVal;
 }
 
-Value *TranslateNoArgMatrixOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
+Value *TranslateNoArgMatrix3x4Operation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
                          HLOperationLowerHelper &helper,
                          HLObjectOperationLowerHelper *pObjHelper,
                          bool &Translated) {
@@ -4373,6 +4373,21 @@ Value *TranslateNoArgMatrixOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode o
   return retVal;
 }
 
+Value *TranslateNoArgTransposedMatrix3x4Operation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
+                                                  HLOperationLowerHelper &helper,
+                                                  HLObjectOperationLowerHelper *pObjHelper,
+                                                  bool &Translated) {
+  hlsl::OP *hlslOP = &helper.hlslOP;
+  VectorType *Ty = cast<VectorType>(CI->getType());
+  uint32_t rVals[] = { 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2 };
+  Constant *rows = ConstantDataVector::get(CI->getContext(), rVals);
+  uint8_t cVals[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 };
+  Constant *cols = ConstantDataVector::get(CI->getContext(), cVals);
+  Value *retVal =
+    TrivialDxilOperation(opcode, { nullptr, rows, cols }, Ty, CI, hlslOP);
+  return retVal;
+}
+
 Value *TranslateNoArgNoReturnPreserveOutput(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
   HLOperationLowerHelper &helper, HLObjectOperationLowerHelper *pObjHelper, bool &Translated) {
   Instruction *pResult = cast<Instruction>(
@@ -4458,7 +4473,9 @@ IntrinsicLower gLowerTable[static_cast<unsigned>(IntrinsicOp::Num_Intrinsics)] =
     {IntrinsicOp::IOP_NonUniformResourceIndex, TranslateNonUniformResourceIndex, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_ObjectRayDirection, TranslateNoArgVectorOperation, DXIL::OpCode::ObjectRayDirection},
     {IntrinsicOp::IOP_ObjectRayOrigin, TranslateNoArgVectorOperation, DXIL::OpCode::ObjectRayOrigin},
-    {IntrinsicOp::IOP_ObjectToWorld, TranslateNoArgMatrixOperation, DXIL::OpCode::ObjectToWorld},
+    {IntrinsicOp::IOP_ObjectToWorld, TranslateNoArgMatrix3x4Operation, DXIL::OpCode::ObjectToWorld},
+    {IntrinsicOp::IOP_ObjectToWorld3x4, TranslateNoArgMatrix3x4Operation, DXIL::OpCode::ObjectToWorld},
+    {IntrinsicOp::IOP_ObjectToWorld4x3, TranslateNoArgTransposedMatrix3x4Operation, DXIL::OpCode::ObjectToWorld},
     {IntrinsicOp::IOP_PrimitiveIndex, TrivialNoArgWithRetOperation, DXIL::OpCode::PrimitiveIndex},
     {IntrinsicOp::IOP_Process2DQuadTessFactorsAvg, TranslateProcessTessFactors, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_Process2DQuadTessFactorsMax, TranslateProcessTessFactors, DXIL::OpCode::NumOpCodes},
@@ -4501,7 +4518,9 @@ IntrinsicLower gLowerTable[static_cast<unsigned>(IntrinsicOp::Num_Intrinsics)] =
     {IntrinsicOp::IOP_WaveReadLaneFirst, TranslateWaveReadLaneFirst, DXIL::OpCode::WaveReadLaneFirst},
     {IntrinsicOp::IOP_WorldRayDirection, TranslateNoArgVectorOperation, DXIL::OpCode::WorldRayDirection},
     {IntrinsicOp::IOP_WorldRayOrigin, TranslateNoArgVectorOperation, DXIL::OpCode::WorldRayOrigin},
-    {IntrinsicOp::IOP_WorldToObject, TranslateNoArgMatrixOperation, DXIL::OpCode::WorldToObject},
+    {IntrinsicOp::IOP_WorldToObject, TranslateNoArgMatrix3x4Operation, DXIL::OpCode::WorldToObject},
+    {IntrinsicOp::IOP_WorldToObject3x4, TranslateNoArgMatrix3x4Operation, DXIL::OpCode::WorldToObject},
+    {IntrinsicOp::IOP_WorldToObject4x3, TranslateNoArgTransposedMatrix3x4Operation, DXIL::OpCode::WorldToObject},
     {IntrinsicOp::IOP_abort, EmptyLower, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_abs, TransalteAbs, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_acos, TrivialUnaryOperation, DXIL::OpCode::Acos},

File diff suppressed because it is too large
+ 157 - 137
tools/clang/lib/Sema/gen_intrin_main_tables_15.h


+ 1 - 1
tools/clang/test/CodeGenHLSL/abs1.hlsl

@@ -2,7 +2,7 @@
 
 // CHECK: main
 // After lowering, these would turn into multiple abs calls rather than a 4 x float
-// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 80,
+// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 84,
 
 float4 main(float4 a : A) : SV_TARGET {
   return abs(a*a.yxxx);

+ 13 - 0
tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms3x4.hlsl

@@ -0,0 +1,13 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 0)
+// CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 1)
+// CHECK: call float @dx.op.worldToObject.f32(i32 152, i32 2, i8 2)
+// CHECK: call float @dx.op.worldToObject.f32(i32 152, i32 2, i8 3)
+
+float4 emit(uint shader)  {
+  float3x4 o2w = ObjectToWorld3x4();
+  float3x4 w2o = WorldToObject3x4();
+
+  return float4(o2w._m20_m21, w2o._33_34);
+}

+ 13 - 0
tools/clang/test/CodeGenHLSL/quick-test/raytracing_sgv_transforms4x3.hlsl

@@ -0,0 +1,13 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 0)
+// CHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 2, i8 1)
+// CHECK: call float @dx.op.worldToObject.f32(i32 152, i32 2, i8 2)
+// CHECK: call float @dx.op.worldToObject.f32(i32 152, i32 2, i8 3)
+
+float4 emit(uint shader)  {
+  float4x3 o2w = ObjectToWorld4x3();
+  float4x3 w2o = WorldToObject4x3();
+
+  return float4(o2w._m02_m12, w2o._33_43);
+}

+ 8 - 3
tools/clang/unittests/HLSL/ExtensionTest.cpp

@@ -731,11 +731,16 @@ TEST_F(ExtensionTest, UnsignedOpcodeIsUnchanged) {
 
   // - opcode is unchanged when it matches an hlsl intrinsic with
   //   an unsigned version.
-  // Note that 117 is the current opcode for IOP_min. If that opcode
-  // changes the test will need to be updated to reflect the new opcode.
+  // This should use the same value as IOP_min.
+  std::string matchStr;
+  std::ostringstream ss(matchStr);
+  ss << "call i32 @test_unsigned(i32 "
+     << (unsigned)hlsl::IntrinsicOp::IOP_min
+     << ", ";
+
   VERIFY_IS_TRUE(
     disassembly.npos !=
-    disassembly.find("call i32 @test_unsigned(i32 137, "));
+    disassembly.find(ss.str()));
 }
 
 TEST_F(ExtensionTest, ResourceExtensionIntrinsic) {

+ 6 - 2
utils/hct/gen_intrin_main.txt

@@ -291,8 +291,12 @@ uint [[rn]] InstanceIndex();
 uint [[rn]] HitKind();
 uint [[rn]] RayFlags();
 // group: Ray Transforms
-row_major float<3,4> [[rn]] ObjectToWorld();
-row_major float<3,4> [[rn]] WorldToObject();
+float<3,4> [[rn]] ObjectToWorld();
+float<3,4> [[rn]] WorldToObject();
+float<3,4> [[rn]] ObjectToWorld3x4();
+float<3,4> [[rn]] WorldToObject3x4();
+float<4,3> [[rn]] ObjectToWorld4x3();
+float<4,3> [[rn]] WorldToObject4x3();
 } namespace
 
 namespace StreamMethods {

Some files were not shown because too many files changed in this diff