Member rename: src/backend/metal

This commit is contained in:
Corentin Wallez 2017-11-23 15:52:29 -05:00 committed by Corentin Wallez
parent e00385af73
commit b0c75a5b68
24 changed files with 148 additions and 148 deletions

View File

@ -40,7 +40,7 @@ namespace metal {
void UnmapImpl() override; void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override; void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
id<MTLBuffer> mtlBuffer = nil; id<MTLBuffer> mMtlBuffer = nil;
}; };
class BufferView : public BufferViewBase { class BufferView : public BufferViewBase {
@ -57,14 +57,14 @@ namespace metal {
void Tick(Serial finishedSerial); void Tick(Serial finishedSerial);
private: private:
Device* device; Device* mDevice;
struct Request { struct Request {
Ref<Buffer> buffer; Ref<Buffer> buffer;
uint32_t mapSerial; uint32_t mapSerial;
uint32_t offset; uint32_t offset;
}; };
SerialQueue<Request> inflightRequests; SerialQueue<Request> mInflightRequests;
}; };
} }

View File

@ -30,27 +30,27 @@ namespace metal {
storageMode = MTLResourceStorageModePrivate; storageMode = MTLResourceStorageModePrivate;
} }
mtlBuffer = [ToBackend(GetDevice())->GetMTLDevice() newBufferWithLength:GetSize() mMtlBuffer = [ToBackend(GetDevice())->GetMTLDevice() newBufferWithLength:GetSize()
options:storageMode]; options:storageMode];
} }
Buffer::~Buffer() { Buffer::~Buffer() {
[mtlBuffer release]; [mMtlBuffer release];
mtlBuffer = nil; mMtlBuffer = nil;
} }
id<MTLBuffer> Buffer::GetMTLBuffer() { id<MTLBuffer> Buffer::GetMTLBuffer() {
return mtlBuffer; return mMtlBuffer;
} }
void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, uint32_t offset) { void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, uint32_t offset) {
const char* data = reinterpret_cast<const char*>([mtlBuffer contents]); const char* data = reinterpret_cast<const char*>([mMtlBuffer contents]);
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data + offset); CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data + offset);
} }
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) { void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
auto* uploader = ToBackend(GetDevice())->GetResourceUploader(); auto* uploader = ToBackend(GetDevice())->GetResourceUploader();
uploader->BufferSubData(mtlBuffer, start * sizeof(uint32_t), count * sizeof(uint32_t), data); uploader->BufferSubData(mMtlBuffer, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
} }
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t) { void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t) {
@ -70,11 +70,11 @@ namespace metal {
} }
MapReadRequestTracker::MapReadRequestTracker(Device* device) MapReadRequestTracker::MapReadRequestTracker(Device* device)
: device(device) { : mDevice(device) {
} }
MapReadRequestTracker::~MapReadRequestTracker() { MapReadRequestTracker::~MapReadRequestTracker() {
ASSERT(inflightRequests.Empty()); ASSERT(mInflightRequests.Empty());
} }
void MapReadRequestTracker::Track(Buffer* buffer, uint32_t mapSerial, uint32_t offset) { void MapReadRequestTracker::Track(Buffer* buffer, uint32_t mapSerial, uint32_t offset) {
@ -83,14 +83,14 @@ namespace metal {
request.mapSerial = mapSerial; request.mapSerial = mapSerial;
request.offset = offset; request.offset = offset;
inflightRequests.Enqueue(std::move(request), device->GetPendingCommandSerial()); mInflightRequests.Enqueue(std::move(request), mDevice->GetPendingCommandSerial());
} }
void MapReadRequestTracker::Tick(Serial finishedSerial) { void MapReadRequestTracker::Tick(Serial finishedSerial) {
for (auto& request : inflightRequests.IterateUpTo(finishedSerial)) { for (auto& request : mInflightRequests.IterateUpTo(finishedSerial)) {
request.buffer->OnMapReadCommandSerialFinished(request.mapSerial, request.offset); request.buffer->OnMapReadCommandSerialFinished(request.mapSerial, request.offset);
} }
inflightRequests.ClearUpTo(finishedSerial); mInflightRequests.ClearUpTo(finishedSerial);
} }
} }
} }

View File

@ -32,8 +32,8 @@ namespace metal {
void FillCommands(id<MTLCommandBuffer> commandBuffer); void FillCommands(id<MTLCommandBuffer> commandBuffer);
private: private:
Device* device; Device* mDevice;
CommandIterator commands; CommandIterator mCommands;
}; };
} }

View File

