void test() { /* Matrix: * 0 1 0 * 0 | 0 * 1 & 1 * 0 1 0 */ printf("Test: Sblock Matrix\n"); write_lut(LUT_SELF, 0); write_lut(LUT_AND4, 1); write_lut(LUT_OR, 2); write_type(0,1,1, 2); write_type(0,2,1, 1); write_state(0,0,1, 1); write_state(0,2,0, 1); write_state(0,2,2, 1); write_state(0,3,1, 1); swap_cell_storage(); config(); step(1); readback(); swap_cell_storage(); read_state(0,0,1); read_state(0,1,1); read_state(0,2,1); read_state(0,3,1); step(1); readback(); swap_cell_storage(); read_state(0,0,1); read_state(0,1,1); read_state(0,2,1); read_state(0,3,1); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(0, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); }
void swap_run_swap() { swap_cell_storage(); config(); step(7); readback(); swap_cell_storage(); }
/* * Print an error message to the error output (either stderr, or * if trapping errors, to the error trap file). We precede this * with the program's name and an optional string (a0), then use * the format and variable argument list, then append an optional * Unix error string. Finally, if errors are being trapped, we * pass the error text and the quit flag to the trap function. * * In the interest of `look and feel', if errors are being trapped, * the program name is omitted. */ static void verror(int quit, const char *a0, const char *fmt, va_list l, int e) { register FILE *fp = trap_file; /* print to the trap file, if any, else stderr */ if ((fp = trap_file) != NULL) rewind(fp); /* now can write */ else { fp = stderr; (void) fflush(fp); } if (trap_file == NULL) (void) fprintf(fp, "%s: ", ProgName); if (a0) (void) fprintf(fp, "%s", a0); (void) vfprintf(fp, fmt, l); if (e) (void) fprintf(fp, ": %s", strerror(e)); (void) putc('\n', fp); (void) fflush(fp); if (trap_file != NULL) (*trap_fn)(quit, readback()); if (quit) exit(quit); }
void DebugOutput::process(struct GPUOutputBatch& gpu_batch, const AlignmentMate mate, const AlignmentScore score) { // read back the data into the CPU for later processing readback(cpu_batch, gpu_batch, mate, score); }
// Draw a blurred version of the provided path. // Return the right half of the middle row in 'result'. static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma, int* result, int resultCount) { SkBitmap bitmap; bitmap.allocN32Pixels(resultCount, 30); SkCanvas canvas(bitmap); blur_path(&canvas, path, gaussianSigma); readback(&canvas, result, resultCount); }
// temporary disable; see below for explanation static bool gpu_blur_path(GrContext* context, const SkPath& path, SkScalar gaussianSigma, int* result, int resultCount) { GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = resultCount; desc.fHeight = 30; desc.fSampleCnt = 0; SkAutoTUnref<GrTexture> texture(grContext->createTexture(desc, false, nullptr, 0)); SkAutoTUnref<SkGpuDevice> device(new SkGpuDevice (grContext, texture.get())); SkCanvas canvas(device.get()); blur_path(&canvas, path, gaussianSigma); readback(&canvas, result, resultCount); return true; }
// temporary disable; see below for explanation static bool gpu_blur_path(GrContextFactory* factory, const SkPath& path, SkScalar gaussianSigma, int* result, int resultCount) { GrContext* grContext = factory->get(GrContextFactory::kNative_GLContextType); if (NULL == grContext) { return false; } GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = resultCount; desc.fHeight = 30; desc.fSampleCnt = 0; SkAutoTUnref<GrTexture> texture(grContext->createUncachedTexture(desc, NULL, 0)); SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (grContext, texture.get()))); SkCanvas canvas(device.get()); blur_path(&canvas, path, gaussianSigma); readback(&canvas, result, resultCount); return true; }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { unsigned char alphaData[X_SIZE * Y_SIZE]; bool match; static const size_t kRowBytes[] = {0, X_SIZE, X_SIZE + 1, 2 * X_SIZE - 1}; for (int rt = 0; rt < 2; ++rt) { GrSurfaceDesc desc; // let Skia know we will be using this texture as a render target desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; // it is a single channel texture desc.fConfig = kAlpha_8_GrPixelConfig; desc.fWidth = X_SIZE; desc.fHeight = Y_SIZE; // We are initializing the texture with zeros here memset(alphaData, 0, X_SIZE * Y_SIZE); SkAutoTUnref<GrTexture> texture( context->textureProvider()->createTexture(desc, SkBudgeted::kNo , alphaData, 0)); if (!texture) { if (!rt) { ERRORF(reporter, "Could not create alpha texture."); } continue; } // create a distinctive texture for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { alphaData[y * X_SIZE + x] = y*X_SIZE+x; } } for (auto rowBytes : kRowBytes) { // upload the texture (do per-rowbytes iteration because we may overwrite below). texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, alphaData, 0); size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]); // clear readback to something non-zero so we can detect readback failures memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE); // read the texture back texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, readback.get(), rowBytes); // make sure the original & read back versions match SkString msg; msg.printf("rt:%d, rb:%d", rt, SkToU32(rowBytes)); validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZeroRowBytes, alphaData, msg); // Now try writing on the single channel texture (if we could create as a RT). if (texture->asRenderTarget()) { SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create( texture->asRenderTarget(), &props, SkGpuDevice::kUninit_InitContents)); SkCanvas canvas(device); SkPaint paint; const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10); paint.setColor(SK_ColorWHITE); canvas.drawRect(rect, paint); memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE); texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, readback.get(), rowBytes); match = true; for (int y = 0; y < Y_SIZE && match; ++y) { for (int x = 0; x < X_SIZE && match; ++x) { uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x]; if (0xFF != rbValue) { ERRORF(reporter, "Failed alpha readback after clear. Expected: 0xFF, Got: 0x%02x" " at (%d,%d), rb:%d", rbValue, x, y, SkToU32(rowBytes)); match = false; } } } } } } static const GrPixelConfig kRGBAConfigs[] { kRGBA_8888_GrPixelConfig, kBGRA_8888_GrPixelConfig, kSRGBA_8888_GrPixelConfig }; for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { alphaData[y * X_SIZE + x] = y*X_SIZE+x; } } // Attempt to read back just alpha from a RGBA/BGRA texture. Once with a texture-only src and // once with a render target. for (auto cfg : kRGBAConfigs) { for (int rt = 0; rt < 2; ++rt) { GrSurfaceDesc desc; desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; desc.fConfig = cfg; desc.fWidth = X_SIZE; desc.fHeight = Y_SIZE; uint32_t rgbaData[X_SIZE * Y_SIZE]; // Make the alpha channel of the rgba texture come from alphaData. for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { rgbaData[y * X_SIZE + x] = GrColorPackRGBA(6, 7, 8, alphaData[y * X_SIZE + x]); } } SkAutoTUnref<GrTexture> texture( context->textureProvider()->createTexture(desc, SkBudgeted::kNo, rgbaData, 0)); if (!texture) { // We always expect to be able to create a RGBA texture if (!rt && kRGBA_8888_GrPixelConfig == desc.fConfig) { ERRORF(reporter, "Failed to create RGBA texture."); } continue; } for (auto rowBytes : kRowBytes) { size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]); // Clear so we don't accidentally see values from previous iteration. memset(readback.get(), 0x0, nonZeroRowBytes * Y_SIZE); // read the texture back texture->readPixels(0, 0, desc.fWidth, desc.fHeight, kAlpha_8_GrPixelConfig, readback.get(), rowBytes); // make sure the original & read back versions match SkString msg; msg.printf("rt:%d, rb:%d", rt, SkToU32(rowBytes)); validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZeroRowBytes, alphaData, msg); } } } }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); unsigned char alphaData[X_SIZE * Y_SIZE]; static const int kClearValue = 0x2; bool match; static const size_t kRowBytes[] = {0, X_SIZE, X_SIZE + 1, 2 * X_SIZE - 1}; { GrSurfaceDesc desc; desc.fFlags = kNone_GrSurfaceFlags; desc.fConfig = kAlpha_8_GrPixelConfig; // it is a single channel texture desc.fWidth = X_SIZE; desc.fHeight = Y_SIZE; // We are initializing the texture with zeros here memset(alphaData, 0, X_SIZE * Y_SIZE); sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc, SkBudgeted::kNo, alphaData, 0)); if (!proxy) { ERRORF(reporter, "Could not create alpha texture."); return; } sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext( std::move(proxy), nullptr)); const SkImageInfo ii = SkImageInfo::MakeA8(X_SIZE, Y_SIZE); sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii)); // create a distinctive texture for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { alphaData[y * X_SIZE + x] = y*X_SIZE+x; } } for (auto rowBytes : kRowBytes) { // upload the texture (do per-rowbytes iteration because we may overwrite below). bool result = sContext->writePixels(ii, alphaData, 0, 0, 0); REPORTER_ASSERT_MESSAGE(reporter, result, "Initial A8 writePixels failed"); size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; std::unique_ptr<uint8_t[]> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]); // clear readback to something non-zero so we can detect readback failures memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE); // read the texture back result = sContext->readPixels(ii, readback.get(), rowBytes, 0, 0); REPORTER_ASSERT_MESSAGE(reporter, result, "Initial A8 readPixels failed"); // make sure the original & read back versions match SkString msg; msg.printf("rb:%d A8", SkToU32(rowBytes)); validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZeroRowBytes, alphaData, msg); // Now try writing to a single channel surface (if we could create one). if (surf) { SkCanvas* canvas = surf->getCanvas(); SkPaint paint; const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10); paint.setColor(SK_ColorWHITE); canvas->drawRect(rect, paint); memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE); result = surf->readPixels(ii, readback.get(), nonZeroRowBytes, 0, 0); REPORTER_ASSERT_MESSAGE(reporter, result, "A8 readPixels after clear failed"); match = true; for (int y = 0; y < Y_SIZE && match; ++y) { for (int x = 0; x < X_SIZE && match; ++x) { uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x]; if (0xFF != rbValue) { ERRORF(reporter, "Failed alpha readback after clear. Expected: 0xFF, Got: 0x%02x" " at (%d,%d), rb:%d", rbValue, x, y, SkToU32(rowBytes)); match = false; } } } } } } static const GrPixelConfig kRGBAConfigs[] { kRGBA_8888_GrPixelConfig, kBGRA_8888_GrPixelConfig, kSRGBA_8888_GrPixelConfig }; for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { alphaData[y * X_SIZE + x] = y*X_SIZE+x; } } const SkImageInfo dstInfo = SkImageInfo::Make(X_SIZE, Y_SIZE, kAlpha_8_SkColorType, kPremul_SkAlphaType); // Attempt to read back just alpha from a RGBA/BGRA texture. Once with a texture-only src and // once with a render target. for (auto config : kRGBAConfigs) { for (int rt = 0; rt < 2; ++rt) { GrSurfaceDesc desc; desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; desc.fConfig = config; desc.fWidth = X_SIZE; desc.fHeight = Y_SIZE; uint32_t rgbaData[X_SIZE * Y_SIZE]; // Make the alpha channel of the rgba texture come from alphaData. for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { rgbaData[y * X_SIZE + x] = GrColorPackRGBA(6, 7, 8, alphaData[y * X_SIZE + x]); } } sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc, SkBudgeted::kNo, rgbaData, 0); if (!proxy) { // We always expect to be able to create a RGBA texture if (!rt && kRGBA_8888_GrPixelConfig == desc.fConfig) { ERRORF(reporter, "Failed to create RGBA texture."); } continue; } sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext( std::move(proxy), nullptr); for (auto rowBytes : kRowBytes) { size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; std::unique_ptr<uint8_t[]> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]); // Clear so we don't accidentally see values from previous iteration. memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE); // read the texture back bool result = sContext->readPixels(dstInfo, readback.get(), rowBytes, 0, 0); REPORTER_ASSERT_MESSAGE(reporter, result, "8888 readPixels failed"); // make sure the original & read back versions match SkString msg; msg.printf("rt:%d, rb:%d 8888", rt, SkToU32(rowBytes)); validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZeroRowBytes, alphaData, msg); } } } }