void JPJavaEnv::load(const string& path) { TRACE_IN("JPJavaEnv::load"); // WIN32 GetAdapter()->loadLibrary((char*)path.c_str()); CreateJVM_Method = (jint (JNICALL *)(struct JavaVM_ ** ,void ** ,void *))GetAdapter()->getSymbol("JNI_CreateJavaVM"); GetCreatedJVMs_Method = (jint (JNICALL *)(struct JavaVM_ ** , jsize, jsize*))GetAdapter()->getSymbol("JNI_GetCreatedJavaVMs"); // No idea why I can't find this symbol .... no matter, it does not work anyway. //JNI_DestroyJavaVM = (jint (__stdcall *)(struct JavaVM_ *))GetAdapter()->getSymbol("DestroyJavaVM"); TRACE_OUT; }
FStructuredBufferRHIRef FD3D12DynamicRHI::RHICreateStructuredBuffer(uint32 Stride, uint32 Size, uint32 InUsage, FRHIResourceCreateInfo& CreateInfo) { // Check for values that will cause D3D calls to fail check(Size / Stride > 0 && Size % Stride == 0); const D3D12_RESOURCE_DESC Desc = CreateStructuredBufferResourceDesc(Size, InUsage); // Structured buffers, non-byte address buffers, need to be aligned to their stride to ensure that they // can be addressed correctly with element based offsets. const uint32 Alignment = ((InUsage & (BUF_ByteAddressBuffer | BUF_DrawIndirect)) == 0) ? Stride : 4; FD3D12StructuredBuffer* NewBuffer = GetAdapter().CreateRHIBuffer<FD3D12StructuredBuffer>(nullptr, Desc, Alignment, Stride, Size, InUsage, CreateInfo, false); UpdateBufferStats(&NewBuffer->ResourceLocation, true, D3D12_BUFFER_TYPE_STRUCTURED); return NewBuffer; }
/* jshadow: dumb - we get the first IP address (if it exists) */ bool TWinPCAP::GetAdapterIP(int adapter, IN_ADDR * ip, IN_ADDR * mask) { /* Preparation: PCAP */ pcap_if_t * d = GetAdapter(adapter); if (!d) return false; /* look for IP address */ for (pcap_addr_t * addr = d->addresses; addr; addr = addr->next) { /* we are interested only in AF_INET (IPv4) 'cause ARP is defined in IPv4 stack */ if (addr->addr->sa_family == AF_INET) { if (ip) ip->S_un.S_addr = ((struct sockaddr_in *)addr->addr)->sin_addr.S_un.S_addr; if (mask) mask->S_un.S_addr = ((struct sockaddr_in *)addr->netmask)->sin_addr.S_un.S_addr; return true; } } /* not found */ return false; }
FUniformBufferRHIRef FD3D12DynamicRHI::RHICreateUniformBuffer(const void* Contents, const FRHIUniformBufferLayout& Layout, EUniformBufferUsage Usage) { SCOPE_CYCLE_COUNTER(STAT_D3D12UpdateUniformBufferTime); //Note: This is not overly efficient in the mGPU case (we create two+ upload locations) but the CPU savings of having no extra indirection to the resource are worth // it in single node. // Create the uniform buffer FD3D12UniformBuffer* UniformBufferOut = GetAdapter().CreateLinkedObject<FD3D12UniformBuffer>([&](FD3D12Device* Device) -> FD3D12UniformBuffer* { // If NumBytesActualData == 0, this uniform buffer contains no constants, only a resource table. FD3D12UniformBuffer* NewUniformBuffer = new FD3D12UniformBuffer(Device, Layout); check(nullptr != NewUniformBuffer); const uint32 NumBytesActualData = Layout.ConstantBufferSize; if (NumBytesActualData > 0) { // Constant buffers must also be 16-byte aligned. const uint32 NumBytes = Align(NumBytesActualData, D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT); // Allocate a size that is big enough for a multiple of 256 check(Align(NumBytes, 16) == NumBytes); check(Align(Contents, 16) == Contents); check(NumBytes <= D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16); void* MappedData = nullptr; if (Usage == EUniformBufferUsage::UniformBuffer_MultiFrame) { // Uniform buffers that live for multiple frames must use the more expensive and persistent allocation path FD3D12DynamicHeapAllocator& Allocator = GetAdapter().GetUploadHeapAllocator(); MappedData = Allocator.AllocUploadResource(NumBytes, DEFAULT_CONTEXT_UPLOAD_POOL_ALIGNMENT, NewUniformBuffer->ResourceLocation); } else { // Uniform buffers which will live for 1 frame at the max can be allocated very efficently from a ring buffer FD3D12FastConstantAllocator& Allocator = GetAdapter().GetTransientUniformBufferAllocator(); MappedData = Allocator.Allocate(NumBytes, NewUniformBuffer->ResourceLocation); } check(NewUniformBuffer->ResourceLocation.GetOffsetFromBaseOfResource() % 16 == 0); check(NewUniformBuffer->ResourceLocation.GetSize() == NumBytes); // Copy the data to the upload heap check(MappedData != nullptr); FMemory::Memcpy(MappedData, Contents, NumBytesActualData); } // The GPUVA is used to see if this uniform buffer contains constants or is just a resource table. check((NumBytesActualData > 0) ? (0 != NewUniformBuffer->ResourceLocation.GetGPUVirtualAddress()) : (0 == NewUniformBuffer->ResourceLocation.GetGPUVirtualAddress())); return NewUniformBuffer; }); if (Layout.Resources.Num()) { const int32 NumResources = Layout.Resources.Num(); FRHIResource** InResources = (FRHIResource**)((uint8*)Contents + Layout.ResourceOffset); FD3D12UniformBuffer* CurrentBuffer = UniformBufferOut; while (CurrentBuffer != nullptr) { CurrentBuffer->ResourceTable.Empty(NumResources); CurrentBuffer->ResourceTable.AddZeroed(NumResources); for (int32 i = 0; i < NumResources; ++i) { check(InResources[i]); CurrentBuffer->ResourceTable[i] = InResources[i]; } CurrentBuffer = CurrentBuffer->GetNextObject(); } } return UniformBufferOut; }
/* returns adapter description */ char * TWinPCAP::GetAdapterDescription(int adapter) { pcap_if_t * d = GetAdapter(adapter); return (d) ? d->description : NULL; }
/* returns adapter name */ char * TWinPCAP::GetAdapterName(int adapter) { pcap_if_t * d = GetAdapter(adapter); return (d) ? d->name : NULL; }
/* jShadow: black magic! here we merge IP Helper with WinPCAP - we go through all * IP addresses via IP Helper and check if some of them matches one of the addresses * of WinPCAP adapter address list. if a match is found we get MAC via IP Helper */ bool TWinPCAP::GetAdapterMAC(int adapter, unsigned char * mac) { bool ok = false; /* Preparation: PCAP */ pcap_if_t * d = GetAdapter(adapter); if (!d) return false; /* Preparation: IPHlpAPI */ PMIB_IPADDRTABLE mib_ip_table = NULL; ULONG mib_ip_table_size = 0; /* walk through adapters via IPHelper API*/ GetIpAddrTable(mib_ip_table, &mib_ip_table_size, FALSE); if (mib_ip_table_size != 0) { mib_ip_table = (PMIB_IPADDRTABLE) new unsigned char[mib_ip_table_size]; if (mib_ip_table) { if (GetIpAddrTable(mib_ip_table, &mib_ip_table_size, FALSE) == NO_ERROR) { for (unsigned int i = 0; i < mib_ip_table->dwNumEntries && !ok; i++) { /* walk through adapter addresses */ for (pcap_addr_t * addr = d->addresses; addr && !ok; addr = addr->next) { /* we are interested only in AF_INET (IPv4) 'cause ARP is defined in IPv4 stack */ if (addr->addr->sa_family == AF_INET && ((struct sockaddr_in *)addr->addr)->sin_addr.S_un.S_addr == mib_ip_table->table[i].dwAddr) { /* gotcha - fetch HW address! */ MIB_IFROW mib_if_entry; mib_if_entry.dwIndex = mib_ip_table->table[i].dwIndex; if (GetIfEntry(&mib_if_entry) == NO_ERROR) { ok = true; memcpy(mac, mib_if_entry.bPhysAddr, 6); } /* if */ } /* if */ } /* for on winpcap adapter list */ } /* for each of IP address matches */ } /* if GetIpAddrTable */ /* cleanup */ delete [] mib_ip_table; } } /* hack: we fill mac address with FF-s if we failed to find it. this * workaround is needed to avoid 3 more lines of code in send_packet - * if we failed to figure out mac address, we'll send from broadcast * address (we'll most likely get a responce in that case). To speed * up send_packet code we move invariant MAC workaroud here. */ if (!ok) { memset(mac, 0xff, 6); } return ok; }
void* FD3D12DynamicRHI::LockBuffer(FRHICommandListImmediate* RHICmdList, BufferType* Buffer, uint32 Offset, uint32 Size, EResourceLockMode LockMode) { #if STATS LockBufferCalls++; SCOPE_CYCLE_COUNTER(STAT_D3D12LockBufferTime); INC_DWORD_STAT_BY(STAT_D3D12LockBufferCalls, LockBufferCalls); #endif FD3D12LockedResource& LockedData = Buffer->LockedData; check(LockedData.bLocked == false); FD3D12Device* Device = GetRHIDevice(); FD3D12Adapter& Adapter = GetAdapter(); // Determine whether the buffer is dynamic or not. const bool bIsDynamic = (Buffer->GetUsage() & BUF_AnyDynamic) ? true : false; void* Data = nullptr; if (bIsDynamic) { check(LockMode == RLM_WriteOnly); BufferType* CurrentBuffer = Buffer; // Update all of the resources in the LDA chain while (CurrentBuffer) { // Allocate a new resource // If on the RenderThread, queue up a command on the RHIThread to rename this buffer at the correct time if (ShouldDeferBufferLockOperation(RHICmdList)) { FRHICommandRenameUploadBuffer<BufferType>* Command = new (RHICmdList->AllocCommand<FRHICommandRenameUploadBuffer<BufferType>>()) FRHICommandRenameUploadBuffer<BufferType>(CurrentBuffer, Device); Data = Adapter.GetUploadHeapAllocator().AllocUploadResource(Buffer->GetSize(), Buffer->BufferAlignment, Command->NewResource); } else { FD3D12ResourceLocation Location(CurrentBuffer->GetParentDevice()); Data = Adapter.GetUploadHeapAllocator().AllocUploadResource(Buffer->GetSize(), Buffer->BufferAlignment, Location); CurrentBuffer->Rename(Location); } CurrentBuffer = CurrentBuffer->GetNextObject(); } } else { FD3D12Resource* pResource = Buffer->ResourceLocation.GetResource(); // Locking for read must occur immediately so we can't queue up the operations later. if (LockMode == RLM_ReadOnly) { LockedData.bLockedForReadOnly = true; // If the static buffer is being locked for reading, create a staging buffer. FD3D12Resource* StagingBuffer = nullptr; const GPUNodeMask Node = Device->GetNodeMask(); VERIFYD3D12RESULT(Adapter.CreateBuffer(D3D12_HEAP_TYPE_READBACK, Node, Node, Offset + Size, &StagingBuffer)); // Copy the contents of the buffer to the staging buffer. { const auto& pfnCopyContents = [&]() { FD3D12CommandContext& DefaultContext = Device->GetDefaultCommandContext(); FD3D12CommandListHandle& hCommandList = DefaultContext.CommandListHandle; FScopeResourceBarrier ScopeResourceBarrierSource(hCommandList, pResource, pResource->GetDefaultResourceState(), D3D12_RESOURCE_STATE_COPY_SOURCE, 0); // Don't need to transition upload heaps DefaultContext.numCopies++; hCommandList->CopyBufferRegion( StagingBuffer->GetResource(), 0, pResource->GetResource(), Offset, Size); hCommandList.UpdateResidency(StagingBuffer); hCommandList.UpdateResidency(pResource); DefaultContext.FlushCommands(true); }; if (ShouldDeferBufferLockOperation(RHICmdList)) { // Sync when in the render thread implementation check(IsInRHIThread() == false); RHICmdList->ImmediateFlush(EImmediateFlushType::FlushRHIThread); pfnCopyContents(); } else { check(IsInRHIThread()); pfnCopyContents(); } } LockedData.ResourceLocation.AsStandAlone(StagingBuffer, Size); Data = LockedData.ResourceLocation.GetMappedBaseAddress(); } else { // If the static buffer is being locked for writing, allocate memory for the contents to be written to. Data = Device->GetDefaultFastAllocator().Allocate<FD3D12ScopeLock>(Size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT, &LockedData.ResourceLocation); } } LockedData.LockedOffset = Offset; LockedData.LockedPitch = Size; LockedData.bLocked = true; // Return the offset pointer check(Data != nullptr); return Data; }