@ -149,12 +149,12 @@ namespace metal {
} }
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder) CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
: CommandBufferBase(builder), device(ToBackend(builder->GetDevice())), : CommandBufferBase(builder), mDevice(ToBackend(builder->GetDevice())),
commands(builder->AcquireCommands()) { mCommands(builder->AcquireCommands()) {
} }
CommandBuffer::~CommandBuffer() { CommandBuffer::~CommandBuffer() {
FreeCommands(&commands); FreeCommands(&mCommands);
} }
void CommandBuffer::FillCommands(id<MTLCommandBuffer> commandBuffer) { void CommandBuffer::FillCommands(id<MTLCommandBuffer> commandBuffer) {
@ -165,16 +165,16 @@ namespace metal {
uint32_t indexBufferOffset = 0; uint32_t indexBufferOffset = 0;
CurrentEncoders encoders; CurrentEncoders encoders;
encoders.device = device; encoders.device = mDevice;
PerStage<std::array<uint32_t, kMaxPushConstants>> pushConstants; PerStage<std::array<uint32_t, kMaxPushConstants>> pushConstants;
uint32_t currentSubpass = 0; uint32_t currentSubpass = 0;
while (commands.NextCommandId(&type)) { while (mCommands.NextCommandId(&type)) {
switch (type) { switch (type) {
case Command::BeginComputePass: case Command::BeginComputePass:
{ {
commands.NextCommand<BeginComputePassCmd>(); mCommands.NextCommand<BeginComputePassCmd>();
encoders.BeginCompute(commandBuffer); encoders.BeginCompute(commandBuffer);
pushConstants[nxt::ShaderStage::Compute].fill(0); pushConstants[nxt::ShaderStage::Compute].fill(0);
@ -186,7 +186,7 @@ namespace metal {
case Command::BeginRenderPass: case Command::BeginRenderPass:
{ {
BeginRenderPassCmd* beginRenderPassCmd = commands.NextCommand<BeginRenderPassCmd>(); BeginRenderPassCmd* beginRenderPassCmd = mCommands.NextCommand<BeginRenderPassCmd>();
encoders.currentRenderPass = ToBackend(beginRenderPassCmd->renderPass.Get()); encoders.currentRenderPass = ToBackend(beginRenderPassCmd->renderPass.Get());
encoders.currentFramebuffer = ToBackend(beginRenderPassCmd->framebuffer.Get()); encoders.currentFramebuffer = ToBackend(beginRenderPassCmd->framebuffer.Get());
encoders.EnsureNoBlitEncoder(); encoders.EnsureNoBlitEncoder();
@ -196,7 +196,7 @@ namespace metal {
case Command::BeginRenderSubpass: case Command::BeginRenderSubpass:
{ {
commands.NextCommand<BeginRenderSubpassCmd>(); mCommands.NextCommand<BeginRenderSubpassCmd>();
encoders.BeginSubpass(commandBuffer, currentSubpass); encoders.BeginSubpass(commandBuffer, currentSubpass);
pushConstants[nxt::ShaderStage::Vertex].fill(0); pushConstants[nxt::ShaderStage::Vertex].fill(0);
@ -213,7 +213,7 @@ namespace metal {
case Command::CopyBufferToBuffer: case Command::CopyBufferToBuffer:
{ {
CopyBufferToBufferCmd* copy = commands.NextCommand<CopyBufferToBufferCmd>(); CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
auto& src = copy->source; auto& src = copy->source;
auto& dst = copy->destination; auto& dst = copy->destination;
@ -229,7 +229,7 @@ namespace metal {
case Command::CopyBufferToTexture: case Command::CopyBufferToTexture:
{ {
CopyBufferToTextureCmd* copy = commands.NextCommand<CopyBufferToTextureCmd>(); CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
auto& src = copy->source; auto& src = copy->source;
auto& dst = copy->destination; auto& dst = copy->destination;
Buffer* buffer = ToBackend(src.buffer.Get()); Buffer* buffer = ToBackend(src.buffer.Get());
@ -261,7 +261,7 @@ namespace metal {
case Command::CopyTextureToBuffer: case Command::CopyTextureToBuffer:
{ {
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>(); CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
auto& src = copy->source; auto& src = copy->source;
auto& dst = copy->destination; auto& dst = copy->destination;
Texture* texture = ToBackend(src.texture.Get()); Texture* texture = ToBackend(src.texture.Get());
@ -293,7 +293,7 @@ namespace metal {
case Command::Dispatch: case Command::Dispatch:
{ {
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>(); DispatchCmd* dispatch = mCommands.NextCommand<DispatchCmd>();
ASSERT(encoders.compute); ASSERT(encoders.compute);
[encoders.compute dispatchThreadgroups:MTLSizeMake(dispatch->x, dispatch->y, dispatch->z) [encoders.compute dispatchThreadgroups:MTLSizeMake(dispatch->x, dispatch->y, dispatch->z)
@ -303,7 +303,7 @@ namespace metal {
case Command::DrawArrays: case Command::DrawArrays:
{ {
DrawArraysCmd* draw = commands.NextCommand<DrawArraysCmd>(); DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
ASSERT(encoders.render); ASSERT(encoders.render);
[encoders.render [encoders.render
@ -317,7 +317,7 @@ namespace metal {
case Command::DrawElements: case Command::DrawElements:
{ {
DrawElementsCmd* draw = commands.NextCommand<DrawElementsCmd>(); DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
ASSERT(encoders.render); ASSERT(encoders.render);
[encoders.render [encoders.render
@ -334,20 +334,20 @@ namespace metal {
case Command::EndComputePass: case Command::EndComputePass:
{ {
commands.NextCommand<EndComputePassCmd>(); mCommands.NextCommand<EndComputePassCmd>();
encoders.EndCompute(); encoders.EndCompute();
} }
break; break;
case Command::EndRenderPass: case Command::EndRenderPass:
{ {
commands.NextCommand<EndRenderPassCmd>(); mCommands.NextCommand<EndRenderPassCmd>();
} }
break; break;
case Command::EndRenderSubpass: case Command::EndRenderSubpass:
{ {
commands.NextCommand<EndRenderSubpassCmd>(); mCommands.NextCommand<EndRenderSubpassCmd>();
encoders.EndSubpass(); encoders.EndSubpass();
currentSubpass += 1; currentSubpass += 1;
} }
@ -355,7 +355,7 @@ namespace metal {
case Command::SetComputePipeline: case Command::SetComputePipeline:
{ {
SetComputePipelineCmd* cmd = commands.NextCommand<SetComputePipelineCmd>(); SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
lastComputePipeline = ToBackend(cmd->pipeline).Get(); lastComputePipeline = ToBackend(cmd->pipeline).Get();
ASSERT(encoders.compute); ASSERT(encoders.compute);
@ -365,7 +365,7 @@ namespace metal {
case Command::SetRenderPipeline: case Command::SetRenderPipeline:
{ {
SetRenderPipelineCmd* cmd = commands.NextCommand<SetRenderPipelineCmd>(); SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
lastRenderPipeline = ToBackend(cmd->pipeline).Get(); lastRenderPipeline = ToBackend(cmd->pipeline).Get();
ASSERT(encoders.render); ASSERT(encoders.render);
@ -377,8 +377,8 @@ namespace metal {
case Command::SetPushConstants: case Command::SetPushConstants:
{ {
SetPushConstantsCmd* cmd = commands.NextCommand<SetPushConstantsCmd>(); SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
uint32_t* values = commands.NextData<uint32_t>(cmd->count); uint32_t* values = mCommands.NextData<uint32_t>(cmd->count);
for (auto stage : IterateStages(cmd->stages)) { for (auto stage : IterateStages(cmd->stages)) {
memcpy(&pushConstants[stage][cmd->offset], values, cmd->count * sizeof(uint32_t)); memcpy(&pushConstants[stage][cmd->offset], values, cmd->count * sizeof(uint32_t));
@ -412,7 +412,7 @@ namespace metal {
case Command::SetStencilReference: case Command::SetStencilReference:
{ {
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>(); SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
ASSERT(encoders.render); ASSERT(encoders.render);
@ -422,7 +422,7 @@ namespace metal {
case Command::SetBlendColor: case Command::SetBlendColor:
{ {
SetBlendColorCmd* cmd = commands.NextCommand<SetBlendColorCmd>(); SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
ASSERT(encoders.render); ASSERT(encoders.render);
@ -436,7 +436,7 @@ namespace metal {
case Command::SetBindGroup: case Command::SetBindGroup:
{ {
SetBindGroupCmd* cmd = commands.NextCommand<SetBindGroupCmd>(); SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
BindGroup* group = ToBackend(cmd->group.Get()); BindGroup* group = ToBackend(cmd->group.Get());
uint32_t groupIndex = cmd->index; uint32_t groupIndex = cmd->index;
@ -550,7 +550,7 @@ namespace metal {
case Command::SetIndexBuffer: case Command::SetIndexBuffer:
{ {
SetIndexBufferCmd* cmd = commands.NextCommand<SetIndexBufferCmd>(); SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
auto b = ToBackend(cmd->buffer.Get()); auto b = ToBackend(cmd->buffer.Get());
indexBuffer = b->GetMTLBuffer(); indexBuffer = b->GetMTLBuffer();
indexBufferOffset = cmd->offset; indexBufferOffset = cmd->offset;
@ -559,9 +559,9 @@ namespace metal {
case Command::SetVertexBuffers: case Command::SetVertexBuffers:
{ {
SetVertexBuffersCmd* cmd = commands.NextCommand<SetVertexBuffersCmd>(); SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
auto buffers = commands.NextData<Ref<BufferBase>>(cmd->count); auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);
auto offsets = commands.NextData<uint32_t>(cmd->count); auto offsets = mCommands.NextData<uint32_t>(cmd->count);
std::array<id<MTLBuffer>, kMaxVertexInputs> mtlBuffers; std::array<id<MTLBuffer>, kMaxVertexInputs> mtlBuffers;
std::array<NSUInteger, kMaxVertexInputs> mtlOffsets; std::array<NSUInteger, kMaxVertexInputs> mtlOffsets;
@ -584,7 +584,7 @@ namespace metal {
case Command::TransitionBufferUsage: case Command::TransitionBufferUsage:
{ {
TransitionBufferUsageCmd* cmd = commands.NextCommand<TransitionBufferUsageCmd>(); TransitionBufferUsageCmd* cmd = mCommands.NextCommand<TransitionBufferUsageCmd>();
cmd->buffer->UpdateUsageInternal(cmd->usage); cmd->buffer->UpdateUsageInternal(cmd->usage);
} }
@ -592,7 +592,7 @@ namespace metal {
case Command::TransitionTextureUsage: case Command::TransitionTextureUsage:
{ {
TransitionTextureUsageCmd* cmd = commands.NextCommand<TransitionTextureUsageCmd>(); TransitionTextureUsageCmd* cmd = mCommands.NextCommand<TransitionTextureUsageCmd>();
cmd->texture->UpdateUsageInternal(cmd->usage); cmd->texture->UpdateUsageInternal(cmd->usage);
} }

View File

@ -31,8 +31,8 @@ namespace metal {
MTLSize GetLocalWorkGroupSize() const; MTLSize GetLocalWorkGroupSize() const;
private: private:
id<MTLComputePipelineState> mtlComputePipelineState = nil; id<MTLComputePipelineState> mMtlComputePipelineState = nil;
MTLSize localWorkgroupSize; MTLSize mLocalWorkgroupSize;
}; };
} }

View File

@ -31,7 +31,7 @@ namespace metal {
auto compilationData = module->GetFunction(entryPoint.c_str(), ToBackend(GetLayout())); auto compilationData = module->GetFunction(entryPoint.c_str(), ToBackend(GetLayout()));
NSError *error = nil; NSError *error = nil;
mtlComputePipelineState = [mtlDevice mMtlComputePipelineState = [mtlDevice
newComputePipelineStateWithFunction:compilationData.function error:&error]; newComputePipelineStateWithFunction:compilationData.function error:&error];
if (error != nil) { if (error != nil) {
NSLog(@" error => %@", error); NSLog(@" error => %@", error);
@ -40,19 +40,19 @@ namespace metal {
} }
// Copy over the local workgroup size as it is passed to dispatch explicitly in Metal // Copy over the local workgroup size as it is passed to dispatch explicitly in Metal
localWorkgroupSize = compilationData.localWorkgroupSize; mLocalWorkgroupSize = compilationData.localWorkgroupSize;
} }
ComputePipeline::~ComputePipeline() { ComputePipeline::~ComputePipeline() {
[mtlComputePipelineState release]; [mMtlComputePipelineState release];
} }
void ComputePipeline::Encode(id<MTLComputeCommandEncoder> encoder) { void ComputePipeline::Encode(id<MTLComputeCommandEncoder> encoder) {
[encoder setComputePipelineState:mtlComputePipelineState]; [encoder setComputePipelineState:mMtlComputePipelineState];
} }
MTLSize ComputePipeline::GetLocalWorkGroupSize() const { MTLSize ComputePipeline::GetLocalWorkGroupSize() const {
return localWorkgroupSize; return mLocalWorkgroupSize;
} }
} }

View File

@ -32,7 +32,7 @@ namespace metal {
id<MTLDepthStencilState> GetMTLDepthStencilState(); id<MTLDepthStencilState> GetMTLDepthStencilState();
private: private:
id<MTLDepthStencilState> mtlDepthStencilState = nil; id<MTLDepthStencilState> mMtlDepthStencilState = nil;
}; };
} }

View File

@ -97,17 +97,17 @@ namespace metal {
} }
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice(); auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
mtlDepthStencilState = [mtlDevice newDepthStencilStateWithDescriptor:mtlDepthStencilDescriptor]; mMtlDepthStencilState = [mtlDevice newDepthStencilStateWithDescriptor:mtlDepthStencilDescriptor];
[mtlDepthStencilDescriptor release]; [mtlDepthStencilDescriptor release];
} }
DepthStencilState::~DepthStencilState() { DepthStencilState::~DepthStencilState() {
[mtlDepthStencilState release]; [mMtlDepthStencilState release];
mtlDepthStencilState = nil; mMtlDepthStencilState = nil;
} }
id<MTLDepthStencilState> DepthStencilState::GetMTLDepthStencilState() { id<MTLDepthStencilState> DepthStencilState::GetMTLDepthStencilState() {
return mtlDepthStencilState; return mMtlDepthStencilState;
} }
} }

View File

@ -30,7 +30,7 @@ namespace metal {
MTLVertexDescriptor* GetMTLVertexDescriptor(); MTLVertexDescriptor* GetMTLVertexDescriptor();
private: private:
MTLVertexDescriptor* mtlVertexDescriptor = nil; MTLVertexDescriptor* mMtlVertexDescriptor = nil;
}; };
} }

View File

@ -46,7 +46,7 @@ namespace metal {
InputState::InputState(InputStateBuilder* builder) InputState::InputState(InputStateBuilder* builder)
: InputStateBase(builder) { : InputStateBase(builder) {
mtlVertexDescriptor = [MTLVertexDescriptor new]; mMtlVertexDescriptor = [MTLVertexDescriptor new];
const auto& attributesSetMask = GetAttributesSetMask(); const auto& attributesSetMask = GetAttributesSetMask();
for (uint32_t i = 0; i < attributesSetMask.size(); ++i) { for (uint32_t i = 0; i < attributesSetMask.size(); ++i) {
@ -59,7 +59,7 @@ namespace metal {
attribDesc.format = VertexFormatType(info.format); attribDesc.format = VertexFormatType(info.format);
attribDesc.offset = info.offset; attribDesc.offset = info.offset;
attribDesc.bufferIndex = kMaxBindingsPerGroup + info.bindingSlot; attribDesc.bufferIndex = kMaxBindingsPerGroup + info.bindingSlot;
mtlVertexDescriptor.attributes[i] = attribDesc; mMtlVertexDescriptor.attributes[i] = attribDesc;
[attribDesc release]; [attribDesc release];
} }
@ -81,18 +81,18 @@ namespace metal {
layoutDesc.stride = info.stride; layoutDesc.stride = info.stride;
} }
// TODO(cwallez@chromium.org): make the offset depend on the pipeline layout // TODO(cwallez@chromium.org): make the offset depend on the pipeline layout
mtlVertexDescriptor.layouts[kMaxBindingsPerGroup + i] = layoutDesc; mMtlVertexDescriptor.layouts[kMaxBindingsPerGroup + i] = layoutDesc;
[layoutDesc release]; [layoutDesc release];
} }
} }
InputState::~InputState() { InputState::~InputState() {
[mtlVertexDescriptor release]; [mMtlVertexDescriptor release];
mtlVertexDescriptor = nil; mMtlVertexDescriptor = nil;
} }
MTLVertexDescriptor* InputState::GetMTLVertexDescriptor() { MTLVertexDescriptor* InputState::GetMTLVertexDescriptor() {
return mtlVertexDescriptor; return mMtlVertexDescriptor;
} }
} }

View File

@ -124,14 +124,14 @@ namespace metal {
private: private:
void OnCompletedHandler(); void OnCompletedHandler();
id<MTLDevice> mtlDevice = nil; id<MTLDevice> mMtlDevice = nil;
id<MTLCommandQueue> commandQueue = nil; id<MTLCommandQueue> mCommandQueue = nil;
MapReadRequestTracker* mapReadTracker; MapReadRequestTracker* mMapReadTracker;
ResourceUploader* resourceUploader; ResourceUploader* mResourceUploader;
Serial finishedCommandSerial = 0; Serial mFinishedCommandSerial = 0;
Serial pendingCommandSerial = 1; Serial mPendingCommandSerial = 1;
id<MTLCommandBuffer> pendingCommands = nil; id<MTLCommandBuffer> mPendingCommands = nil;
}; };
class BindGroup : public BindGroupBase { class BindGroup : public BindGroupBase {
@ -161,7 +161,7 @@ namespace metal {
void Submit(uint32_t numCommands, CommandBuffer* const * commands); void Submit(uint32_t numCommands, CommandBuffer* const * commands);
private: private:
id<MTLCommandQueue> commandQueue = nil; id<MTLCommandQueue> mCommandQueue = nil;
}; };
class RenderPass : public RenderPassBase { class RenderPass : public RenderPassBase {

View File

@ -45,10 +45,10 @@ namespace metal {
// Device // Device
Device::Device(id<MTLDevice> mtlDevice) Device::Device(id<MTLDevice> mtlDevice)
: mtlDevice(mtlDevice), mapReadTracker(new MapReadRequestTracker(this)), : mMtlDevice(mtlDevice), mMapReadTracker(new MapReadRequestTracker(this)),
resourceUploader(new ResourceUploader(this)) { mResourceUploader(new ResourceUploader(this)) {
[mtlDevice retain]; [mMtlDevice retain];
commandQueue = [mtlDevice newCommandQueue]; mCommandQueue = [mMtlDevice newCommandQueue];
} }
Device::~Device() { Device::~Device() {
@ -58,25 +58,25 @@ namespace metal {
// SubmitPendingCommandBuffer then wait for it to be passed. Instead we submit and // SubmitPendingCommandBuffer then wait for it to be passed. Instead we submit and
// wait for the serial before the next pendingCommandSerial. // wait for the serial before the next pendingCommandSerial.
SubmitPendingCommandBuffer(); SubmitPendingCommandBuffer();
while (finishedCommandSerial != pendingCommandSerial - 1) { while (mFinishedCommandSerial != mPendingCommandSerial - 1) {
usleep(100); usleep(100);
} }
Tick(); Tick();
[pendingCommands release]; [mPendingCommands release];
pendingCommands = nil; mPendingCommands = nil;
delete mapReadTracker; delete mMapReadTracker;
mapReadTracker = nullptr; mMapReadTracker = nullptr;
delete resourceUploader; delete mResourceUploader;
resourceUploader = nullptr; mResourceUploader = nullptr;
[mtlDevice release]; [mMtlDevice release];
mtlDevice = nil; mMtlDevice = nil;
[commandQueue release]; [mCommandQueue release];
commandQueue = nil; mCommandQueue = nil;
} }
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) { BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
@ -138,8 +138,8 @@ namespace metal {
} }
void Device::TickImpl() { void Device::TickImpl() {
resourceUploader->Tick(finishedCommandSerial); mResourceUploader->Tick(mFinishedCommandSerial);
mapReadTracker->Tick(finishedCommandSerial); mMapReadTracker->Tick(mFinishedCommandSerial);
// Code above might have added GPU work, submit it. This also makes sure // Code above might have added GPU work, submit it. This also makes sure
// that even when no GPU work is happening, the serial number keeps incrementing. // that even when no GPU work is happening, the serial number keeps incrementing.
@ -147,34 +147,34 @@ namespace metal {
} }
id<MTLDevice> Device::GetMTLDevice() { id<MTLDevice> Device::GetMTLDevice() {
return mtlDevice; return mMtlDevice;
} }
id<MTLCommandBuffer> Device::GetPendingCommandBuffer() { id<MTLCommandBuffer> Device::GetPendingCommandBuffer() {
if (pendingCommands == nil) { if (mPendingCommands == nil) {
pendingCommands = [commandQueue commandBuffer]; mPendingCommands = [mCommandQueue commandBuffer];
[pendingCommands retain]; [mPendingCommands retain];
} }
return pendingCommands; return mPendingCommands;
} }
void Device::SubmitPendingCommandBuffer() { void Device::SubmitPendingCommandBuffer() {
if (pendingCommands == nil) { if (mPendingCommands == nil) {
return; return;
} }
// Ok, ObjC blocks are weird. My understanding is that local variables are captured by value // Ok, ObjC blocks are weird. My understanding is that local variables are captured by value
// so this-> works as expected. However it is unclear how members are captured, (are they // so this-> works as expected. However it is unclear how members are captured, (are they
// captured using this-> or by value?) so we make a copy of the pendingCommandSerial on the stack. // captured using this-> or by value?) so we make a copy of the pendingCommandSerial on the stack.
Serial pendingSerial = pendingCommandSerial; Serial pendingSerial = mPendingCommandSerial;
[pendingCommands addCompletedHandler:^(id<MTLCommandBuffer>) { [mPendingCommands addCompletedHandler:^(id<MTLCommandBuffer>) {
this->finishedCommandSerial = pendingSerial; this->mFinishedCommandSerial = pendingSerial;
}]; }];
[pendingCommands commit]; [mPendingCommands commit];
[pendingCommands release]; [mPendingCommands release];
pendingCommands = nil; mPendingCommands = nil;
pendingCommandSerial ++; mPendingCommandSerial ++;
} }
uint64_t Device::GetPendingCommandSerial() { uint64_t Device::GetPendingCommandSerial() {
@ -183,15 +183,15 @@ namespace metal {
// enqueued on the next Tick() and eventually increments the serial. Otherwise if no GPU work // enqueued on the next Tick() and eventually increments the serial. Otherwise if no GPU work
// happens we could be waiting for this serial forever. // happens we could be waiting for this serial forever.
GetPendingCommandBuffer(); GetPendingCommandBuffer();
return pendingCommandSerial; return mPendingCommandSerial;
} }
MapReadRequestTracker* Device::GetMapReadTracker() const { MapReadRequestTracker* Device::GetMapReadTracker() const {
return mapReadTracker; return mMapReadTracker;
} }
ResourceUploader* Device::GetResourceUploader() const { ResourceUploader* Device::GetResourceUploader() const {
return resourceUploader; return mResourceUploader;
} }
// Bind Group // Bind Group
@ -220,16 +220,16 @@ namespace metal {
Queue::Queue(QueueBuilder* builder) Queue::Queue(QueueBuilder* builder)
: QueueBase(builder) { : QueueBase(builder) {
Device* device = ToBackend(builder->GetDevice()); Device* device = ToBackend(builder->GetDevice());
commandQueue = [device->GetMTLDevice() newCommandQueue]; mCommandQueue = [device->GetMTLDevice() newCommandQueue];
} }
Queue::~Queue() { Queue::~Queue() {
[commandQueue release]; [mCommandQueue release];
commandQueue = nil; mCommandQueue = nil;
} }
id<MTLCommandQueue> Queue::GetMTLCommandQueue() { id<MTLCommandQueue> Queue::GetMTLCommandQueue() {
return commandQueue; return mCommandQueue;
} }
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) { void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) {

View File

@ -36,7 +36,7 @@ namespace metal {
const BindingIndexInfo& GetBindingIndexInfo(nxt::ShaderStage stage) const; const BindingIndexInfo& GetBindingIndexInfo(nxt::ShaderStage stage) const;
private: private:
PerStage<BindingIndexInfo> indexInfo; PerStage<BindingIndexInfo> mIndexInfo;
}; };
} }

View File

@ -41,15 +41,15 @@ namespace metal {
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: case nxt::BindingType::UniformBuffer:
case nxt::BindingType::StorageBuffer: case nxt::BindingType::StorageBuffer:
indexInfo[stage][group][binding] = bufferIndex; mIndexInfo[stage][group][binding] = bufferIndex;
bufferIndex++; bufferIndex++;
break; break;
case nxt::BindingType::Sampler: case nxt::BindingType::Sampler:
indexInfo[stage][group][binding] = samplerIndex; mIndexInfo[stage][group][binding] = samplerIndex;
samplerIndex++; samplerIndex++;
break; break;
case nxt::BindingType::SampledTexture: case nxt::BindingType::SampledTexture:
indexInfo[stage][group][binding] = textureIndex; mIndexInfo[stage][group][binding] = textureIndex;
textureIndex++; textureIndex++;
break; break;
} }
@ -59,7 +59,7 @@ namespace metal {
} }
const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo(nxt::ShaderStage stage) const { const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo(nxt::ShaderStage stage) const {
return indexInfo[stage]; return mIndexInfo[stage];
} }
} }

View File

@ -33,9 +33,9 @@ namespace metal {
void Encode(id<MTLRenderCommandEncoder> encoder); void Encode(id<MTLRenderCommandEncoder> encoder);
private: private:
MTLIndexType mtlIndexType; MTLIndexType mMtlIndexType;
MTLPrimitiveType mtlPrimitiveTopology; MTLPrimitiveType mMtlPrimitiveTopology;
id<MTLRenderPipelineState> mtlRenderPipelineState = nil; id<MTLRenderPipelineState> mMtlRenderPipelineState = nil;
}; };
} }

View File

@ -66,8 +66,8 @@ namespace metal {
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder) RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
: RenderPipelineBase(builder), : RenderPipelineBase(builder),
mtlIndexType(MTLIndexFormat(GetIndexFormat())), mMtlIndexType(MTLIndexFormat(GetIndexFormat())),
mtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) { mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) {
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice(); auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
@ -116,7 +116,7 @@ namespace metal {
// TODO(kainino@chromium.org): push constants, textures, samplers // TODO(kainino@chromium.org): push constants, textures, samplers
NSError *error = nil; NSError *error = nil;
mtlRenderPipelineState = [mtlDevice mMtlRenderPipelineState = [mtlDevice
newRenderPipelineStateWithDescriptor:descriptor error:&error]; newRenderPipelineStateWithDescriptor:descriptor error:&error];
if (error != nil) { if (error != nil) {
NSLog(@" error => %@", error); NSLog(@" error => %@", error);
@ -129,19 +129,19 @@ namespace metal {
} }
RenderPipeline::~RenderPipeline() { RenderPipeline::~RenderPipeline() {
[mtlRenderPipelineState release]; [mMtlRenderPipelineState release];
} }
MTLIndexType RenderPipeline::GetMTLIndexType() const { MTLIndexType RenderPipeline::GetMTLIndexType() const {
return mtlIndexType; return mMtlIndexType;
} }
MTLPrimitiveType RenderPipeline::GetMTLPrimitiveTopology() const { MTLPrimitiveType RenderPipeline::GetMTLPrimitiveTopology() const {
return mtlPrimitiveTopology; return mMtlPrimitiveTopology;
} }
void RenderPipeline::Encode(id<MTLRenderCommandEncoder> encoder) { void RenderPipeline::Encode(id<MTLRenderCommandEncoder> encoder) {
[encoder setRenderPipelineState:mtlRenderPipelineState]; [encoder setRenderPipelineState:mMtlRenderPipelineState];
} }
} }

View File

@ -34,8 +34,8 @@ namespace metal {
void Tick(Serial finishedSerial); void Tick(Serial finishedSerial);
private: private:
Device* device; Device* mDevice;
SerialQueue<id<MTLBuffer>> inflightUploadBuffers; SerialQueue<id<MTLBuffer>> mInflightUploadBuffers;
}; };

View File

@ -20,20 +20,20 @@ namespace backend {
namespace metal { namespace metal {
ResourceUploader::ResourceUploader(Device* device) ResourceUploader::ResourceUploader(Device* device)
: device(device) { : mDevice(device) {
} }
ResourceUploader::~ResourceUploader() { ResourceUploader::~ResourceUploader() {
ASSERT(inflightUploadBuffers.Empty()); ASSERT(mInflightUploadBuffers.Empty());
} }
void ResourceUploader::BufferSubData(id<MTLBuffer> buffer, uint32_t start, uint32_t size, const void* data) { void ResourceUploader::BufferSubData(id<MTLBuffer> buffer, uint32_t start, uint32_t size, const void* data) {
// TODO(cwallez@chromium.org) use a ringbuffer instead of creating a small buffer for each update // TODO(cwallez@chromium.org) use a ringbuffer instead of creating a small buffer for each update
id<MTLBuffer> uploadBuffer = [device->GetMTLDevice() newBufferWithLength:size id<MTLBuffer> uploadBuffer = [mDevice->GetMTLDevice() newBufferWithLength:size
options:MTLResourceStorageModeShared]; options:MTLResourceStorageModeShared];
memcpy([uploadBuffer contents], data, size); memcpy([uploadBuffer contents], data, size);
id<MTLCommandBuffer> commandBuffer = device->GetPendingCommandBuffer(); id<MTLCommandBuffer> commandBuffer = mDevice->GetPendingCommandBuffer();
id<MTLBlitCommandEncoder> encoder = [commandBuffer blitCommandEncoder]; id<MTLBlitCommandEncoder> encoder = [commandBuffer blitCommandEncoder];
[encoder copyFromBuffer:uploadBuffer [encoder copyFromBuffer:uploadBuffer
sourceOffset:0 sourceOffset:0
@ -42,14 +42,14 @@ namespace metal {
size:size]; size:size];
[encoder endEncoding]; [encoder endEncoding];
inflightUploadBuffers.Enqueue(uploadBuffer, device->GetPendingCommandSerial()); mInflightUploadBuffers.Enqueue(uploadBuffer, mDevice->GetPendingCommandSerial());
} }
void ResourceUploader::Tick(Serial finishedSerial) { void ResourceUploader::Tick(Serial finishedSerial) {
for (id<MTLBuffer> buffer : inflightUploadBuffers.IterateUpTo(finishedSerial)) { for (id<MTLBuffer> buffer : mInflightUploadBuffers.IterateUpTo(finishedSerial)) {
[buffer release]; [buffer release];
} }
inflightUploadBuffers.ClearUpTo(finishedSerial); mInflightUploadBuffers.ClearUpTo(finishedSerial);
} }
} }

View File

@ -30,7 +30,7 @@ namespace metal {
id<MTLSamplerState> GetMTLSamplerState(); id<MTLSamplerState> GetMTLSamplerState();
private: private:
id<MTLSamplerState> mtlSamplerState = nil; id<MTLSamplerState> mMtlSamplerState = nil;
}; };
} }

View File

@ -49,15 +49,15 @@ namespace metal {
// TODO(kainino@chromium.org): wrap modes // TODO(kainino@chromium.org): wrap modes
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice(); auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
mtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:desc]; mMtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:desc];
} }
Sampler::~Sampler() { Sampler::~Sampler() {
[mtlSamplerState release]; [mMtlSamplerState release];
} }
id<MTLSamplerState> Sampler::GetMTLSamplerState() { id<MTLSamplerState> Sampler::GetMTLSamplerState() {
return mtlSamplerState; return mMtlSamplerState;
} }
} }

View File

@ -42,7 +42,7 @@ namespace metal {
// Calling compile on CompilerMSL somehow changes internal state that makes subsequent // Calling compile on CompilerMSL somehow changes internal state that makes subsequent
// compiles return invalid MSL. We keep the spirv around and recreate the compiler everytime // compiles return invalid MSL. We keep the spirv around and recreate the compiler everytime
// we need to use it. // we need to use it.
std::vector<uint32_t> spirv; std::vector<uint32_t> mSpirv;
}; };
} }

View File

@ -42,14 +42,14 @@ namespace metal {
} }
ShaderModule::ShaderModule(ShaderModuleBuilder* builder) ShaderModule::ShaderModule(ShaderModuleBuilder* builder)
: ShaderModuleBase(builder), spirv(builder->AcquireSpirv()) { : ShaderModuleBase(builder), mSpirv(builder->AcquireSpirv()) {
spirv_cross::CompilerMSL compiler(spirv); spirv_cross::CompilerMSL compiler(mSpirv);
ExtractSpirvInfo(compiler); ExtractSpirvInfo(compiler);
} }
ShaderModule::MetalFunctionData ShaderModule::GetFunction(const char* functionName, ShaderModule::MetalFunctionData ShaderModule::GetFunction(const char* functionName,
const PipelineLayout* layout) const { const PipelineLayout* layout) const {
spirv_cross::CompilerMSL compiler(spirv); spirv_cross::CompilerMSL compiler(mSpirv);
// By default SPIRV-Cross will give MSL resources indices in increasing order. // By default SPIRV-Cross will give MSL resources indices in increasing order.
// To make the MSL indices match the indices chosen in the PipelineLayout, we build // To make the MSL indices match the indices chosen in the PipelineLayout, we build

View File

@ -35,7 +35,7 @@ namespace metal {
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override; void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
private: private:
id<MTLTexture> mtlTexture = nil; id<MTLTexture> mMtlTexture = nil;
}; };
class TextureView : public TextureViewBase { class TextureView : public TextureViewBase {

View File

@ -74,20 +74,20 @@ namespace metal {
desc.storageMode = MTLStorageModePrivate; desc.storageMode = MTLStorageModePrivate;
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice(); auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
mtlTexture = [mtlDevice newTextureWithDescriptor:desc]; mMtlTexture = [mtlDevice newTextureWithDescriptor:desc];
} }
Texture::Texture(TextureBuilder* builder, id<MTLTexture> mtlTexture) Texture::Texture(TextureBuilder* builder, id<MTLTexture> mtlTexture)
: TextureBase(builder), mtlTexture(mtlTexture) { : TextureBase(builder), mMtlTexture(mtlTexture) {
[mtlTexture retain]; [mMtlTexture retain];
} }
Texture::~Texture() { Texture::~Texture() {
[mtlTexture release]; [mMtlTexture release];
} }
id<MTLTexture> Texture::GetMTLTexture() { id<MTLTexture> Texture::GetMTLTexture() {
return mtlTexture; return mMtlTexture;
} }
void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) { void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) {