WrappedID3D12DescriptorHeap::WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *real, WrappedID3D12Device *device, const D3D12_DESCRIPTOR_HEAP_DESC &desc) : WrappedDeviceChild12(real, device) { realCPUBase = real->GetCPUDescriptorHandleForHeapStart(); realGPUBase = real->GetGPUDescriptorHandleForHeapStart(); increment = device->GetUnwrappedDescriptorIncrement(desc.Type); numDescriptors = desc.NumDescriptors; descriptors = new D3D12Descriptor[numDescriptors]; RDCEraseMem(descriptors, sizeof(D3D12Descriptor) * numDescriptors); for(UINT i = 0; i < numDescriptors; i++) { // only need to set this once, it's aliased between samp and nonsamp descriptors[i].samp.heap = this; descriptors[i].samp.idx = i; // initially descriptors are undefined. This way we just fill them with // some null SRV descriptor so it's safe to copy around etc but is no // less undefined for the application to use descriptors[i].nonsamp.type = D3D12Descriptor::TypeUndefined; } }
wstring Win32CallstackResolver::pdbBrowse(wstring startingPoint) { OPENFILENAMEW ofn; RDCEraseMem(&ofn, sizeof(ofn)); wchar_t outBuf[MAX_PATH*2]; wcscpy_s(outBuf, startingPoint.c_str()); ofn.lStructSize = sizeof(OPENFILENAME); ofn.lpstrTitle = L"Locate PDB File"; ofn.lpstrFilter = L"PDB File\0*.pdb\0"; ofn.lpstrFile = outBuf; ofn.nMaxFile = MAX_PATH*2-1; ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST; // | OFN_ENABLEINCLUDENOTIFY | OFN_ENABLEHOOK BOOL ret = GetOpenFileNameW(&ofn); if(ret == FALSE) return L""; return outBuf; }
void WrappedVulkan::RemapMemoryIndices(VkPhysicalDeviceMemoryProperties *memProps, uint32_t **memIdxMap) { uint32_t *memmap = new uint32_t[32]; *memIdxMap = memmap; m_MemIdxMaps.push_back(memmap); RDCEraseMem(memmap, sizeof(uint32_t) * 32); // basic idea here: // We want to discourage coherent memory maps as much as possible while capturing, // as they're painful to track. Unfortunately the spec guarantees that at least // one such memory type will be available, and we must follow that. // // So, rather than removing the coherent memory type we make it as unappealing as // possible and try and ensure that only someone looking specifically for a coherent // memory type will find it. That way hopefully memory selection algorithms will // pick non-coherent memory and do proper flushing as necessary. // we want to add a new heap, hopefully there is room #if CREATE_NON_COHERENT_ATTRACTIVE_MEMORY RDCASSERT(memProps->memoryHeapCount < VK_MAX_MEMORY_HEAPS - 1); uint32_t coherentHeap = memProps->memoryHeapCount; memProps->memoryHeapCount++; // make a new heap that's tiny. If any applications look at heap sizes to determine // viability, they'll dislike the look of this one (the real heaps should be much // bigger). memProps->memoryHeaps[coherentHeap].flags = 0; // not device local memProps->memoryHeaps[coherentHeap].size = 32 * 1024 * 1024; #endif // for every coherent memory type, add a non-coherent type first, then // mark the coherent type with our crappy heap uint32_t origCount = memProps->memoryTypeCount; VkMemoryType origTypes[VK_MAX_MEMORY_TYPES]; memcpy(origTypes, memProps->memoryTypes, sizeof(origTypes)); uint32_t newtypeidx = 0; for(uint32_t i = 0; i < origCount; i++) { #if CREATE_NON_COHERENT_ATTRACTIVE_MEMORY if((origTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0) { // coherent type found. // can we still add a new type without exceeding the max? if(memProps->memoryTypeCount + 1 <= VK_MAX_MEMORY_TYPES) { // copy both types from the original type memProps->memoryTypes[newtypeidx] = origTypes[i]; memProps->memoryTypes[newtypeidx + 1] = origTypes[i]; // mark first as non-coherent, cached memProps->memoryTypes[newtypeidx].propertyFlags &= ~VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; memProps->memoryTypes[newtypeidx].propertyFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT; // point second at bad heap memProps->memoryTypes[newtypeidx + 1].heapIndex = coherentHeap; // point both new types at this original type memmap[newtypeidx++] = i; memmap[newtypeidx++] = i; // we added a type memProps->memoryTypeCount++; } else { // can't add a new type, but we can at least repoint this coherent // type at the bad heap to discourage use memProps->memoryTypes[newtypeidx] = origTypes[i]; memProps->memoryTypes[newtypeidx].heapIndex = coherentHeap; memmap[newtypeidx++] = i; } } else #endif { // non-coherent already or non-hostvisible, just copy through memProps->memoryTypes[newtypeidx] = origTypes[i]; memmap[newtypeidx++] = i; } } }
VkResult WrappedVulkan::vkCreateFramebuffer( VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer) { VkImageView *unwrapped = GetTempArray<VkImageView>(pCreateInfo->attachmentCount); for(uint32_t i=0; i < pCreateInfo->attachmentCount; i++) unwrapped[i] = Unwrap(pCreateInfo->pAttachments[i]); VkFramebufferCreateInfo unwrappedInfo = *pCreateInfo; unwrappedInfo.renderPass = Unwrap(unwrappedInfo.renderPass); unwrappedInfo.pAttachments = unwrapped; VkResult ret = ObjDisp(device)->CreateFramebuffer(Unwrap(device), &unwrappedInfo, pAllocator, pFramebuffer); if(ret == VK_SUCCESS) { ResourceId id = GetResourceManager()->WrapResource(Unwrap(device), *pFramebuffer); if(m_State >= WRITING) { Chunk *chunk = NULL; { CACHE_THREAD_SERIALISER(); SCOPED_SERIALISE_CONTEXT(CREATE_FRAMEBUFFER); Serialise_vkCreateFramebuffer(localSerialiser, device, pCreateInfo, NULL, pFramebuffer); chunk = scope.Get(); } VkResourceRecord *record = GetResourceManager()->AddResourceRecord(*pFramebuffer); record->AddChunk(chunk); record->imageAttachments = new VkResourceRecord*[VkResourceRecord::MaxImageAttachments]; RDCASSERT(pCreateInfo->attachmentCount <= VkResourceRecord::MaxImageAttachments); RDCEraseMem(record->imageAttachments, sizeof(ResourceId)*VkResourceRecord::MaxImageAttachments); if(pCreateInfo->renderPass != VK_NULL_HANDLE) record->AddParent(GetRecord(pCreateInfo->renderPass)); for(uint32_t i=0; i < pCreateInfo->attachmentCount; i++) { VkResourceRecord *attRecord = GetRecord(pCreateInfo->pAttachments[i]); record->AddParent(attRecord); record->imageAttachments[i] = attRecord; } } else { GetResourceManager()->AddLiveResource(id, *pFramebuffer); m_CreationInfo.m_Framebuffer[id].Init(GetResourceManager(), m_CreationInfo, &unwrappedInfo); } } return ret; }