@@ -1480,9 +1480,78 @@ impl<A: HalApi> Device<A> {
1480
1480
} ;
1481
1481
}
1482
1482
1483
- use naga:: valid:: Capabilities as Caps ;
1484
1483
profiling:: scope!( "naga::validate" ) ;
1484
+ let debug_source =
1485
+ if self . instance_flags . contains ( wgt:: InstanceFlags :: DEBUG ) && !source. is_empty ( ) {
1486
+ Some ( hal:: DebugSource {
1487
+ file_name : Cow :: Owned (
1488
+ desc. label
1489
+ . as_ref ( )
1490
+ . map_or ( "shader" . to_string ( ) , |l| l. to_string ( ) ) ,
1491
+ ) ,
1492
+ source_code : Cow :: Owned ( source. clone ( ) ) ,
1493
+ } )
1494
+ } else {
1495
+ None
1496
+ } ;
1497
+
1498
+ let info = self
1499
+ . create_validator ( naga:: valid:: ValidationFlags :: all ( ) )
1500
+ . validate ( & module)
1501
+ . map_err ( |inner| {
1502
+ pipeline:: CreateShaderModuleError :: Validation ( pipeline:: ShaderError {
1503
+ source,
1504
+ label : desc. label . as_ref ( ) . map ( |l| l. to_string ( ) ) ,
1505
+ inner : Box :: new ( inner) ,
1506
+ } )
1507
+ } ) ?;
1508
+
1509
+ let interface =
1510
+ validation:: Interface :: new ( & module, & info, self . limits . clone ( ) , self . features ) ;
1511
+ let hal_shader = hal:: ShaderInput :: Naga ( hal:: NagaShader {
1512
+ module,
1513
+ info,
1514
+ debug_source,
1515
+ } ) ;
1516
+ let hal_desc = hal:: ShaderModuleDescriptor {
1517
+ label : desc. label . to_hal ( self . instance_flags ) ,
1518
+ runtime_checks : desc. shader_bound_checks . runtime_checks ( ) ,
1519
+ } ;
1520
+ let raw = match unsafe {
1521
+ self . raw
1522
+ . as_ref ( )
1523
+ . unwrap ( )
1524
+ . create_shader_module ( & hal_desc, hal_shader)
1525
+ } {
1526
+ Ok ( raw) => raw,
1527
+ Err ( error) => {
1528
+ return Err ( match error {
1529
+ hal:: ShaderError :: Device ( error) => {
1530
+ pipeline:: CreateShaderModuleError :: Device ( error. into ( ) )
1531
+ }
1532
+ hal:: ShaderError :: Compilation ( ref msg) => {
1533
+ log:: error!( "Shader error: {}" , msg) ;
1534
+ pipeline:: CreateShaderModuleError :: Generation
1535
+ }
1536
+ } )
1537
+ }
1538
+ } ;
1539
+
1540
+ Ok ( pipeline:: ShaderModule {
1541
+ raw : Some ( raw) ,
1542
+ device : self . clone ( ) ,
1543
+ interface : Some ( interface) ,
1544
+ info : ResourceInfo :: new ( desc. label . borrow_or_default ( ) , None ) ,
1545
+ label : desc. label . borrow_or_default ( ) . to_string ( ) ,
1546
+ } )
1547
+ }
1485
1548
1549
+ /// Create a validator with the given validation flags.
1550
+ pub fn create_validator (
1551
+ self : & Arc < Self > ,
1552
+ flags : naga:: valid:: ValidationFlags ,
1553
+ ) -> naga:: valid:: Validator {
1554
+ use naga:: valid:: Capabilities as Caps ;
1486
1555
let mut caps = Caps :: empty ( ) ;
1487
1556
caps. set (
1488
1557
Caps :: PUSH_CONSTANT ,
@@ -1560,20 +1629,6 @@ impl<A: HalApi> Device<A> {
1560
1629
self . features . intersects ( wgt:: Features :: SUBGROUP_BARRIER ) ,
1561
1630
) ;
1562
1631
1563
- let debug_source =
1564
- if self . instance_flags . contains ( wgt:: InstanceFlags :: DEBUG ) && !source. is_empty ( ) {
1565
- Some ( hal:: DebugSource {
1566
- file_name : Cow :: Owned (
1567
- desc. label
1568
- . as_ref ( )
1569
- . map_or ( "shader" . to_string ( ) , |l| l. to_string ( ) ) ,
1570
- ) ,
1571
- source_code : Cow :: Owned ( source. clone ( ) ) ,
1572
- } )
1573
- } else {
1574
- None
1575
- } ;
1576
-
1577
1632
let mut subgroup_stages = naga:: valid:: ShaderStages :: empty ( ) ;
1578
1633
subgroup_stages. set (
1579
1634
naga:: valid:: ShaderStages :: COMPUTE | naga:: valid:: ShaderStages :: FRAGMENT ,
@@ -1590,57 +1645,10 @@ impl<A: HalApi> Device<A> {
1590
1645
} else {
1591
1646
naga:: valid:: SubgroupOperationSet :: empty ( )
1592
1647
} ;
1593
-
1594
- let info = naga:: valid:: Validator :: new ( naga:: valid:: ValidationFlags :: all ( ) , caps)
1595
- . subgroup_stages ( subgroup_stages)
1596
- . subgroup_operations ( subgroup_operations)
1597
- . validate ( & module)
1598
- . map_err ( |inner| {
1599
- pipeline:: CreateShaderModuleError :: Validation ( pipeline:: ShaderError {
1600
- source,
1601
- label : desc. label . as_ref ( ) . map ( |l| l. to_string ( ) ) ,
1602
- inner : Box :: new ( inner) ,
1603
- } )
1604
- } ) ?;
1605
-
1606
- let interface =
1607
- validation:: Interface :: new ( & module, & info, self . limits . clone ( ) , self . features ) ;
1608
- let hal_shader = hal:: ShaderInput :: Naga ( hal:: NagaShader {
1609
- module,
1610
- info,
1611
- debug_source,
1612
- } ) ;
1613
- let hal_desc = hal:: ShaderModuleDescriptor {
1614
- label : desc. label . to_hal ( self . instance_flags ) ,
1615
- runtime_checks : desc. shader_bound_checks . runtime_checks ( ) ,
1616
- } ;
1617
- let raw = match unsafe {
1618
- self . raw
1619
- . as_ref ( )
1620
- . unwrap ( )
1621
- . create_shader_module ( & hal_desc, hal_shader)
1622
- } {
1623
- Ok ( raw) => raw,
1624
- Err ( error) => {
1625
- return Err ( match error {
1626
- hal:: ShaderError :: Device ( error) => {
1627
- pipeline:: CreateShaderModuleError :: Device ( error. into ( ) )
1628
- }
1629
- hal:: ShaderError :: Compilation ( ref msg) => {
1630
- log:: error!( "Shader error: {}" , msg) ;
1631
- pipeline:: CreateShaderModuleError :: Generation
1632
- }
1633
- } )
1634
- }
1635
- } ;
1636
-
1637
- Ok ( pipeline:: ShaderModule {
1638
- raw : Some ( raw) ,
1639
- device : self . clone ( ) ,
1640
- interface : Some ( interface) ,
1641
- info : ResourceInfo :: new ( desc. label . borrow_or_default ( ) , None ) ,
1642
- label : desc. label . borrow_or_default ( ) . to_string ( ) ,
1643
- } )
1648
+ let mut validator = naga:: valid:: Validator :: new ( flags, caps) ;
1649
+ validator. subgroup_stages ( subgroup_stages) ;
1650
+ validator. subgroup_operations ( subgroup_operations) ;
1651
+ validator
1644
1652
}
1645
1653
1646
1654
#[ allow( unused_unsafe) ]
0 commit comments