Commit e112df3c authored by Jeff Gilbert's avatar Jeff Gilbert
Browse files

Bug 1692832 - isTexUploadFromPbo iff isPboBound. r=lsalzman, a=RyanVM

INVALID_OPERATION otherwise.

Differential Revision: https://phabricator.services.mozilla.com/D107592
parent 5e781b8c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -205,6 +205,16 @@ void WebGLContext::TexImage(GLenum imageTarget, uint32_t level,
  const WebGLContext::FuncScope funcScope(
      *this, bool(respecFormat) ? "texImage" : "texSubImage");

  const bool isUploadFromPbo = bool(src.mPboOffset);
  const bool isPboBound = bool(mBoundPixelUnpackBuffer);
  if (isUploadFromPbo != isPboBound) {
    GenerateError(LOCAL_GL_INVALID_OPERATION,
                  "Tex upload from %s but PIXEL_UNPACK_BUFFER %s bound.",
                  isUploadFromPbo ? "PBO" : "non-PBO",
                  isPboBound ? "was" : "was not");
    return;
  }

  if (respecFormat) {
    offset = {0, 0, 0};
  }
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ skip-if = os == "win" && os_version == "10.0" # Bug 1302199
[test_privileged_exts.html]
[test_renderer_strings.html]
[test_sab_with_webgl.html]
[test_tex_pbo.html]
[test_texsubimage_float.html]
[test_uninit_data.html]
[test_webgl_available.html]
+100 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
  <head>
    <meta charset='UTF-8'>
    <script src='/tests/SimpleTest/SimpleTest.js'></script>
    <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
  </head>
  <body>
    <script>

function shouldBe(testStr, refStr) {
  ok(testStr == refStr, 'Expected "' + refStr + '", was "' + testStr + '".');
}

function getErrorStr(gl, err) {
  if (!err) return "NO_ERROR";
  for (const k in gl) {
    const v = gl[k];
    if (v == err) {
      return k;
    }
  }
  return `<${err}>`;
}

function glErrorShouldBe(gl, expected, opt_info) {
  if (opt_info) {
    opt_info = opt_info + ': '
  } else {
    opt_info = '';
  }

  if (!expected.length) {
    expected = [expected];
  }
  expected = expected.map(x => getErrorStr(gl, x));
  let was = gl.getError();
  was = getErrorStr(gl, was);
  console.log(expected);
  ok(expected.includes(was),
    `${opt_info}Expected gl.getError() in [${expected}], was ${was}.`);
}

(() => {
  const gl = document.createElement('canvas').getContext('webgl2');
  if (!gl) {
    todo(false, 'No webgl2, skipping...');
    return;
  }
  const pbo = gl.createBuffer();
  gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, pbo);

  const PBO_DATA = new Uint8Array([
    255, 0, 0, 255,
    0, 255, 0, 255,
  ]);
  gl.bufferData(gl.PIXEL_UNPACK_BUFFER, PBO_DATA, gl.STATIC_DRAW);

  const tex = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, tex);

  const fb = gl.createFramebuffer();
  gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);

  const readback = new Uint8Array(4);

  const PBO_LIST = [null, pbo];
  for (const cur of PBO_LIST) {
    gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, cur);

    function tryUpload(arg, expectedReadback) {
      let argType = typeof(arg);
      if (arg === null) {
        argType = 'null';
      }
      const argForPbo = (argType == 'number');
      const pboBound = !!cur;
      const expectedErr = (argForPbo == pboBound) ? 0 : gl.INVALID_OPERATION;
      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
                    arg);
      const with_without = pboBound ? 'with' : 'without';
      glErrorShouldBe(gl, expectedErr, `${with_without} pbo, texImage(..., ${argType}("${arg}"))`);

      if (expectedErr) return;
      gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, readback);
      shouldBe(expectedReadback.toString(), readback.toString());
    }

    const CPU_DATA = new Uint8Array([255, 255, 0, 255]);

    tryUpload(null, [0,0,0,0]);
    tryUpload(CPU_DATA, CPU_DATA);
    tryUpload(0, PBO_DATA.slice(0,4));
    //tryUpload(4, PBO_DATA.slice(4));
  }
})();
    </script>
  </body>
</html>