Commit Graph

9170 Commits

Author SHA1 Message Date
Jake Turner 2f30ad3e27 Make METAL_NOT_HOOKED() be Fatal instead of Error 2022-07-05 11:23:03 +01:00
baldurk 049884f51b Don't make decisions based on legacy GL contexts
* This is especially relevant on Android where we fetch all function pointers at
  init time, so any that we replace via emulation are gone, but it is also
  generally true that we expect GL contexts to be representative.
2022-07-04 15:00:36 +01:00
Jake Turner c56beb77c8 Added DeallocateObjCBridge(WrappedMTL<type> *)
This replaces WrappedMTLObject::Dealloc() which was not implemented or hooked up (it was a TODO).
Deleted WrappedMTLObject::Dealloc()
DeallocateObjCBridge calls resource manager ReleaseWrappedResource().
2022-07-04 10:15:25 +01:00
Jake Turner 8c41ff714e Added MetalResourceManager::ReleaseWrappedResource 2022-07-04 10:15:25 +01:00
Jake Turner c7dae679c1 Use objc_constructInstance in AllocateObjCBridge
This constructs in-place the ObjC bridge class.
This fixes a bug where the reference count of the ObjC bridge class was not guaranteed to be initialized on construction.
2022-07-04 10:15:25 +01:00
Jake Turner 02103a9669 Set non-replay state to BackgroundCapturing 2022-07-04 10:15:25 +01:00
baldurk 4dc80c1793 Use non-legacy ASIC to generate AMDIL
* This may break on drivers old enough to not recognise the first non-legacy
  ASIC, but that is much rarer than new drivers that have dropped support for
  the old ones.
2022-06-30 15:41:45 +01:00
baldurk 9603f5a925 Pre-compile shaders for math and sampling opcodes during shader debug
* D3D12 math shader was already precompiled, but on D3D11 we now allocate
  everything up front and on D3D12 we also up-front compile sampling.
