Skip to content

Refactor Mixins and other inheritance #4226

@greggman

Description

@greggman

I'm running into issues that it's often hard to refactor or change things because of the hierarchy of inheritance with

GPUTest
ValidationTest
ShaderValdiationTest
TextureTestMixin

It's not clear why many of these things are implemented via inheritance instead of as just standalone functions or static functions on a class or a collection of object methods

For example

TextureTestMixin ...

    expectTexelViewComparisonIsOkInTexture(
      src: GPUTexelCopyTextureInfo,
      exp: TexelView,
      size: GPUExtent3D,
      comparisonOptions = {
        maxIntDiff: 0,
        maxDiffULPsForNormFormat: 1,
        maxDiffULPsForFloatFormat: 1,
      }
    ): void {
      this.eventualExpectOK(
        textureContentIsOKByT2B(this, src, size, { expTexelView: exp }, comparisonOptions)
      );
    } 

Can just as easily be implemented as

    function expectTexelViewComparisonIsOkInTexture(
      t: GPUTest,
      src: GPUTexelCopyTextureInfo,
      exp: TexelView,
      size: GPUExtent3D,
      comparisonOptions = {
        maxIntDiff: 0,
        maxDiffULPsForNormFormat: 1,
        maxDiffULPsForFloatFormat: 1,
      }
    ): void {
      t.eventualExpectOK(
        textureContentIsOKByT2B(t, src, size, { expTexelView: exp }, comparisonOptions)
      );
    } 

But now it's not inherited.

If it's important we could put bunch of these on objects/classes so there is less importing required.

// texture_test_helpers.ts
export default {
  createTextureFromTexelView(...),
  expectTexelViewComparisonIsOkInTexture(...),
  createTextureFromTexelViewsMultipleMipmaps(...),
  ...
}

Then

import tHelpers from './texture_test_helpers.ts`

...
  const tex = tHelpers.createTextureFromTexelView(...);

In any case, it feels like separating functions out from the inheritance hierarchy makes them more usable in more places.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions