Update sdr to use SdfValueTypeNames::Int# values
authortallytalwar <tallytalwar@users.noreply.github.com>
Sat, 3 Feb 2024 03:25:14 +0000 (19:25 -0800)
committerpixar-oss <pixar-oss@users.noreply.github.com>
Sat, 3 Feb 2024 03:25:14 +0000 (19:25 -0800)
- Shaders using sdr which have support for int2, int3, int4 can now
leverage SdfValueTypeNames->Int2, SdfValueTypeNames->Int3,
SdfValueTypeNames->Int4 appropriately, without having to specify
sdrUsdDefinitionType.

- Updates to following tests:
   - testUsdShadeShaderDef
   - testOslParser

(Internal change: 2313496)

pxr/usd/plugin/sdrOsl/testenv/testOslParser.testenv/TestShaderPropertiesNodeOSL.osl
pxr/usd/plugin/sdrOsl/testenv/testOslParser.testenv/TestShaderPropertiesNodeOSL.oso
pxr/usd/sdr/shaderProperty.cpp
pxr/usd/usdShade/testenv/testUsdShadeShaderDef/shaderDefs.usda

index f0b6cfda0736b12bd432c3d33df18b489090527c..2f4d6fcfc4a46d9dce1948ae6879ba2054e82c6e 100644 (file)
@@ -37,7 +37,10 @@ shader TestShaderPropertiesNodeOSL
     [[
         string vstructmember = "inputVstruct.parameter"
     ]],
-    int inputIntArray[3] = {1, 2, 3},
+    int inputInt2[2] = {1, 2},
+    int inputInt3[3] = {1, 2, 3},
+    int inputInt4[4] = {1, 2, 3, 4},
+    int inputIntArray[5] = {1, 2, 3, 4, 5},
     string inputStringArray[4] = { "foo", "bar", "baz", "moo" },
     float inputFloatArray[5] = { 1.0, 2.0, 3.0, 4.0, 5.0 },
     color inputColorArray[2] = { color(1.0, 1.0, 1.0), color(1.0, 1.0, 1.0) },
@@ -89,4 +92,4 @@ shader TestShaderPropertiesNodeOSL
 )
 {
     // Nothing here!
-}
\ No newline at end of file
+}
index 652134b1fdcd8b56ced945e277ba327ade5ee02b..bcbbd9737b9272b2e93279543b3d2e5011bd1e20 100644 (file)
@@ -1,5 +1,5 @@
 OpenShadingLanguage 1.00
-# Compiled by oslc 1.8.2.pixar1697a56
+# Compiled by oslc 1.11.0@OPROJECT_VERSION_RELEASE_TYPE@
 # options: -o TestShaderPropertiesNodeOSL.oso
 shader TestShaderPropertiesNodeOSL     %meta{string,help,"This node is used for testing shader property typecorrectness"} 
 param  int     inputInt        1               %read{2147483647,-1} %write{2147483647,-1}
@@ -14,7 +14,10 @@ param        struct TestStruct       inputStruct                     %read{2147483647,-1} %write{2147483647,-1}
 param  float   inputStruct.foo 0               %read{2147483647,-1} %write{2147483647,-1} %mystruct{inputStruct} %mystructfield{0}
 param  float   inputVstruct    0               %read{2147483647,-1} %write{2147483647,-1}
 param  float   inputVstruct_parameter  0               %meta{string,vstructmember,"inputVstruct.parameter"}  %read{2147483647,-1} %write{2147483647,-1}
-param  int[3]  inputIntArray   1 2 3           %read{2147483647,-1} %write{2147483647,-1}
+param  int[2]  inputInt2       1 2             %read{2147483647,-1} %write{2147483647,-1}
+param  int[3]  inputInt3       1 2 3           %read{2147483647,-1} %write{2147483647,-1}
+param  int[4]  inputInt4       1 2 3 4         %read{2147483647,-1} %write{2147483647,-1}
+param  int[5]  inputIntArray   1 2 3 4 5               %read{2147483647,-1} %write{2147483647,-1}
 param  string[4]       inputStringArray        "foo" "bar" "baz" "moo"         %read{2147483647,-1} %write{2147483647,-1}
 param  float[5]        inputFloatArray 1 2 3 4 5               %read{2147483647,-1} %write{2147483647,-1}
 param  color[2]        inputColorArray 1 1 1 1 1 1             %read{2147483647,-1} %write{2147483647,-1}
