|
4 | 4 |
|
5 | 5 | using namespace nri; |
6 | 6 |
|
| 7 | +// |
| 8 | +//BindingInfo::BindingInfo(StdAllocator<uint8_t>& allocator) |
| 9 | +// : hasVariableDescriptorNum(allocator) |
| 10 | +// , descriptorSetRangeDescs(allocator) |
| 11 | +// , dynamicConstantBufferDescs(allocator) |
| 12 | +// , descriptorSetDescs(allocator) { |
| 13 | +// |
| 14 | +//} |
| 15 | +// |
| 16 | + |
7 | 17 | PipelineLayoutMTL::~PipelineLayoutMTL() { |
8 | 18 |
|
9 | 19 | } |
10 | 20 |
|
11 | 21 | Result PipelineLayoutMTL::Create(const PipelineLayoutDesc& pipelineLayoutDesc) { |
| 22 | + |
| 23 | + |
| 24 | + size_t rangeNum = 0; |
| 25 | + size_t dynamicConstantBufferNum = 0; |
| 26 | + for (uint32_t i = 0; i < pipelineLayoutDesc.descriptorSetNum; i++) { |
| 27 | + rangeNum += pipelineLayoutDesc.descriptorSets[i].rangeNum; |
| 28 | + dynamicConstantBufferNum += pipelineLayoutDesc.descriptorSets[i].dynamicConstantBufferNum; |
| 29 | + } |
| 30 | + |
12 | 31 | m_DescriptorSets.resize(pipelineLayoutDesc.descriptorSetNum); |
| 32 | + m_HasVariableDescriptorNum.resize(pipelineLayoutDesc.descriptorSetNum); |
| 33 | + m_DescriptorSetRangeDescs.reserve(rangeNum); |
| 34 | + m_DynamicConstantBufferDescs.reserve(dynamicConstantBufferNum); |
| 35 | + |
13 | 36 | for (uint32_t i = 0; i < pipelineLayoutDesc.descriptorSetNum; i++) { |
14 | 37 | const DescriptorSetDesc& descriptorSetDesc = pipelineLayoutDesc.descriptorSets[i]; |
15 | 38 |
|
16 | | - NSMutableArray<MTLArgumentDescriptor*>* argumentDescriptors = [[NSMutableArray alloc] init]; |
17 | | - MTLArgumentDescriptor* argDescriptor = [MTLArgumentDescriptor argumentDescriptor]; |
| 39 | + // Binding info |
| 40 | + m_HasVariableDescriptorNum[i] = false; |
| 41 | + m_DescriptorSets[i].m_DescriptorSetDesc = descriptorSetDesc; |
| 42 | + m_DescriptorSets[i].m_DescriptorSetDesc.ranges = m_DescriptorSetRangeDescs.data() +m_DescriptorSetRangeDescs.size(); |
| 43 | + m_DescriptorSets[i].m_DescriptorSetDesc.dynamicConstantBuffers = m_DynamicConstantBufferDescs.data() + m_DynamicConstantBufferDescs.size(); |
| 44 | + m_DescriptorSetRangeDescs.insert(m_DescriptorSetRangeDescs.end(), descriptorSetDesc.ranges, descriptorSetDesc.ranges + descriptorSetDesc.rangeNum); |
| 45 | + m_DynamicConstantBufferDescs.insert(m_DynamicConstantBufferDescs.end(), descriptorSetDesc.dynamicConstantBuffers, descriptorSetDesc.dynamicConstantBuffers + descriptorSetDesc.dynamicConstantBufferNum); |
18 | 46 |
|
| 47 | + NSMutableArray<MTLArgumentDescriptor*>* argumentDescriptors = [[NSMutableArray alloc] init]; |
19 | 48 | for(size_t r = 0; r < descriptorSetDesc.rangeNum; r++) { |
20 | | - |
| 49 | + MTLArgumentDescriptor* argDescriptor = [MTLArgumentDescriptor argumentDescriptor]; |
| 50 | + const DescriptorRangeDesc* range = &descriptorSetDesc.ranges[r]; |
| 51 | + argDescriptor.arrayLength = range->descriptorNum; |
| 52 | + argDescriptor.access = MTLBindingAccessReadWrite; |
| 53 | + argDescriptor.index = range->baseRegisterIndex; |
| 54 | + switch(range->descriptorType) { |
| 55 | + case DescriptorType::TEXTURE: |
| 56 | + argDescriptor.dataType = MTLDataTypeTexture; |
| 57 | + argDescriptor.textureType = MTLTextureType2D; // descriptor type does not have this |
| 58 | + break; |
| 59 | + case DescriptorType::SAMPLER: |
| 60 | + argDescriptor.dataType = MTLDataTypeSampler; |
| 61 | + break; |
| 62 | + case DescriptorType::CONSTANT_BUFFER: |
| 63 | + case DescriptorType::STORAGE_TEXTURE: |
| 64 | + case DescriptorType::BUFFER: |
| 65 | + case DescriptorType::STORAGE_BUFFER: |
| 66 | + case DescriptorType::STRUCTURED_BUFFER: |
| 67 | + case DescriptorType::STORAGE_STRUCTURED_BUFFER: |
| 68 | + argDescriptor.dataType = MTLDataTypeStruct; |
| 69 | + break; |
| 70 | + case DescriptorType::ACCELERATION_STRUCTURE: |
| 71 | + argDescriptor.dataType = MTLDataTypePrimitiveAccelerationStructure; |
| 72 | + break; |
| 73 | + default: |
| 74 | + break; |
| 75 | + } |
21 | 76 | } |
22 | | - |
23 | | - |
24 | | - //argDescriptor.access = memberDescriptor.mAccessType; |
25 | | - //argDescriptor.arrayLength = memberDescriptor.mArrayLength; |
26 | | - //argDescriptor.constantBlockAlignment = memberDescriptor.mAlignment; |
27 | | - //argDescriptor.dataType = memberDescriptor.mDataType; |
28 | | - //argDescriptor.index = memberDescriptor.mArgumentIndex; |
29 | | - //argDescriptor.textureType = memberDescriptor.mTextureType; |
30 | | - |
31 | | - [argumentDescriptors addObject:argDescriptor]; |
32 | 77 | m_DescriptorSets[i].m_ArgumentDescriptors = argumentDescriptors; |
33 | 78 |
|
34 | 79 | } |
|
0 commit comments