Browse Source

shaderpipeline: Clean up alpha test inject pass code, use unordered !=

rdb 1 year ago
parent
commit
249ab8dc91

+ 6 - 3
panda/src/shaderpipeline/spirVInjectAlphaTestPass.cxx

@@ -50,6 +50,8 @@ begin_function(Instruction op) {
  */
  */
 bool SpirVInjectAlphaTestPass::
 bool SpirVInjectAlphaTestPass::
 transform_function_op(Instruction op) {
 transform_function_op(Instruction op) {
+  // There may be multiple returns.  Insert an alpha test before every return
+  // statement.
   if (_var_id != 0 &&
   if (_var_id != 0 &&
       (op.opcode == spv::OpReturn || op.opcode == spv::OpReturnValue)) {
       (op.opcode == spv::OpReturn || op.opcode == spv::OpReturnValue)) {
 
 
@@ -61,6 +63,7 @@ transform_function_op(Instruction op) {
       return true;
       return true;
 
 
     case M_never:
     case M_never:
+      // Replace the OpReturn with an OpKill.
       op_kill();
       op_kill();
       return false;
       return false;
 
 
@@ -69,7 +72,7 @@ transform_function_op(Instruction op) {
       break;
       break;
 
 
     case M_equal:
     case M_equal:
-      opcode = spv::OpFOrdNotEqual;
+      opcode = spv::OpFUnordNotEqual;
       break;
       break;
 
 
     case M_less_equal:
     case M_less_equal:
@@ -95,8 +98,8 @@ transform_function_op(Instruction op) {
 
 
     if (_alpha_ref_var_id == 0) {
     if (_alpha_ref_var_id == 0) {
       _alpha_ref_var_id = define_variable(ShaderType::float_type, spv::StorageClassUniformConstant);
       _alpha_ref_var_id = define_variable(ShaderType::float_type, spv::StorageClassUniformConstant);
-      if (_location >= 0) {
-        decorate(_alpha_ref_var_id, spv::DecorationLocation, (uint32_t)_location);
+      if (_ref_location >= 0) {
+        decorate(_alpha_ref_var_id, spv::DecorationLocation, (uint32_t)_ref_location);
       }
       }
     }
     }
     uint32_t alpha = op_load(op_access_chain(_var_id, {define_int_constant(3)}));
     uint32_t alpha = op_load(op_access_chain(_var_id, {define_int_constant(3)}));

+ 4 - 14
panda/src/shaderpipeline/spirVInjectAlphaTestPass.h

@@ -18,6 +18,7 @@
 
 
 /**
 /**
  * Injects an alpha test before all return statements of fragment entry points.
  * Injects an alpha test before all return statements of fragment entry points.
+ * The alpha test is always performed on the output with location 0.
  */
  */
 class EXPCL_PANDA_SHADERPIPELINE SpirVInjectAlphaTestPass final : public SpirVTransformPass {
 class EXPCL_PANDA_SHADERPIPELINE SpirVInjectAlphaTestPass final : public SpirVTransformPass {
 public:
 public:
@@ -33,7 +34,8 @@ public:
     M_always            // Always draw.
     M_always            // Always draw.
   };
   };
 
 
-  SpirVInjectAlphaTestPass(Mode mode, int location = -1) : _mode(mode), _location(location) {}
+  SpirVInjectAlphaTestPass(Mode mode, int ref_location = -1) :
+    _mode(mode), _ref_location(ref_location) {}
 
 
   virtual bool transform_entry_point(spv::ExecutionModel model, uint32_t id, const char *name, const uint32_t *var_ids, uint16_t num_vars);
   virtual bool transform_entry_point(spv::ExecutionModel model, uint32_t id, const char *name, const uint32_t *var_ids, uint16_t num_vars);
   virtual bool begin_function(Instruction op);
   virtual bool begin_function(Instruction op);
@@ -42,7 +44,7 @@ public:
 
 
 public:
 public:
   const Mode _mode;
   const Mode _mode;
-  const int _location;
+  const int _ref_location;
 
 
   uint32_t _alpha_ref_var_id = 0;
   uint32_t _alpha_ref_var_id = 0;
 
 
@@ -51,18 +53,6 @@ private:
 
 
   // For each entry point we access, the output variable to test.
   // For each entry point we access, the output variable to test.
   pmap<uint32_t, uint32_t> _entry_points;
   pmap<uint32_t, uint32_t> _entry_points;
-
-  // This stores the type IDs of all the types that (indirectly) contain the
-  // type we want to unpack.  For each affected struct, access chains (struct
-  // members only) leading to the hoisted type in question, as well as the
-  // type that the wrapped additional variables should have.
-  pmap<uint32_t, pvector<std::pair<const ShaderType *, AccessChain> > > _affected_types;
-  pset<uint32_t> _affected_pointer_types;
-
-public:
-  // For each access chain consisting only of struct members
-  // (prefixed by a variable id), map to the variable that has been hoisted
-  pmap<AccessChain, uint32_t> _hoisted_vars;
 };
 };
 
 
 #endif
 #endif