@@ -37,16 +40,16 @@ const       point   $const1 1 2 3           %read{0,0} %write{2147483647,-1}
 const  normal  $const2 1 2 3           %read{1,1} %write{2147483647,-1}
 const  vector  $const3 1 2 3           %read{2,2} %write{2147483647,-1}
 code inputPointRoleNone
-# TestShaderPropertiesNodeOSL.osl:63
-#     ]],
-       assign          inputPointRoleNone $const1      %filename{"TestShaderPropertiesNodeOSL.osl"} %line{63} %argrw{"wr"}
+# TestShaderPropertiesNodeOSL.osl:69
+#     color inputPointRoleNone = point(1.0, 2.0, 3.0)
+       assign          inputPointRoleNone $const1      %filename{"TestShaderPropertiesNodeOSL.osl"} %line{69} %argrw{"wr"}
 code inputNormalRoleNone
-# TestShaderPropertiesNodeOSL.osl:67
-#     ]],
-       assign          inputNormalRoleNone $const2     %filename{"TestShaderPropertiesNodeOSL.osl"} %line{67} %argrw{"wr"}
+# TestShaderPropertiesNodeOSL.osl:73
+#     color inputNormalRoleNone = normal(1.0, 2.0, 3.0)
+       assign          inputNormalRoleNone $const2     %filename{"TestShaderPropertiesNodeOSL.osl"} %line{73} %argrw{"wr"}
 code inputVectorRoleNone
-# TestShaderPropertiesNodeOSL.osl:71
-#     ]],
-       assign          inputVectorRoleNone $const3     %filename{"TestShaderPropertiesNodeOSL.osl"} %line{71} %argrw{"wr"}
+# TestShaderPropertiesNodeOSL.osl:77
+#     color inputVectorRoleNone = vector(1.0, 2.0, 3.0)
+       assign          inputVectorRoleNone $const3     %filename{"TestShaderPropertiesNodeOSL.osl"} %line{77} %argrw{"wr"}
 code ___main___
        end
index 2a9904f2c0ebf85d9573463fd21804d1fdaf7b1c..57d72599e6c0c46ed54bca8df3f023efc047baeb 100644 (file)
@@ -300,10 +300,19 @@ namespace {
             }
 
             // We prefer more specific types, so if the arraySize is 2, 3, or 4,
-            // then try to convert to a fixed-dimension float array.
+            // then try to convert to a fixed-dimension int or float array.
             // In the future if we change this to not return a fixed-size array,
             // all the parsers need to be updated to not return a fixed-size
             // array as well.
+            if (type == SdrPropertyTypes->Int) {
+                if (arraySize == 2) {
+                    return std::make_pair(SdfValueTypeNames->Int2, TfToken());
+                } else if (arraySize == 3) {
+                    return std::make_pair(SdfValueTypeNames->Int3, TfToken());
+                } else if (arraySize == 4) {
+                    return std::make_pair(SdfValueTypeNames->Int4, TfToken());
+                }
+            }
             if (type == SdrPropertyTypes->Float) {
                 if (arraySize == 2) {
                     return std::make_pair(SdfValueTypeNames->Float2, TfToken());
index 4706e2526a1caea0efe5d09f59967870f9a0889d..122bc70376be2ffa090f26f2a5c62b5c807f6c10 100644 (file)
@@ -17,7 +17,10 @@ def Shader "TestShaderPropertiesNodeUSD" (
     vector3f inputs:inputVector = (0.0, 0.0, 0.0)
     matrix4d inputs:inputMatrix = (
         (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0) )
-    int[] inputs:inputIntArray = [1, 2, 3]
+    int[] inputs:inputInt2 = [1, 2]
+    int[] inputs:inputInt3 = [1, 2, 3]
+    int[] inputs:inputInt4 = [1, 2, 3, 5]
+    int[] inputs:inputIntArray = [1, 2, 3, 4, 5]
     string[] inputs:inputStringArray = [ "foo", "bar", "baz", "moo" ]
     float[] inputs:inputFloatArray = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]
     color3f[] inputs:inputColorArray = [ (1.0, 1.0, 1.0), (1.0, 1.0, 1.0) ]