mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 00:47:13 +00:00
@@ -86,7 +86,6 @@ namespace metal {
|
||||
const auto& info = currentRenderPass->GetSubpassInfo(subpass);
|
||||
|
||||
MTLRenderPassDescriptor* descriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
||||
bool usingBackbuffer = false; // HACK(kainino@chromium.org): workaround for not having depth attachments
|
||||
for (uint32_t index = 0; index < info.colorAttachments.size(); ++index) {
|
||||
uint32_t attachment = info.colorAttachments[index];
|
||||
|
||||
@@ -98,18 +97,30 @@ namespace metal {
|
||||
texture = ToBackend(textureView->GetTexture())->GetMTLTexture();
|
||||
} else {
|
||||
texture = device->GetCurrentTexture();
|
||||
usingBackbuffer = true;
|
||||
}
|
||||
descriptor.colorAttachments[index].texture = texture;
|
||||
descriptor.colorAttachments[index].loadAction = MTLLoadActionClear;
|
||||
descriptor.colorAttachments[index].loadAction = MTLLoadActionLoad;
|
||||
descriptor.colorAttachments[index].clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 0.0);
|
||||
descriptor.colorAttachments[index].storeAction = MTLStoreActionStore;
|
||||
}
|
||||
// TODO(kainino@chromium.org): load depth attachment from subpass
|
||||
if (usingBackbuffer) {
|
||||
descriptor.depthAttachment.texture = device->GetCurrentDepthTexture();
|
||||
descriptor.depthAttachment.loadAction = MTLLoadActionLoad;
|
||||
descriptor.depthAttachment.storeAction = MTLStoreActionStore;
|
||||
if (info.depthStencilAttachmentSet) {
|
||||
uint32_t attachment = info.depthStencilAttachment;
|
||||
|
||||
auto textureView = currentFramebuffer->GetTextureView(attachment);
|
||||
id<MTLTexture> texture = ToBackend(textureView->GetTexture())->GetMTLTexture();
|
||||
nxt::TextureFormat format = textureView->GetTexture()->GetFormat();
|
||||
if (TextureFormatHasDepth(format)) {
|
||||
descriptor.depthAttachment.texture = texture;
|
||||
descriptor.depthAttachment.loadAction = MTLLoadActionClear;
|
||||
descriptor.depthAttachment.clearDepth = 1.0;
|
||||
descriptor.depthAttachment.storeAction = MTLStoreActionStore;
|
||||
}
|
||||
if (TextureFormatHasStencil(format)) {
|
||||
descriptor.stencilAttachment.texture = texture;
|
||||
descriptor.stencilAttachment.loadAction = MTLLoadActionClear;
|
||||
descriptor.stencilAttachment.clearStencil = 0;
|
||||
descriptor.stencilAttachment.storeAction = MTLStoreActionStore;
|
||||
}
|
||||
}
|
||||
|
||||
render = [commandBuffer renderCommandEncoderWithDescriptor:descriptor];
|
||||
|
||||
@@ -108,7 +108,6 @@ namespace metal {
|
||||
|
||||
id<MTLDevice> GetMTLDevice();
|
||||
id<MTLTexture> GetCurrentTexture();
|
||||
id<MTLTexture> GetCurrentDepthTexture();
|
||||
|
||||
id<MTLCommandBuffer> GetPendingCommandBuffer();
|
||||
void SubmitPendingCommandBuffer();
|
||||
@@ -127,7 +126,6 @@ namespace metal {
|
||||
|
||||
id<CAMetalDrawable> currentDrawable = nil;
|
||||
id<MTLTexture> currentTexture = nil;
|
||||
id<MTLTexture> currentDepthTexture = nil;
|
||||
|
||||
Serial finishedCommandSerial = 0;
|
||||
Serial pendingCommandSerial = 1;
|
||||
|
||||
@@ -74,9 +74,6 @@ namespace metal {
|
||||
|
||||
[currentTexture release];
|
||||
currentTexture = nil;
|
||||
|
||||
[currentDepthTexture release];
|
||||
currentDepthTexture = nil;
|
||||
}
|
||||
|
||||
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
|
||||
@@ -146,32 +143,11 @@ namespace metal {
|
||||
currentTexture = drawable.texture;
|
||||
[currentTexture retain];
|
||||
|
||||
if (currentDepthTexture == nil ||
|
||||
currentTexture.width != currentDepthTexture.width ||
|
||||
currentTexture.height != currentDepthTexture.height) {
|
||||
if (currentDepthTexture != nil) {
|
||||
[currentDepthTexture release];
|
||||
}
|
||||
MTLTextureDescriptor* depthDescriptor = [MTLTextureDescriptor
|
||||
texture2DDescriptorWithPixelFormat:MTLPixelFormatDepth32Float
|
||||
width:currentTexture.width
|
||||
height:currentTexture.height
|
||||
mipmapped:NO];
|
||||
depthDescriptor.textureType = MTLTextureType2D;
|
||||
depthDescriptor.usage = MTLTextureUsageRenderTarget;
|
||||
depthDescriptor.storageMode = MTLStorageModePrivate;
|
||||
currentDepthTexture = [mtlDevice newTextureWithDescriptor:depthDescriptor];
|
||||
}
|
||||
|
||||
MTLRenderPassDescriptor* passDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
|
||||
passDescriptor.colorAttachments[0].texture = currentTexture;
|
||||
passDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
||||
passDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||
passDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0);
|
||||
passDescriptor.depthAttachment.texture = currentDepthTexture;
|
||||
passDescriptor.depthAttachment.loadAction = MTLLoadActionClear;
|
||||
passDescriptor.depthAttachment.storeAction = MTLStoreActionStore;
|
||||
passDescriptor.depthAttachment.clearDepth = 1.0;
|
||||
|
||||
|
||||
id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
|
||||
@@ -195,10 +171,6 @@ namespace metal {
|
||||
return currentTexture;
|
||||
}
|
||||
|
||||
id<MTLTexture> Device::GetCurrentDepthTexture() {
|
||||
return currentDepthTexture;
|
||||
}
|
||||
|
||||
id<MTLCommandBuffer> Device::GetPendingCommandBuffer() {
|
||||
if (pendingCommands == nil) {
|
||||
pendingCommands = [commandQueue commandBuffer];
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace metal {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
return MTLPixelFormatRGBA8Unorm;
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
return MTLPixelFormatDepth32Float_Stencil8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +67,7 @@ namespace metal {
|
||||
desc.depth = GetDepth();
|
||||
desc.mipmapLevelCount = GetNumMipLevels();
|
||||
desc.arrayLength = 1;
|
||||
desc.storageMode = MTLStorageModePrivate;
|
||||
|
||||
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
||||
mtlTexture = [mtlDevice newTextureWithDescriptor:desc];
|
||||
|
||||
Reference in New Issue
Block a user