* The only exception is const offsets which can't be variable, so we cache these
  (likely we'll only see a few variants per shader/capture) and create them on
  demand.
2022-06-30 13:51:27 +01:00
baldurk 337704df1e Use a dense map for SPIR-V ID deaths 2022-06-30 13:51:26 +01:00
baldurk 7990254bc0 Avoid copying shader debug states, only move them 2022-06-30 13:51:26 +01:00
Jake Turner 1816bb809b Use capture mode directly : don't use local var
ie. replace

bool backframe = IsBackgroundCapturing(m_State);
if(backframe)

with

if(IsBackgroundCapturing(m_State))
2022-06-30 11:40:09 +01:00
Jake Turner 8b8027ff89 Update MetalCmdBufferRecordingInfo data
Switch to caching the CA::MetalLayer & WrappedMTLTexture from the MTL::Drawable.
This is to avoid validation asserts about accessing the texture of a MTL::Drawable after calling MTLCommandBuffer::presentDrawable.

Switch "bool present" to "uint32_t flags" to future proof being able to store multiple flags on the command buffer recoring info
2022-06-30 11:40:09 +01:00
Jake Turner ee82cf1476 Add MetalCmdBufferStatus enum 2022-06-30 11:40:09 +01:00
Jake Turner 4d69962397 Return the WrappedMTLCommandQueue from CmdBuffer
Previous API return goes back to usage for objective C calls and this is not required now the objective C and C++ wrapping/unwrapping has advanced and simplified.
More sense/natural/correct to return type without casting it.
2022-06-30 11:40:09 +01:00
Jake Turner 681611d3c4 MTLCommandBuffer API: enqueue, waitUntilCompleted
Hook and capture serialization for enqueue() & waitUntilCompleted()
2022-06-30 11:40:09 +01:00
Christian Voss-Wolff 4ba631d822 Fix Vulkan crash when viewing NV12 in TextureViewer 2022-06-29 11:04:01 +01:00
Jake Turner d257b5016d Wrapped MtlBlitCommandEncoder
Added temporary implementation of GetWrapped() and Unwrap() for the unimplemented Metal types used by MTLBlitCommandEncoder APIs (MTLFence, MTLIndirectCommandBuffer, MTLCounterSampleBuffer).
The API synchronizeResource uses ObjC inheritance for MTLResource, which uses new helper methods for MTLResource without implementing the complete type.

MTLResource helper methods: GetResID(), Unwrap(), GetWrapped().
The WrappedMTLResource* is cast to WrappedMTLObject* to get the ID and real resource.

For the unimplemented Metal types: MTLFence, MTLIndirectCommandBuffer, MTLCounterSampleBuffer have added temporary implementations of GetWrapped() and Unwrap().
These temporary implementations perform the appropriate casting. There is no actual implementation of the unimplemented wrapped types. These unimplemented wrapped types are a temporary solution to enable the ObjC bridge to be implemented.

The APIs related to retrieving GPU counters have been hooked with basic serialization. It is expected the replay and capture will need to be specific ie. capture & serialize the buffer data, then at replay upload the serialized buffer data to the GPU buffer.
2022-06-28 12:33:45 +01:00
Jake Turner 98075c6759 Unit tests for Metal format helper methods
Basic tests for public methods:
MakeResourceFormat(MTL::PixelFormat format);
GetByteSize(uint32_t width, uint32_t height, uint32_t depth, MTL::PixelFormat format, uint32_t mip);

One test for helper method:
GetPlaneByteSize(uint32_t width, uint32_t height, uint32_t depth, MTL::PixelFormat format, uint32_t mip, uint32_t plane);
2022-06-24 21:03:36 +01:00
Jake Turner b6787686d3 Helpers for Texture byte size and ResourceFormat
public Methods

MakeResourceFormat(MTL::PixelFormat format);
GetByteSize(uint32_t width, uint32_t height, uint32_t depth, MTL::PixelFormat format, uint32_t mip);

private helper Methods

IsOneComponent(MTL::PixelFormat mtlFormat);
IsTwoComponent(MTL::PixelFormat mtlFormat);
IsThreeComponent(MTL::PixelFormat mtlFormat);
IsFourComponent(MTL::PixelFormat mtlFormat);
IsBlockFormat(MTL::PixelFormat mtlFormat);
IsDepthOrStencilFormat(MTL::PixelFormat mtlFormat);
IsUNormFormat(MTL::PixelFormat mtlFormat);
IsSNormFormat(MTL::PixelFormat mtlFormat);
IsFloatFormat(MTL::PixelFormat mtlFormat);
IsUIntFormat(MTL::PixelFormat mtlFormat);
IsSIntFormat(MTL::PixelFormat mtlFormat);
IsSRGBFormat(MTL::PixelFormat mtlFormat);
IsYUVFormat(MTL::PixelFormat format);
GetBlockShape(MTL::PixelFormat format, uint32_t plane);
GetPlaneByteSize(uint32_t width, uint32_t height, uint32_t depth, MTL::PixelFormat format, uint32_t mip, uint32_t plane);
2022-06-24 21:03:36 +01:00
Jake Turner 5096d0244d Future proofing MakeBlendMultiplier & MakeBlendOp
Remove default from switch statements to trigger compile errors if MTL::BlendFactor or MTL::BlendOperation enumerations change in the future.
2022-06-24 21:03:36 +01:00
baldurk 67920a37b4 Update RGA backend to include gfx1035 2022-06-24 11:10:57 +01:00
baldurk a48591143a Load stencil state from stencil attachment correctly 2022-06-23 18:39:30 +01:00
baldurk e310f72939 Delete chunks upon re-beginning a command buffer
* If a command buffer had an unbalanced begin/end, some chunks may still be left
  in the record that haven't been baked. Delete these before beginning to record
  again.
2022-06-23 18:38:03 +01:00
baldurk 5919085e47 Fix unused lambda capture compile warning 2022-06-23 12:12:06 +01:00
Jake Turner b44a75eddf Helpers to convert MTL Blend, ColorWriteMask enums
MakeBlendMultiplier(MTL::BlendFactor blend);
MakeBlendOp(MTL::BlendOperation op);
MakeWriteMask(MTL::ColorWriteMask mask);
2022-06-23 12:11:57 +01:00
Jake Turner d3e2231ba9 Use bytebuf::assign() instead of resize, memcpy 2022-06-23 12:11:57 +01:00
Jake Turner 1f6b2abc12 ObjC helpers MTL::Drawable, CALayer, CAMetalLayer
Get_Texture(MTL::Drawable *drawable);
Get_Layer(MTL::Drawable *drawable);
CALayer_GetSize(void *layerHandle, int &width, int &height);
CAMetalLayer_Set_drawableSize(void *layerHandle, int w, int h);
CAMetalLayer_Set_device(void *layerHandle, MTL::Device *device);
CAMetalLayer_Set_framebufferOnly(void *layerHandle, bool enable);
CAMetalLayer_Set_pixelFormat(void *layerHandle, MTL::PixelFormat format);
CA::MetalDrawable *CAMetalLayer_nextDrawable(void *layerHandle);
2022-06-23 12:11:57 +01:00
Jake Turner 0499c2af96 Serialization for enum MetalResourceType 2022-06-23 12:11:57 +01:00
Jake Turner c7b6d6293e Serialization for Metal types
structs

MTL::Origin
MTL::Region
MTL::Size

enums

MTL::BlitOption
MTL::DeviceLocation
MTL::ArgumentBuffersTier
MTL::DepthClipMode
MTL::TriangleFillMode
MTL::CullMode
2022-06-23 12:11:57 +01:00
baldurk c13366d13b Fix capturing frame 0 if the first window is never presented
* The first window created becomes active, if it never presents then a frame 0
  capture never finishes.
2022-06-22 20:04:42 +01:00
baldurk f18d1b3b98 Improve ordering of source declared variables for debug info 2022-06-22 20:04:42 +01:00
baldurk c8f673137b Fix handling of local variable mappings around function entry & calls 2022-06-22 20:04:42 +01:00
baldurk 2bf91773f3 When using debug info, don't use first store as variable live point
* We already will have a live point when the variable is declared
2022-06-22 20:04:42 +01:00
Orson Baines d1dcb81acd use WrappedOpenGL::SetFetchCounters in occlusion query 2022-06-22 13:17:24 +01:00
Orson Baines 45ac6242e0 OpenGL Pixel History address PR feedback
- add missing destroy resources call
- restore framebuffer binding after replaying draw
- disable more state bits for occlusion querying
- read back query results after executing all queries
2022-06-22 13:17:24 +01:00
Orson Baines 8684585330 Add WIP OpenGL Pixel History code for PostMod pixel value
The OpenGL Pixel History feature is hidden behind the OpenGL_PixelHistory config toggle.
For now, we only run an occlusion query and then replay the events
and read back the pixel values to return to the UI.
2022-06-22 13:17:24 +01:00
baldurk 7d9a1a05b8 Correctly handle programs that don't create graphics queues 2022-06-21 15:31:41 +01:00
baldurk e903589e95 Fix bitcast between types of different column counts 2022-06-20 17:20:51 +01:00
baldurk 687c11ba68 Fix handling of 64-bit integer vertex attributes in mesh output fetch 2022-06-20 16:47:50 +01:00
baldurk 0431e4114f Handle D3D12 renderpass resolves. Closes #2622 2022-06-20 16:47:50 +01:00
Jake Turner e7669288c9 DoStringise for MetalChunk 2022-06-20 10:14:34 +01:00
Jake Turner c6fff16bf2 Reserve Chunk for modifying MTLBuffer contents
MTLBuffer_InternalModifyCPUContents
2022-06-20 10:14:34 +01:00
William Hjelm 59b43510b2 Fix typo in in intercepted CreateCommittedResource 2022-06-17 19:47:21 +01:00
baldurk 028d71fced Remove DENY_SHADER_RESOURCE flag in all resource creation functions 2022-06-17 18:13:06 +01:00
baldurk 46a1f90495 Disable depth bounds test when rendering GL overlay 2022-06-17 17:27:30 +01:00
Danylo Piliaiev 623cd01919 Do not use inline asm for debugbreak on non i386/x86_64 targets
Fixes compilation on non i386/x86_64 Linux targets.

Don't use arch specific assembly for other architectures because
in most cases it breaks gdb ability to do next step.

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
2022-06-17 17:26:16 +01:00
baldurk 6a006625f2 Ignore rasterizerDiscardEnable == true if it is dynamic. Closes #2617
* Normally we have to ignore subsequent states as potentially garbage pointers
  if discard is enabled, but when it's dynamic state we have to ignore its
  valid.
2022-06-17 10:46:14 +01:00
baldurk 0fce39ff04 Implement workaround for broken occlusion queries on Intel. Closes #2591
* If a draw has no effects (color mask writes off, no depth attachment) then
  Intel will not return proper occlusion query results. Forcibly patching in a
  storage write works around the problem.
2022-06-16 15:53:50 +01:00
baldurk 59804c1d1e When using GLES on desktop, use same API for child context. Closes #2612 2022-06-16 15:53:50 +01:00
baldurk fc39299da8 Don't require GL_OVR_multiview2 when GL_OVR_multiview is enough
* This is also all we check for in code.
2022-06-16 15:53:50 +01:00