Changeset 273516 in webkit
- Timestamp:
- Feb 25, 2021, 3:25:29 PM (4 years ago)
- Location:
- trunk/Source/ThirdParty/ANGLE
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/ThirdParty/ANGLE/ChangeLog
r273200 r273516 1 2021-02-25 Kyle Piddington <kpiddington@apple.com> 2 3 Fix crashes in fast/canvas/webgl/texImage video tests 4 Refactor IOSurfaceSurfaceMtl to match open source implementation. 5 Additional cleanup 6 7 https://bugs.webkit.org/show_bug.cgi?id=222331 8 9 Reviewed by Dean Jackson. 10 11 12 * src/libANGLE/renderer/metal/ContextMtl.h: 13 * src/libANGLE/renderer/metal/ContextMtl.mm: 14 (rx::ContextMtl::onBackbufferResized): 15 * src/libANGLE/renderer/metal/DisplayMtl.mm: 16 (rx::DisplayMtl::createPbufferSurface): 17 (rx::DisplayMtl::createPbufferFromClientBuffer): 18 * src/libANGLE/renderer/metal/FrameBufferMtl.h: 19 (rx::FramebufferMtl::getAttachedBackbuffer const): 20 * src/libANGLE/renderer/metal/FrameBufferMtl.mm: 21 (rx::FramebufferMtl::FramebufferMtl): 22 * src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h: 23 * src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm: 24 (rx::IOSurfaceSurfaceMtl::IOSurfaceSurfaceMtl): 25 (rx::IOSurfaceSurfaceMtl::~IOSurfaceSurfaceMtl): 26 (rx::IOSurfaceSurfaceMtl::bindTexImage): 27 (rx::IOSurfaceSurfaceMtl::releaseTexImage): 28 (rx::IOSurfaceSurfaceMtl::getAttachmentRenderTarget): 29 (rx::IOSurfaceSurfaceMtl::ensureColorTextureCreated): 30 (rx::IOSurfaceSurfaceMtl::ValidateAttributes): 31 * src/libANGLE/renderer/metal/SurfaceMtl.h: 32 (rx::SurfaceMtl::getColorTexture): 33 (rx::SurfaceMtl::getSamples const): 34 (rx::SurfaceMtl::hasRobustResourceInit const): 35 (rx::WindowSurfaceMtl::preserveBuffer const): 36 * src/libANGLE/renderer/metal/SurfaceMtl.mm: 37 (rx::SurfaceMtl::SurfaceMtl): 38 * src/libANGLE/renderer/metal/TextureMtl.h: 39 * src/libANGLE/renderer/metal/TextureMtl.mm: 40 (rx::TextureMtl::ensureTextureCreated): 41 (rx::TextureMtl::ensureSamplerStateCreated): 42 (rx::TextureMtl::bindTexImage): 43 (rx::TextureMtl::releaseTexImage): 44 (rx::TextureMtl::getAttachmentRenderTarget): 45 * src/libANGLE/renderer/metal/mtl_common.h: 46 1 47 2021-02-19 Kyle Piddington <kpiddington@apple.com> 2 48 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.h
r270733 r273516 30 30 class ProgramMtl; 31 31 class RenderTargetMtl; 32 class SurfaceMtlProtocol;33 32 class BufferMtl; 33 class WindowSurfaceMtl; 34 34 35 35 class ContextMtl : public ContextImpl, public mtl::Context … … 293 293 FramebufferMtl *framebuffer, 294 294 bool renderPassChanged); 295 void onBackbufferResized(const gl::Context *context, SurfaceMtlProtocol *backbuffer);295 void onBackbufferResized(const gl::Context *context, WindowSurfaceMtl *backbuffer); 296 296 297 297 // Invoke by QueryMtl -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm
r273200 r273516 1933 1933 } 1934 1934 1935 void ContextMtl::onBackbufferResized(const gl::Context *context, SurfaceMtlProtocol *backbuffer)1935 void ContextMtl::onBackbufferResized(const gl::Context *context, WindowSurfaceMtl *backbuffer) 1936 1936 { 1937 1937 const gl::State &glState = getState(); -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/DisplayMtl.mm
r273032 r273516 271 271 const egl::AttributeMap &attribs) 272 272 { 273 UNIMPLEMENTED(); 274 return static_cast<SurfaceImpl *>(0); 273 return new PBufferSurfaceMtl(this, state, attribs); 275 274 } 276 275 … … 280 279 const egl::AttributeMap &attribs) 281 280 { 282 return new IOSurfaceSurfaceMtl(this, state, clientBuffer, attribs); 281 switch (buftype) 282 { 283 case EGL_IOSURFACE_ANGLE: 284 return new IOSurfaceSurfaceMtl(this, state, clientBuffer, attribs); 285 break; 286 default: 287 UNREACHABLE(); 288 return nullptr; 289 } 283 290 } 284 291 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/FrameBufferMtl.h
r270733 r273516 24 24 } // namespace mtl 25 25 class ContextMtl; 26 class SurfaceMtl;26 class WindowSurfaceMtl; 27 27 28 28 class FramebufferMtl : public FramebufferImpl … … 31 31 explicit FramebufferMtl(const gl::FramebufferState &state, 32 32 bool flipY, 33 SurfaceMtlProtocol *backbuffer);33 WindowSurfaceMtl *backbuffer); 34 34 ~FramebufferMtl() override; 35 35 void destroy(const gl::Context *context) override; … … 100 100 gl::Rectangle getCompleteRenderArea() const; 101 101 int getSamples() const; 102 SurfaceMtlProtocol *getAttachedBackbuffer() const { return mBackbuffer; }102 WindowSurfaceMtl *getAttachedBackbuffer() const { return mBackbuffer; } 103 103 104 104 bool renderPassHasStarted(ContextMtl *contextMtl) const; … … 222 222 bool mRenderPassCleanStart = false; 223 223 224 SurfaceMtlProtocol *mBackbuffer = nullptr;224 WindowSurfaceMtl *mBackbuffer = nullptr; 225 225 const bool mFlipY = false; 226 226 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/FrameBufferMtl.mm
r271080 r273516 57 57 FramebufferMtl::FramebufferMtl(const gl::FramebufferState &state, 58 58 bool flipY, 59 SurfaceMtlProtocol *backbuffer)59 WindowSurfaceMtl *backbuffer) 60 60 : FramebufferImpl(state), mBackbuffer(backbuffer), mFlipY(flipY) 61 61 { -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h
r273200 r273516 23 23 class DisplayMTL; 24 24 25 class IOSurfaceSurfaceMtl : public SurfaceMtlProtocol 25 // Offscreen created from IOSurface 26 class IOSurfaceSurfaceMtl : public OffscreenSurfaceMtl 26 27 { 27 28 public: … … 32 33 ~IOSurfaceSurfaceMtl() override; 33 34 34 void destroy(const egl::Display *display) override;35 36 egl::Error initialize(const egl::Display *display) override;37 FramebufferImpl *createDefaultFramebuffer(const gl::Context *context,38 const gl::FramebufferState &state) override;39 40 egl::Error makeCurrent(const gl::Context *context) override;41 egl::Error unMakeCurrent(const gl::Context *context) override;42 egl::Error swap(const gl::Context *context) override;43 egl::Error postSubBuffer(const gl::Context *context,44 EGLint x,45 EGLint y,46 EGLint width,47 EGLint height) override;48 49 egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override;50 35 egl::Error bindTexImage(const gl::Context *context, 51 36 gl::Texture *texture, 52 37 EGLint buffer) override; 53 38 egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override; 54 egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override;55 egl::Error getMscRate(EGLint *numerator, EGLint *denominator) override;56 void setSwapInterval(EGLint interval) override;57 void setFixedWidth(EGLint width) override;58 void setFixedHeight(EGLint height) override;59 60 // Width can change when the client window resizes.61 EGLint getWidth() const override;62 // Height can change when the client window resizes.63 EGLint getHeight() const override;64 65 EGLint isPostSubBufferSupported() const override;66 EGLint getSwapBehavior() const override;67 39 68 40 angle::Result getAttachmentRenderTarget(const gl::Context *context, … … 72 44 FramebufferAttachmentRenderTarget **rtOut) override; 73 45 74 angle::Result ensureCurrentDrawableObtained(const gl::Context *context) override; 75 angle::Result ensureCurrentDrawableObtained(const gl::Context *context, 76 bool *newDrawableOut) override; 77 int getSamples() const override { return 1; } 78 bool preserveBuffer() const override { return false; } 79 mtl::TextureRef getTexture(const gl::Context *context); 80 bool hasRobustResourceInit() const override { return false; } 81 angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context) override 82 { 83 return angle::Result::Continue; 84 } 85 const mtl::TextureRef &getColorTexture() override { return mIOSurfaceTexture; } 46 static bool ValidateAttributes(EGLClientBuffer buffer, const egl::AttributeMap &attribs); 86 47 87 48 private: 88 angle::Result ensureTextureCreated(const gl::Context *context); 89 angle::Result createBackingTexture(const gl::Context *context); 90 angle::Result createTexture(const gl::Context *context, 91 const mtl::Format &format, 92 uint32_t width, 93 uint32_t height, 94 bool renderTargetOnly, 95 mtl::TextureRef *textureOut); 49 angle::Result ensureColorTextureCreated(const gl::Context *context); 96 50 97 angle::Result initializeAlphaChannel(const gl::Context *context, GLuint texture);98 99 #if defined(ANGLE_PLATFORM_IOS_SIMULATOR)100 IOSurfaceLockOptions getIOSurfaceLockOptions() const;101 #endif102 103 ContextMtl *contextMTL;104 51 IOSurfaceRef mIOSurface; 105 GLint mGLInternalFormat; 106 mtl::TextureRef mIOSurfaceTexture; 107 mtl::TextureRef mIOSurfaceTextureView; 108 mtl::Format mFormat; 109 mtl::Format mInternalFormat; 110 RenderTargetMtl mRenderTarget; 111 bool mIOSurfaceTextureCreated; 112 int mWidth; 113 int mHeight; 114 int mPlane; 115 int mFormatIndex; 116 int mRowStrideInPixels; 117 118 #if defined(ANGLE_PLATFORM_IOS_SIMULATOR) 119 GLuint mBoundTextureID; 120 bool mUploadFromIOSurface; 121 bool mReadbackToIOSurface; 122 #endif 52 NSUInteger mIOSurfacePlane; 53 int mIOSurfaceFormatIdx; 123 54 }; 124 55 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm
r273200 r273516 36 36 GLenum internalFormat; 37 37 GLenum type; 38 angle::FormatID pixelFormat; 39 angle::FormatID internalPixelFormat; 38 size_t componentBytes; 39 40 angle::FormatID nativeAngleFormatId; 40 41 }; 41 42 42 static const IOSurfaceFormatInfo kIOSurfaceFormats[] = { 43 {GL_RED, GL_UNSIGNED_BYTE, angle::FormatID::R8_UNORM, angle::FormatID::R8_UNORM}, 44 {GL_R16UI, GL_UNSIGNED_SHORT, angle::FormatID::R16G16_UINT, angle::FormatID::R16G16_UINT}, 45 {GL_RG, GL_UNSIGNED_BYTE, angle::FormatID::R8G8_UNORM, angle::FormatID::R8G8_UNORM}, 46 {GL_RGB, GL_UNSIGNED_BYTE, angle::FormatID::R8G8B8A8_UNORM, angle::FormatID::B8G8R8A8_UNORM}, 47 {GL_BGRA_EXT, GL_UNSIGNED_BYTE, angle::FormatID::B8G8R8A8_UNORM, 48 angle::FormatID::B8G8R8A8_UNORM}, 49 {GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV, angle::FormatID::R10G10B10A2_UNORM, 50 angle::FormatID::R10G10B10A2_UNORM}, 51 {GL_RGBA, GL_HALF_FLOAT, angle::FormatID::R16G16B16A16_FLOAT, 52 angle::FormatID::R16G16B16A16_FLOAT}, 53 }; 43 // clang-format off 44 // NOTE(hqle): Support R16_UINT once GLES3 is complete. 45 constexpr std::array<IOSurfaceFormatInfo, 8> kIOSurfaceFormats = {{ 46 {GL_RED, GL_UNSIGNED_BYTE, 1, angle::FormatID::R8_UNORM}, 47 {GL_RED, GL_UNSIGNED_SHORT, 2, angle::FormatID::R16_UNORM}, 48 {GL_RG, GL_UNSIGNED_BYTE, 2, angle::FormatID::R8G8_UNORM}, 49 {GL_RG, GL_UNSIGNED_SHORT, 4, angle::FormatID::R16G16_UNORM}, 50 {GL_RGB, GL_UNSIGNED_BYTE, 4, angle::FormatID::B8G8R8A8_UNORM}, 51 {GL_BGRA_EXT, GL_UNSIGNED_BYTE, 4, angle::FormatID::B8G8R8A8_UNORM}, 52 {GL_RGBA, GL_HALF_FLOAT, 8, angle::FormatID::R16G16B16A16_FLOAT}, 53 {GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV, 4, angle::FormatID::B10G10R10A2_UNORM}, 54 }}; 55 // clang-format on 54 56 55 57 int FindIOSurfaceFormatIndex(GLenum internalFormat, GLenum type) 56 58 { 57 for ( size_t i = 0; i < static_cast<size_t>(ArraySize(kIOSurfaceFormats)); ++i)59 for (int i = 0; i < static_cast<int>(kIOSurfaceFormats.size()); ++i) 58 60 { 59 61 const auto &formatInfo = kIOSurfaceFormats[i]; 60 62 if (formatInfo.internalFormat == internalFormat && formatInfo.type == type) 61 63 { 62 return static_cast<int>(i);64 return i; 63 65 } 64 66 } 65 67 return -1; 66 68 } 67 68 // TODO(jcunningham) : refactor this and surfacemtl to reduce copy+pasted code69 69 70 70 ANGLE_MTL_UNUSED … … 231 231 } // anonymous namespace 232 232 233 // IOSurfaceSurfaceMtl implementation. 233 234 IOSurfaceSurfaceMtl::IOSurfaceSurfaceMtl(DisplayMtl *display, 234 235 const egl::SurfaceState &state, 235 236 EGLClientBuffer buffer, 236 237 const egl::AttributeMap &attribs) 237 : SurfaceMtlProtocol(state) 238 { 239 // Keep reference to the IOSurface so it doesn't get deleted while the pbuffer exists. 240 mIOSurface = reinterpret_cast<IOSurfaceRef>(buffer); 238 : OffscreenSurfaceMtl(display, state, attribs), mIOSurface((__bridge IOSurfaceRef)(buffer)) 239 { 241 240 CFRetain(mIOSurface); 242 241 243 // Extract attribs useful for the call to EAGLTexImageIOSurface2D 244 mWidth = static_cast<int>(attribs.get(EGL_WIDTH)); 245 mHeight = static_cast<int>(attribs.get(EGL_HEIGHT)); 246 mPlane = static_cast<int>(attribs.get(EGL_IOSURFACE_PLANE_ANGLE)); 247 // Hopefully the number of bytes per row is always an integer number of pixels. We use 248 // glReadPixels to fill the IOSurface in the simulator and it can only support strides that are 249 // an integer number of pixels. 250 ASSERT(IOSurfaceGetBytesPerRowOfPlane(mIOSurface, mPlane) % 251 IOSurfaceGetBytesPerElementOfPlane(mIOSurface, mPlane) == 252 0); 253 mRowStrideInPixels = static_cast<int>(IOSurfaceGetBytesPerRowOfPlane(mIOSurface, mPlane) / 254 IOSurfaceGetBytesPerElementOfPlane(mIOSurface, mPlane)); 242 mIOSurfacePlane = static_cast<int>(attribs.get(EGL_IOSURFACE_PLANE_ANGLE)); 255 243 256 244 EGLAttrib internalFormat = attribs.get(EGL_TEXTURE_INTERNAL_FORMAT_ANGLE); 257 245 EGLAttrib type = attribs.get(EGL_TEXTURE_TYPE_ANGLE); 258 m FormatIndex =246 mIOSurfaceFormatIdx = 259 247 FindIOSurfaceFormatIndex(static_cast<GLenum>(internalFormat), static_cast<GLenum>(type)); 260 ASSERT(mFormatIndex >= 0); 261 mFormat = display->getPixelFormat(kIOSurfaceFormats[mFormatIndex].pixelFormat); 262 mInternalFormat = display->getPixelFormat(kIOSurfaceFormats[mFormatIndex].internalPixelFormat); 263 mGLInternalFormat = kIOSurfaceFormats[mFormatIndex].internalFormat; 264 } 265 248 ASSERT(mIOSurfaceFormatIdx >= 0); 249 250 mColorFormat = 251 display->getPixelFormat(kIOSurfaceFormats[mIOSurfaceFormatIdx].nativeAngleFormatId); 252 } 266 253 IOSurfaceSurfaceMtl::~IOSurfaceSurfaceMtl() 267 254 { 268 StopFrameCapture();269 255 if (mIOSurface != nullptr) 270 256 { … … 272 258 mIOSurface = nullptr; 273 259 } 274 }275 276 void IOSurfaceSurfaceMtl::destroy(const egl::Display *display) {}277 278 egl::Error IOSurfaceSurfaceMtl::initialize(const egl::Display *display)279 {280 DisplayMtl *displayMtl = mtl::GetImpl(display);281 id<MTLDevice> metalDevice = displayMtl->getMetalDevice();282 283 StartFrameCapture(metalDevice, displayMtl->cmdQueue().get());284 return egl::NoError();285 }286 287 FramebufferImpl *IOSurfaceSurfaceMtl::createDefaultFramebuffer(const gl::Context *context,288 const gl::FramebufferState &state)289 {290 auto fbo = new FramebufferMtl(state, /* flipY */ true, /* backbuffer */ this);291 return fbo;292 }293 294 egl::Error IOSurfaceSurfaceMtl::makeCurrent(const gl::Context *context)295 {296 ContextMtl *contextMtl = mtl::GetImpl(context);297 StartFrameCapture(contextMtl);298 return egl::NoError();299 }300 301 egl::Error IOSurfaceSurfaceMtl::unMakeCurrent(const gl::Context *context)302 {303 StopFrameCapture();304 return egl::NoError();305 }306 307 egl::Error IOSurfaceSurfaceMtl::swap(const gl::Context *context)308 {309 StopFrameCapture();310 ContextMtl *contextMtl = mtl::GetImpl(context);311 StartFrameCapture(contextMtl);312 return egl::NoError();313 }314 315 egl::Error IOSurfaceSurfaceMtl::postSubBuffer(const gl::Context *context,316 EGLint x,317 EGLint y,318 EGLint width,319 EGLint height)320 {321 UNIMPLEMENTED();322 return egl::EglBadAccess();323 }324 325 egl::Error IOSurfaceSurfaceMtl::querySurfacePointerANGLE(EGLint attribute, void **value)326 {327 UNIMPLEMENTED();328 return egl::EglBadAccess();329 260 } 330 261 … … 333 264 EGLint buffer) 334 265 { 335 336 angle::Result res = createBackingTexture(context); 337 if (res == angle::Result::Continue) 338 return egl::NoError(); 339 else 340 return egl::EglBadAccess(); 266 ContextMtl *contextMtl = mtl::GetImpl(context); 267 StartFrameCapture(contextMtl); 268 269 // Initialize offscreen texture if needed: 270 ANGLE_TO_EGL_TRY(ensureColorTextureCreated(context)); 271 272 return OffscreenSurfaceMtl::bindTexImage(context, texture, buffer); 341 273 } 342 274 343 275 egl::Error IOSurfaceSurfaceMtl::releaseTexImage(const gl::Context *context, EGLint buffer) 344 276 { 345 // This will need implementation 346 ContextMtl *contextMtl = mtl::GetImpl(context); 347 if (contextMtl->flush(context) == angle::Result::Continue) 348 { 349 mIOSurfaceTextureCreated = false; 350 return egl::NoError(); 351 } 352 return egl::EglBadAccess(); 353 } 354 355 egl::Error IOSurfaceSurfaceMtl::getSyncValues(EGLuint64KHR *ust, 356 EGLuint64KHR *msc, 357 EGLuint64KHR *sbc) 358 { 359 UNIMPLEMENTED(); 360 return egl::EglBadAccess(); 361 } 362 363 egl::Error IOSurfaceSurfaceMtl::getMscRate(EGLint *numerator, EGLint *denominator) 364 { 365 UNIMPLEMENTED(); 366 return egl::EglBadAccess(); 367 } 368 369 void IOSurfaceSurfaceMtl::setSwapInterval(EGLint interval) 370 { 371 UNIMPLEMENTED(); 372 } 373 374 void IOSurfaceSurfaceMtl::setFixedWidth(EGLint width) 375 { 376 UNIMPLEMENTED(); 377 } 378 379 void IOSurfaceSurfaceMtl::setFixedHeight(EGLint height) 380 { 381 UNIMPLEMENTED(); 382 } 383 384 // width and height can change with client window resizing 385 EGLint IOSurfaceSurfaceMtl::getWidth() const 386 { 387 return static_cast<EGLint>(mWidth); 388 } 389 390 EGLint IOSurfaceSurfaceMtl::getHeight() const 391 { 392 return static_cast<EGLint>(mHeight); 393 } 394 395 EGLint IOSurfaceSurfaceMtl::isPostSubBufferSupported() const 396 { 397 return EGL_FALSE; 398 } 399 400 EGLint IOSurfaceSurfaceMtl::getSwapBehavior() const 401 { 402 return EGL_BUFFER_DESTROYED; 277 egl::Error re = OffscreenSurfaceMtl::releaseTexImage(context, buffer); 278 StopFrameCapture(); 279 return re; 403 280 } 404 281 … … 410 287 FramebufferAttachmentRenderTarget **rtOut) 411 288 { 412 ANGLE_TRY(ensureTextureCreated(context)); 413 *rtOut = &mRenderTarget; 289 // Initialize offscreen texture if needed: 290 ANGLE_TRY(ensureColorTextureCreated(context)); 291 292 return OffscreenSurfaceMtl::getAttachmentRenderTarget(context, binding, imageIndex, samples, 293 rtOut); 294 } 295 296 angle::Result IOSurfaceSurfaceMtl::ensureColorTextureCreated(const gl::Context *context) 297 { 298 if (mColorTexture) 299 { 300 return angle::Result::Continue; 301 } 302 ContextMtl *contextMtl = mtl::GetImpl(context); 303 ANGLE_MTL_OBJC_SCOPE 304 { 305 auto texDesc = 306 [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:mColorFormat.metalFormat 307 width:mSize.width 308 height:mSize.height 309 mipmapped:NO]; 310 311 texDesc.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget; 312 313 id<MTLTexture> texture = 314 [contextMtl->getMetalDevice() newTextureWithDescriptor:texDesc 315 iosurface:mIOSurface 316 plane:mIOSurfacePlane]; 317 318 mColorTexture = mtl::Texture::MakeFromMetal([texture ANGLE_MTL_AUTORELEASE]); 319 } 320 321 mColorRenderTarget.set(mColorTexture, mtl::kZeroNativeMipLevel, 0, mColorFormat); 322 323 if (kIOSurfaceFormats[mIOSurfaceFormatIdx].internalFormat == GL_RGB) 324 { 325 // This format has emulated alpha channel. Initialize texture's alpha channel to 1.0. 326 const mtl::Format &rgbClearFormat = 327 contextMtl->getPixelFormat(angle::FormatID::R8G8B8_UNORM); 328 ANGLE_TRY(mtl::InitializeTextureContentsGPU( 329 context, mColorTexture, rgbClearFormat, 330 mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)), 331 MTLColorWriteMaskAlpha)); 332 333 // Disable subsequent rendering to alpha channel. 334 mColorTexture->setColorWritableMask(MTLColorWriteMaskAll & (~MTLColorWriteMaskAlpha)); 335 } 336 414 337 return angle::Result::Continue; 415 338 } 416 339 417 angle::Result IOSurfaceSurfaceMtl::ensureCurrentDrawableObtained(const gl::Context *context, bool *newDrawableOut) 418 { 419 return angle::Result::Continue; 420 } 421 angle::Result IOSurfaceSurfaceMtl::ensureCurrentDrawableObtained(const gl::Context *context) 422 { 423 return angle::Result::Continue; 424 } 425 426 angle::Result IOSurfaceSurfaceMtl::createBackingTexture(const gl::Context *context) 427 { 428 mtl::TextureRef mTemporarySurfaceRef; 429 ANGLE_TRY(createTexture(context, mFormat, mWidth, mHeight, false, &mTemporarySurfaceRef)); 430 // Create texture view around the base format of the texture. 431 mIOSurfaceTexture = 432 mTemporarySurfaceRef->createViewWithDifferentFormat(MTLPixelFormatBGRA8Unorm); 433 mRenderTarget.set(mIOSurfaceTexture, mtl::kZeroNativeMipLevel, 0, mInternalFormat); 434 435 if (mGLInternalFormat == GL_RGB) 436 { 437 // Disable subsequent rendering to alpha channel. 438 // TODO: Investigate if this allows the higher level alpha masks can 439 // be disabled once this backend is live. 440 mIOSurfaceTexture->setColorWritableMask(MTLColorWriteMaskAll & (~MTLColorWriteMaskAlpha)); 441 } 442 443 mIOSurfaceTextureCreated = true; 444 return angle::Result::Continue; 445 } 446 447 angle::Result IOSurfaceSurfaceMtl::ensureTextureCreated(const gl::Context *context) 448 { 449 if (!mIOSurfaceTextureCreated) 450 { 451 return createBackingTexture(context); 452 } 453 return angle::Result::Continue; 454 } 455 456 mtl::TextureRef IOSurfaceSurfaceMtl::getTexture(const gl::Context *context) 457 { 458 if (ensureCurrentDrawableObtained(context) == angle::Result::Continue) 459 { 460 return mIOSurfaceTexture; 461 } 462 return nullptr; 463 } 464 465 angle::Result IOSurfaceSurfaceMtl::createTexture(const gl::Context *context, 466 const mtl::Format &format, 467 uint32_t width, 468 uint32_t height, 469 bool renderTargetOnly, 470 mtl::TextureRef *textureOut) 471 { 472 ContextMtl *contextMtl = mtl::GetImpl(context); 473 ANGLE_TRY(mtl::Texture::MakeIOSurfaceTexture(contextMtl, format, width, height, mIOSurface, 474 mPlane, textureOut)); 475 return angle::Result::Continue; 476 } 477 } 340 // static 341 bool IOSurfaceSurfaceMtl::ValidateAttributes(EGLClientBuffer buffer, 342 const egl::AttributeMap &attribs) 343 { 344 IOSurfaceRef ioSurface = (__bridge IOSurfaceRef)(buffer); 345 346 // The plane must exist for this IOSurface. IOSurfaceGetPlaneCount can return 0 for non-planar 347 // ioSurfaces but we will treat non-planar like it is a single plane. 348 size_t surfacePlaneCount = std::max(size_t(1), IOSurfaceGetPlaneCount(ioSurface)); 349 EGLAttrib plane = attribs.get(EGL_IOSURFACE_PLANE_ANGLE); 350 if (plane < 0 || static_cast<size_t>(plane) >= surfacePlaneCount) 351 { 352 return false; 353 } 354 355 // The width height specified must be at least (1, 1) and at most the plane size 356 EGLAttrib width = attribs.get(EGL_WIDTH); 357 EGLAttrib height = attribs.get(EGL_HEIGHT); 358 if (width <= 0 || static_cast<size_t>(width) > IOSurfaceGetWidthOfPlane(ioSurface, plane) || 359 height <= 0 || static_cast<size_t>(height) > IOSurfaceGetHeightOfPlane(ioSurface, plane)) 360 { 361 return false; 362 } 363 364 // Find this IOSurface format 365 EGLAttrib internalFormat = attribs.get(EGL_TEXTURE_INTERNAL_FORMAT_ANGLE); 366 EGLAttrib type = attribs.get(EGL_TEXTURE_TYPE_ANGLE); 367 368 int formatIndex = 369 FindIOSurfaceFormatIndex(static_cast<GLenum>(internalFormat), static_cast<GLenum>(type)); 370 371 if (formatIndex < 0) 372 { 373 return false; 374 } 375 376 // Check that the format matches this IOSurface plane 377 if (IOSurfaceGetBytesPerElementOfPlane(ioSurface, plane) != 378 kIOSurfaceFormats[formatIndex].componentBytes) 379 { 380 return false; 381 } 382 383 return true; 384 }} -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/SurfaceMtl.h
r270733 r273516 25 25 class DisplayMtl; 26 26 27 class SurfaceMtlProtocol : public SurfaceImpl 28 { 29 public: 30 SurfaceMtlProtocol(const egl::SurfaceState &state) : SurfaceImpl(state) {} 31 virtual int getSamples() const = 0; 32 virtual bool preserveBuffer() const = 0; 33 34 virtual angle::Result getAttachmentRenderTarget(const gl::Context *context, 35 GLenum binding, 36 const gl::ImageIndex &imageIndex, 37 GLsizei samples, 38 FramebufferAttachmentRenderTarget **rtOut) override = 0; 39 40 virtual bool hasRobustResourceInit() const = 0; 41 virtual angle::Result ensureCurrentDrawableObtained(const gl::Context *context) = 0; 42 virtual angle::Result ensureCurrentDrawableObtained(const gl::Context *context, bool *newDrawableOut) = 0; 43 virtual angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context) = 0; 44 virtual const mtl::TextureRef & getColorTexture() = 0; 45 }; 46 47 class SurfaceMtl : public SurfaceMtlProtocol 27 #define ANGLE_TO_EGL_TRY(EXPR) \ 28 do \ 29 { \ 30 if (ANGLE_UNLIKELY((EXPR) != angle::Result::Continue)) \ 31 { \ 32 return egl::EglBadSurface(); \ 33 } \ 34 } while (0) 35 36 class SurfaceMtl : public SurfaceImpl 48 37 { 49 38 public: … … 88 77 const gl::ImageIndex &imageIndex) override; 89 78 90 const mtl::TextureRef &getColorTexture() override{ return mColorTexture; }79 const mtl::TextureRef &getColorTexture() { return mColorTexture; } 91 80 const mtl::Format &getColorFormat() const { return mColorFormat; } 92 int getSamples() const override{ return mSamples; }93 94 bool hasRobustResourceInit() const override{ return mRobustResourceInit; }81 int getSamples() const { return mSamples; } 82 83 bool hasRobustResourceInit() const { return mRobustResourceInit; } 95 84 96 85 angle::Result getAttachmentRenderTarget(const gl::Context *context, … … 165 154 FramebufferAttachmentRenderTarget **rtOut) override; 166 155 167 angle::Result ensureCurrentDrawableObtained(const gl::Context *context) override;156 angle::Result ensureCurrentDrawableObtained(const gl::Context *context); 168 157 angle::Result ensureCurrentDrawableObtained(const gl::Context *context, 169 bool *newDrawableOut /** nullable */) override;158 bool *newDrawableOut /** nullable */); 170 159 171 160 // Ensure the the texture returned from getColorTexture() is ready for glReadPixels(). This 172 161 // implicitly calls ensureCurrentDrawableObtained(). 173 angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context) override;174 bool preserveBuffer() const override{ return mRetainBuffer; }162 angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context); 163 bool preserveBuffer() const { return mRetainBuffer; } 175 164 private: 176 165 angle::Result swapImpl(const gl::Context *context); … … 194 183 }; 195 184 196 // Offscreen surface, base class of PBuffer , IOSurface.185 // Offscreen surface, base class of PBuffer. 197 186 class OffscreenSurfaceMtl : public SurfaceMtl 198 187 { -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/SurfaceMtl.mm
r270733 r273516 242 242 const egl::SurfaceState &state, 243 243 const egl::AttributeMap &attribs) 244 : Surface MtlProtocol(state)244 : SurfaceImpl(state) 245 245 { 246 246 mRobustResourceInit = -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/TextureMtl.h
r270733 r273516 316 316 317 317 mtl::Format mFormat; 318 SurfaceMtl Protocol*mBoundSurface = nil;318 SurfaceMtl *mBoundSurface = nil; 319 319 // The real texture used by Metal draw calls. 320 320 mtl::TextureRef mNativeTexture = nil; -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/TextureMtl.mm
r270733 r273516 21 21 #include "libANGLE/renderer/metal/DisplayMtl.h" 22 22 #include "libANGLE/renderer/metal/FrameBufferMtl.h" 23 #include "libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h"24 23 #include "libANGLE/renderer/metal/SamplerMtl.h" 24 #include "libANGLE/renderer/metal/SurfaceMtl.h" 25 25 #include "libANGLE/renderer/metal/mtl_common.h" 26 26 #include "libANGLE/renderer/metal/mtl_format_utils.h" … … 535 535 angle::Result TextureMtl::ensureTextureCreated(const gl::Context *context) 536 536 { 537 if (mBoundSurface)538 {539 return angle::Result::Continue;540 }541 537 if (mNativeTexture) 542 538 { … … 669 665 samplerDesc.maxAnisotropy = 1; 670 666 } 671 667 if(mState.getType() == gl::TextureType::Rectangle) 668 { 669 samplerDesc.normalizedCoordinates = NO; 670 } 671 else 672 { 673 samplerDesc.normalizedCoordinates = YES; 674 } 672 675 mMetalSamplerState = 673 676 displayMtl->getStateCache().getSamplerState(displayMtl->getMetalDevice(), samplerDesc); … … 1212 1215 angle::Result TextureMtl::bindTexImage(const gl::Context *context, egl::Surface *surface) 1213 1216 { 1214 IOSurfaceSurfaceMtl *surfaceMtl = (IOSurfaceSurfaceMtl *)mtl::GetImpl(surface); 1215 mBoundSurface = surfaceMtl; 1217 releaseTexture(true); 1218 1219 auto pBuffer = GetImplAs<OffscreenSurfaceMtl>(surface); 1220 mNativeTexture = pBuffer->getColorTexture(); 1221 mFormat = pBuffer->getColorFormat(); 1222 gl::Extents size = mNativeTexture->sizeAt0(); 1223 mIsPow2 = gl::isPow2(size.width) && gl::isPow2(size.height) && gl::isPow2(size.depth); 1224 ANGLE_TRY(ensureSamplerStateCreated(context)); 1225 1226 // Tell context to rebind textures 1227 ContextMtl *contextMtl = mtl::GetImpl(context); 1228 contextMtl->invalidateCurrentTextures(); 1229 1216 1230 return angle::Result::Continue; 1217 1231 } … … 1219 1233 angle::Result TextureMtl::releaseTexImage(const gl::Context *context) 1220 1234 { 1221 mBoundSurface = nil; 1222 1235 releaseTexture(true); 1223 1236 return angle::Result::Continue; 1224 1237 } … … 1230 1243 FramebufferAttachmentRenderTarget **rtOut) 1231 1244 { 1232 if (mBoundSurface)1233 {1234 ANGLE_TRY(1235 mBoundSurface->getAttachmentRenderTarget(context, binding, imageIndex, samples, rtOut));1236 return angle::Result::Continue;1237 }1238 1245 ANGLE_TRY(ensureTextureCreated(context)); 1239 1246 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_common.h
r271334 r273516 114 114 class SamplerMtl; 115 115 class TransformFeedbackMtl; 116 class SurfaceMtlProtocol;117 116 118 117 ANGLE_GL_OBJECTS_X(ANGLE_PRE_DECLARE_MTL_OBJECT) … … 170 169 { 171 170 using ImplType = DisplayMtl; 172 };173 template <>174 struct ImplTypeHelper<egl::Surface>175 {176 using ImplType = SurfaceMtlProtocol;177 171 }; 178 172 template <typename T> -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_state_cache.h
r270733 r273516 114 114 uint8_t magFilter : 1; 115 115 uint8_t mipFilter : 2; 116 uint8_t normalizedCoordinates: 1; 116 117 117 118 uint8_t maxAnisotropy : 5; -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_state_cache.mm
r270733 r273516 77 77 ANGLE_OBJC_CP_PROPERTY(objCDesc, desc, maxAnisotropy); 78 78 ANGLE_OBJC_CP_PROPERTY(objCDesc, desc, compareFunction); 79 ANGLE_OBJC_CP_PROPERTY(objCDesc, desc, normalizedCoordinates); 79 80 80 81 return [objCDesc ANGLE_MTL_AUTORELEASE]; … … 464 465 465 466 compareFunction = GetCompareFunc(glState.getCompareFunc()); 467 468 normalizedCoordinates = YES; 466 469 } 467 470 … … 481 484 magFilter = MTLSamplerMinMagFilterNearest; 482 485 mipFilter = MTLSamplerMipFilterNearest; 483 486 484 487 maxAnisotropy = 1; 485 488 486 489 compareFunction = MTLCompareFunctionNever; 490 491 normalizedCoordinates = YES; 487 492 } 488 493
Note:
See TracChangeset
for help on using the changeset viewer.