66using UnityEngine . TestTools ;
77using Unity . Collections ;
88using UnityEngine . Rendering . RendererUtils ;
9- using System . Text . RegularExpressions ;
9+ using UnityEngine . Rendering . RenderGraphModule . NativeRenderPassCompiler ;
1010
1111#if UNITY_EDITOR
1212using UnityEditor ;
@@ -1489,7 +1489,7 @@ public void ImportedTexturesAreClearedOnFirstUse()
14891489
14901490 m_RenderGraphTestPipeline . recordRenderGraphBody = ( context , camera , cmd ) =>
14911491 {
1492- var redTexture = CreateRedTexture ( kWidth , kHeight ) ;
1492+ var redTexture = CreateColorTexture ( kWidth , kHeight , Color . red ) ;
14931493 ImportResourceParams importParams = new ImportResourceParams ( )
14941494 {
14951495 clearColor = Color . blue , clearOnFirstUse = true
@@ -1533,6 +1533,128 @@ public void ImportedTexturesAreClearedOnFirstUse()
15331533 pixels . Dispose ( ) ;
15341534 }
15351535
1536+ [ Test ]
1537+ public void ImportedTexturesOperatorEqualAndNotEqual ( )
1538+ {
1539+ const int kWidth = 4 ;
1540+ const int kHeight = 4 ;
1541+
1542+ m_RenderGraphTestPipeline . recordRenderGraphBody = ( context , camera , cmd ) =>
1543+ {
1544+ var importParams = new ImportResourceParams ( )
1545+ {
1546+ clearColor = Color . black ,
1547+ clearOnFirstUse = true
1548+ } ;
1549+
1550+ var redTexture = CreateColorTexture ( kWidth , kHeight , Color . red ) ;
1551+ var red2Texture = CreateColorTexture ( kWidth , kHeight , Color . red ) ;
1552+ var blackTexture = CreateColorTexture ( kWidth , kHeight , Color . black ) ;
1553+
1554+ var importedTextureRed = m_RenderGraph . ImportTexture ( redTexture , importParams ) ;
1555+ var importedTextureRed2 = m_RenderGraph . ImportTexture ( red2Texture , importParams ) ;
1556+ var importedTextureRedSame = m_RenderGraph . ImportTexture ( redTexture , importParams ) ;
1557+ var importedTextureBlack = m_RenderGraph . ImportTexture ( blackTexture , importParams ) ;
1558+
1559+ // Different textures, different handles.
1560+ Assert . True ( importedTextureRed != importedTextureBlack ) ;
1561+
1562+ // Different textures, different handles.
1563+ Assert . True ( importedTextureRed != importedTextureRed2 ) ;
1564+
1565+ // Same texture, different handles.
1566+ Assert . False ( importedTextureRed == importedTextureRedSame ) ;
1567+
1568+ importedTextureRedSame = importedTextureRed ;
1569+
1570+ // Same texture, same handle.
1571+ Assert . True ( importedTextureRed == importedTextureRedSame ) ;
1572+ } ;
1573+
1574+ m_Camera . Render ( ) ;
1575+ }
1576+
1577+ [ Test ]
1578+ public void CreatedTexturesOperatorEqualAndNotEqual ( )
1579+ {
1580+ m_RenderGraphTestPipeline . recordRenderGraphBody = ( context , camera , cmd ) =>
1581+ {
1582+ const int kWidth = 4 ;
1583+ const int kHeight = 4 ;
1584+
1585+ var texture0 = m_RenderGraph . CreateTexture ( new TextureDesc ( kWidth , kHeight ) { colorFormat = GraphicsFormat . R8G8B8A8_UNorm , name = "Texture0" } ) ;
1586+ var texture1 = m_RenderGraph . CreateTexture ( new TextureDesc ( kWidth , kHeight ) { colorFormat = GraphicsFormat . R8G8B8A8_UNorm , name = "Texture1" } ) ;
1587+
1588+ // Different textures, different handles.
1589+ Assert . True ( texture0 != texture1 ) ;
1590+
1591+ // Different textures, different handles.
1592+ Assert . False ( texture0 == texture1 ) ;
1593+
1594+ texture1 = texture0 ;
1595+
1596+ // Same texture, same handles.
1597+ Assert . True ( texture0 == texture1 ) ;
1598+
1599+ // Same texture, same handles.
1600+ Assert . False ( texture0 != texture1 ) ;
1601+ } ;
1602+
1603+ m_Camera . Render ( ) ;
1604+ }
1605+
1606+ [ Test ]
1607+ public void TexturesOperatorWorksInList ( )
1608+ {
1609+ m_RenderGraphTestPipeline . recordRenderGraphBody = ( context , camera , cmd ) =>
1610+ {
1611+ const int kWidth = 4 ;
1612+ const int kHeight = 4 ;
1613+
1614+ var texture0 = m_RenderGraph . CreateTexture ( new TextureDesc ( kWidth , kHeight ) { colorFormat = GraphicsFormat . R8G8B8A8_UNorm , name = "Texture0" } ) ;
1615+ var texture1 = m_RenderGraph . CreateTexture ( new TextureDesc ( kWidth , kHeight ) { colorFormat = GraphicsFormat . R8G8B8A8_UNorm , name = "Texture1" } ) ;
1616+
1617+ var listHandles = new List < TextureHandle > ( ) ;
1618+ listHandles . Add ( texture0 ) ;
1619+
1620+ Assert . True ( listHandles . Contains ( texture0 ) ) ;
1621+ Assert . True ( ! listHandles . Contains ( texture1 ) ) ;
1622+
1623+ listHandles . Add ( texture1 ) ;
1624+
1625+ Assert . True ( listHandles . Contains ( texture1 ) ) ;
1626+ } ;
1627+
1628+ m_Camera . Render ( ) ;
1629+ }
1630+
1631+ [ Test ]
1632+ public void TexturesOperatorWorksInDictionary ( )
1633+ {
1634+ m_RenderGraphTestPipeline . recordRenderGraphBody = ( context , camera , cmd ) =>
1635+ {
1636+ const int kWidth = 4 ;
1637+ const int kHeight = 4 ;
1638+
1639+ var texture0 = m_RenderGraph . CreateTexture ( new TextureDesc ( kWidth , kHeight ) { colorFormat = GraphicsFormat . R8G8B8A8_UNorm , name = "Texture0" } ) ;
1640+ var texture1 = m_RenderGraph . CreateTexture ( new TextureDesc ( kWidth , kHeight ) { colorFormat = GraphicsFormat . R8G8B8A8_UNorm , name = "Texture1" } ) ;
1641+
1642+ var dictionaryHandles = new Dictionary < TextureHandle , int > ( ) ;
1643+ dictionaryHandles . Add ( texture0 , 0 ) ;
1644+
1645+ Assert . True ( dictionaryHandles . ContainsKey ( texture0 ) ) ;
1646+ Assert . True ( dictionaryHandles . TryGetValue ( texture0 , out var value0 ) && value0 == 0 ) ;
1647+ Assert . True ( ! dictionaryHandles . ContainsKey ( texture1 ) ) ;
1648+
1649+ dictionaryHandles . Add ( texture1 , 1 ) ;
1650+
1651+ Assert . True ( dictionaryHandles . ContainsKey ( texture1 ) ) ;
1652+ Assert . True ( dictionaryHandles . TryGetValue ( texture1 , out var value1 ) && value1 == 1 ) ;
1653+ } ;
1654+
1655+ m_Camera . Render ( ) ;
1656+ }
1657+
15361658 [ Test ]
15371659 public void RequestAsyncReadbackIntoNativeArrayWorks ( )
15381660 {
@@ -1552,7 +1674,7 @@ public void RequestAsyncReadbackIntoNativeArrayWorks()
15521674
15531675 passExecuted = true ;
15541676
1555- var redTexture = CreateRedTexture ( kWidth , kHeight ) ;
1677+ var redTexture = CreateColorTexture ( kWidth , kHeight , Color . red ) ;
15561678 var texture0 = m_RenderGraph . ImportTexture ( redTexture ) ;
15571679
15581680 pixels = new NativeArray < byte > ( kWidth * kHeight * 4 , Allocator . Persistent , NativeArrayOptions . UninitializedMemory ) ;
@@ -1603,11 +1725,8 @@ void RenderGraphTest_AsyncReadbackCallback(AsyncGPUReadbackRequest request, ref
16031725 }
16041726 }
16051727
1606- RTHandle CreateRedTexture ( int width , int height )
1728+ RTHandle CreateColorTexture ( int width , int height , Color color )
16071729 {
1608- // Create a red color
1609- Color redColor = Color . red ;
1610-
16111730 // Initialize the RTHandle system if necessary
16121731 RTHandles . Initialize ( width , height ) ;
16131732
@@ -1625,7 +1744,7 @@ RTHandle CreateRedTexture(int width, int height)
16251744 {
16261745 for ( int x = 0 ; x < tempTexture . width ; x ++ )
16271746 {
1628- tempTexture . SetPixel ( x , y , redColor ) ;
1747+ tempTexture . SetPixel ( x , y , color ) ;
16291748 }
16301749 }
16311750 tempTexture . Apply ( ) ;
0 commit comments