Compare commits

..
Author SHA1 Message Date
Bud 5c2de5c5af VRAM Check for dgpus 2024-04-25 04:15:41 +01:00
Bud 39ae925267 commented potential solution for display adapter being defaulted to gpu 0 (igpu) 2024-04-24 10:28:30 +01:00
12 changed files with 96 additions and 456 deletions

No files matched your search

+93 -139
View File
@@ -22,8 +22,7 @@ Environment:
#include<string>
#include<tuple>
#include<vector>
// jocke added for comming dynamic edid loading
#include <iostream>
#include<iostream>
using namespace std;
using namespace Microsoft::IndirectDisp;
@@ -56,10 +55,6 @@ vector<tuple<int, int, int>> monitorModes;
vector< DISPLAYCONFIG_VIDEO_SIGNAL_INFO> s_KnownMonitorModes2;
UINT numVirtualDisplays;
std::vector<unsigned char>
Microsoft::IndirectDisp::IndirectDeviceContext::s_knownMonitorEdidData;
struct IndirectDeviceContextWrapper
{
IndirectDeviceContext* pContext;
@@ -121,7 +116,6 @@ vector<string> split(string& input, char delimiter)
return result;
}
void loadOptions(string filepath) {
ifstream ifs(filepath);
@@ -261,6 +255,8 @@ HRESULT Direct3DDevice::Init()
return hr;
}
// Bud was here - I believe this line above can allow us to select a certain gpu so before last d3d device. call if failed again in sequence
return S_OK;
}
@@ -436,101 +432,39 @@ constexpr DISPLAYCONFIG_VIDEO_SIGNAL_INFO dispinfo(UINT32 h, UINT32 v, UINT32 r)
};
}
// Jocke, createing a 512 byte array filled with 0 values (largest edid bin without breaking standards)
std::vector<BYTE> s_knownMonitorEdidData;
static void edidLoad(const std::string& filename) {
std::wofstream logFile("C:\\IddSampleDriver\\lddlog.txt", std::ios::app);
logFile << L"Entered EDIDLoad" << std::endl;
std::ifstream file(filename, std::ios::binary);
if (file.is_open()) {
logFile << L"Filename found for custom edid" << std::endl;
// Read file into vector
s_knownMonitorEdidData = std::vector<BYTE>(std::istreambuf_iterator<char>(file), {});
logFile << L"Replacing edid data in custom bin" << std::endl;
// Modify bytes at positions 8, 9, 10, and 11
s_knownMonitorEdidData[8] = 0x36;
s_knownMonitorEdidData[9] = 0x94;
s_knownMonitorEdidData[10] = 0x37;
s_knownMonitorEdidData[11] = 0x13;
logFile << L"calculating new checksum" << std::endl;
// Calculate checksum
int checksum = 0;
for (int i = 0; i < 128; ++i) {
checksum += s_knownMonitorEdidData[i];
}
checksum %= 256;
uint8_t bytesum = static_cast<BYTE>(checksum);
s_knownMonitorEdidData[127] = bytesum; // Store checksum as a byte, all byte number might be off by 1 (don't knwo how c++ handles array/vector position 0, if it's resereved or filed with data
logFile << L"Checksum calculated and placed on last byte of edid data" << std::endl;
}
else {
logFile << L"CustomEdid not found, checking default" << std::endl;
std::ifstream filedef("default.bin", std::ios::binary);
if (filedef.is_open()) {
// Read file into vector this is our pre patched default edid
s_knownMonitorEdidData = std::vector<BYTE>(std::istreambuf_iterator<char>(filedef), {});
logFile << L"Default.bin loaded into edid data" << std::endl;
}
else { // if all files are gone from install folder then use our minimal hardcoded edid
logFile << L"Defaulting to hardcoded edid" << std::endl;
string incode = " {\
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x36,0x94,0x37,0x13,0x00,0x00,0x00,0x00,\
0x05,0x16,0x01,0x03,0x6D,0x32,0x1C,0x78,0xEA,0x5E,0xC0,0xA4,0x59,0x4A,0x98,0x25,\
0x20,0x50,0x54,0x00,0x00,0x00,0xD1,0xC0,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,\
0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x3A,0x80,0x18,0x71,0x38,0x2D,0x40,0x58,0x2C,\
0x45,0x00,0xF4,0x19,0x11,0x00,0x00,0x1E,0x00,0x00,0x00,0xFF,0x00,0x4D,0x54,0x54,\
0x31,0x33,0x33,0x37,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0xFD,0x00,0x3B,\
0x3D,0x42,0x44,0x0F,0x00,0x0A,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0xFC,\
0x00,0x4D,0x54,0x54,0x31,0x33,0x33,0x37,0x0A,0x20,0x20,0x20,0x20,0x20,0x00,0x83}";
s_knownMonitorEdidData = std::vector<BYTE>(incode.begin(), incode.end());
}
}
logFile << L"Exiting EDID Load and closing log" << std::endl;
logFile.close();
};
// This is a sample monitor EDID - FOR SAMPLE PURPOSES ONLY
/*
const BYTE IndirectDeviceContext::s_KnownMonitorEdid[] = {
0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x36,0x94,0x37,0x13,0x37,0x13,0x37,0x13,
0x0d,0x22,0x01,0x03,0x80,0x32,0x1f,0x78,0x07,0xee,0x95,0xa3,0x54,0x4c,0x99,0x26,
0x0f,0x50,0x54,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x3a,0x80,0x18,0x71,0x38,0x2d,0x40,0x58,0x2c,
0x45,0x00,0x63,0xc8,0x10,0x00,0x00,0x06,0x00,0x00,0x00,0xfd,0x00,0x17,0xf0,0x0f,
0xff,0x37,0x00,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0xfc,0x00,0x4d,
0x54,0x54,0x31,0x33,0x33,0x37,0x0a,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x10,
0x00,0x13,0x37,0x13,0x37,0x13,0x37,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x33,
0x02,0x03,0x23,0x40,0x23,0x09,0x00,0x00,0xe6,0x06,0x0d,0x01,0xb4,0x78,0x01,0x67,
0x03,0x0c,0x00,0x00,0x00,0x10,0x6e,0xe3,0x05,0x80,0x00,0x67,0xd8,0x5d,0xc4,0x01,
0x6e,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9a,
0x70,0x13,0x79,0x00,0x00,0x00,0x00,0x1e,0x4d,0x54,0x54,0x0d,0x00,0x39,0x05,0x00,
0x00,0x0e,0x18,0x12,0x56,0x44,0x44,0x20,0x62,0x79,0x20,0x4d,0x69,0x6b,0x65,0x54,
0x68,0x65,0x54,0x65,0x63,0x68,0x03,0x01,0x14,0x72,0xd6,0x00,0x84,0xff,0x1d,0x9f,
0x00,0x2f,0x80,0x1f,0x00,0xdf,0x10,0x18,0x02,0x02,0x00,0x04,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x90
const BYTE IndirectDeviceContext::s_KnownMonitorEdid[] =
{
/* 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x79,0x5E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xA6,0x01,0x03,0x80,0x28,
0x1E,0x78,0x0A,0xEE,0x91,0xA3,0x54,0x4C,0x99,0x26,0x0F,0x50,0x54,0x20,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xA0,0x0F,0x20,0x00,0x31,0x58,0x1C,0x20,0x28,0x80,0x14,0x00,
0x90,0x2C,0x11,0x00,0x00,0x1E,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6E */
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x31, 0xD8, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x1F, 0x01, 0x04, 0xB5, 0x77, 0x22, 0x78,
0x3A, 0xC7, 0x25, 0xB1, 0x4B, 0x46, 0xA8, 0x26, 0x0E, 0x50, 0x54, 0x2F,
0xCF, 0x00, 0x71, 0x4F, 0x81, 0x00, 0x81, 0xC0, 0x81, 0x80, 0xA9, 0xC0,
0xB3, 0x00, 0x95, 0x00, 0xD1, 0xC0, 0x74, 0xD6, 0x00, 0xA0, 0xF0, 0x38,
0x40, 0x40, 0x30, 0x20, 0x3A, 0x00, 0xC0, 0x0E, 0x31, 0x00, 0x00, 0x1A,
0x00, 0x00, 0x00, 0xFC, 0x00, 0x49, 0x44, 0x44, 0x20, 0x48, 0x44, 0x52,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x85, 0x02, 0x03, 0x15, 0x00,
0xE3, 0x05, 0xC0, 0x00, 0xE6, 0x06, 0x05, 0x01, 0x8B, 0x73, 0x02, 0xE5,
0x01, 0x8B, 0x84, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC6
};
*/
IndirectDeviceContext::IndirectDeviceContext(_In_ WDFDEVICE WdfDevice) :
m_WdfDevice(WdfDevice)
@@ -547,7 +481,6 @@ IndirectDeviceContext::~IndirectDeviceContext()
void IndirectDeviceContext::InitAdapter()
{
edidLoad("C:\\IddSampleDriver\\user_edid.bin");
// ==============================
// TODO: Update the below diagnostic information in accordance with the target hardware. The strings and version
// numbers are used for telemetry and may be displayed to the user in some situations.
@@ -611,7 +544,6 @@ void IndirectDeviceContext::FinishInit()
}
}
void IndirectDeviceContext::CreateMonitor(unsigned int index) {
// ==============================
// TODO: In a real driver, the EDID should be retrieved dynamically from a connected physical monitor. The EDID
@@ -620,24 +552,18 @@ void IndirectDeviceContext::CreateMonitor(unsigned int index) {
// settings like viewing distance and scale factor. Manufacturers should also use a unique serial number every
// single device to ensure the OS can tell the monitors apart.
// ==============================
std::wofstream logFile("C:\\IddSampleDriver\\lddlog.txt", std::ios::app);
logFile << L"Creating a monitor start at " << std::endl;
WDF_OBJECT_ATTRIBUTES Attr;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&Attr, IndirectDeviceContextWrapper);
logFile << L"Initialized WDF object attributes at " << std::endl;
IDDCX_MONITOR_INFO MonitorInfo = {};
MonitorInfo.Size = sizeof(MonitorInfo);
MonitorInfo.MonitorType = DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI;
MonitorInfo.ConnectorIndex = index;
MonitorInfo.MonitorDescription.Size = sizeof(MonitorInfo.MonitorDescription);
MonitorInfo.MonitorDescription.Type = IDDCX_MONITOR_DESCRIPTION_TYPE_EDID;
MonitorInfo.MonitorDescription.DataSize = sizeof(s_knownMonitorEdidData);
MonitorInfo.MonitorDescription.pData = s_knownMonitorEdidData.data();
MonitorInfo.MonitorDescription.DataSize = sizeof(s_KnownMonitorEdid);
MonitorInfo.MonitorDescription.pData = const_cast<BYTE*>(s_KnownMonitorEdid);
// ==============================
// TODO: The monitor's container ID should be distinct from "this" device's container ID if the monitor is not
@@ -647,57 +573,76 @@ void IndirectDeviceContext::CreateMonitor(unsigned int index) {
// unique monitor or to use "this" device's container ID for a permanent/integrated monitor.
// ==============================
logFile << L"Initialized monitor info at " << std::endl;
// Create a container ID
CoCreateGuid(&MonitorInfo.MonitorContainerId);
logFile << L"Created container ID at " << std::endl;
IDARG_IN_MONITORCREATE MonitorCreate = {};
MonitorCreate.ObjectAttributes = &Attr;
MonitorCreate.pMonitorInfo = &MonitorInfo;
// Create a monitor object with the specified monitor descriptor
IDARG_OUT_MONITORCREATE MonitorCreateOut;
NTSTATUS Status = IddCxMonitorCreate(m_Adapter, &MonitorCreate, &MonitorCreateOut);
if (!NT_SUCCESS(Status))
{
logFile << L"Failed to create monitor object. Status code: " << Status << std::endl;
}
if (NT_SUCCESS(Status))
{
m_Monitor = MonitorCreateOut.MonitorObject;
// Associate the monitor with this device context
auto* pContext = WdfObjectGet_IndirectDeviceContextWrapper(MonitorCreateOut.MonitorObject);
pContext->pContext = this;
logFile << L"Created monitor object and associated it with this device context at " << std::endl;
// Tell the OS that the monitor has been plugged in
IDARG_OUT_MONITORARRIVAL ArrivalOut;
Status = IddCxMonitorArrival(m_Monitor, &ArrivalOut);
if (!NT_SUCCESS(Status))
{
logFile << L"Failed to plug in monitor. Status code: " << Status << std::endl;
}
else
{
logFile << L"Monitor has been plugged in at " << std::endl;
}
}
else {
logFile << L"Weird " << std::endl;
}
logFile << L"Creating a monitor end at " << std::endl;
logFile.close();
}
void IndirectDeviceContext::AssignSwapChain(IDDCX_SWAPCHAIN SwapChain, LUID RenderAdapter, HANDLE NewFrameEvent) // Jocke, is it here we could assign rendering gpu?
void IndirectDeviceContext::AssignSwapChain(IDDCX_SWAPCHAIN SwapChain, LUID RenderAdapter, HANDLE NewFrameEvent)
{
m_ProcessingThread.reset();
auto Device = make_shared<Direct3DDevice>(RenderAdapter);
// Create a factory to enumerate the adapters
IDXGIFactory1* pFactory;
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&pFactory));
if (FAILED(hr))
{
// Handle error
}
// Enumerate the adapters
IDXGIAdapter1* pAdapter;
std::vector<IDXGIAdapter1*> adapters;
for (UINT i = 0; pFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i)
{
adapters.push_back(pAdapter);
}
// Check for a dedicated GPU by checking whether or not the device has any dedicated video memory (Potential bug: Some igpus may contain dedicated video memory which then may default to that device)
bool dedicatedGPUAvailable = false;
LUID dedicatedGPULUID;
for (auto& adapter : adapters)
{
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
// Log the name of the GPU
std::wcout << L"GPU Name: " << desc.Description << std::endl;
// Check if the GPU is a dedicated GPU by checking the vendor ID
if (desc.DedicatedVideoMemory > 0 && desc.VendorId != 0x8086) // 0x8086 is Intel's vendor ID
{
dedicatedGPUAvailable = true;
dedicatedGPULUID = desc.AdapterLuid;
break;
}
}
// Choose the adapter based on whether a GPU with VRAM is available
LUID selectedAdapter = dedicatedGPUAvailable ? dedicatedGPULUID : RenderAdapter;
auto Device = make_shared<Direct3DDevice>(selectedAdapter);
if (FAILED(Device->Init()))
{
// It's important to delete the swap-chain if D3D initialization fails, so that the OS knows to generate a new
@@ -709,8 +654,17 @@ void IndirectDeviceContext::AssignSwapChain(IDDCX_SWAPCHAIN SwapChain, LUID Rend
// Create a new swap-chain processing thread
m_ProcessingThread.reset(new SwapChainProcessor(SwapChain, Device, NewFrameEvent));
}
// Clean up
for (auto& adapter : adapters)
{
adapter->Release(); //Due to the enumarate function directxobjects may start to fill up memory if reference count isnt decreased, We release it for each adapater so we dont use more resources
}
pFactory->Release(); //Similar for this, we created the IDXGIFactory1 object so we need to release it after
}
void IndirectDeviceContext::UnassignSwapChain()
{
// Stop processing the last swap-chain
@@ -809,7 +763,7 @@ NTSTATUS IddSampleMonitorGetDefaultModes(IDDCX_MONITOR MonitorObject, const IDAR
/// <summary>
/// Creates a target mode from the fundamental mode attributes.
/// </summary>
void CreateTargetMode(DISPLAYCONFIG_VIDEO_SIGNAL_INFO& Mode, UINT Width, UINT Height, UINT VSync) // Jocke, is it her we have the issue with 640*480 init when multiple vdds are chosen
void CreateTargetMode(DISPLAYCONFIG_VIDEO_SIGNAL_INFO& Mode, UINT Width, UINT Height, UINT VSync)
{
Mode.totalSize.cx = Mode.activeSize.cx = Width;
Mode.totalSize.cy = Mode.activeSize.cy = Height;
+2 -4
View File
@@ -80,7 +80,6 @@ namespace Microsoft
public:
IndirectDeviceContext(_In_ WDFDEVICE WdfDevice);
virtual ~IndirectDeviceContext();
static std::vector<BYTE> s_knownMonitorEdidData;
void InitAdapter();
void FinishInit();
@@ -101,8 +100,7 @@ namespace Microsoft
public:
static const DISPLAYCONFIG_VIDEO_SIGNAL_INFO s_KnownMonitorModes[];
static BYTE* s_KnownMonitorEdid();
static const BYTE s_KnownMonitorEdid[];
};
};
}
}
-2
View File
@@ -1,5 +1,3 @@
# THIS IS A DEVELOPMENT BRANCH. THIS BRANCH MAY BE UNSTABLE AND CAUSE ISSUES. WE ARE NOT LIABLE FOR ANY ISSUES IF YOU CHOOSE TO ATTEMPT TO BUILD THIS BRANCH
# Virtual Display Driver
based on Microsoft Indirect Display Driver Sample. This creates a virtual display in Windows that acts and functions just like a real one. It's useful for streaming, virtual reality applications, recording, headless servers, etc. The benefit over a physical display is the ability to adjust resolutions and refresh rates beyond the physical displays capabilities. For example, this would enable the ability to stream a game from your home PC using game streaming software at 240hz at 8K while owning a 60hz 1080p monitor (unrealistic, but explains the abilities well). For servers without displays, this enabled remote desktop and screen streaming to other systems as if there were a display installed.
-38
View File
@@ -1,38 +0,0 @@
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$repoName = "PSGallery"
$moduleName1 = "DisplayConfig"
$moduleName2 = "MonitorConfig"
if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) {
& .\dep_fix.ps1
}
# Import the local module
$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path
import-module -name $dpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue
# Import the other localmodule
$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path
import-module -name $mpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue
$disp = Get-Monitor | Select-String -Pattern "MTT1337" | Select-Object LineNumber | Select-Object -ExpandProperty LineNumber
$bpcc = Get-DisplayColorInfo -DisplayId $disp | Select-Object BitsPerColorChannel | Select-Object -ExpandProperty BitsPerColorChannel
if ( $bpcc -is [int] ) {
if ( $bpcc -gt 8 ) {
Disable-DisplayAdvancedColor -DisplayId $disp
break
}
if ( $bpcc -lt 10 ) {
Enable-DisplayAdvancedColor -DisplayId $disp
break
}
}
else { write-error "Something went wrong in identifying the Colormode of the display." ; break }
-39
View File
@@ -1,39 +0,0 @@
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$repoName = "PSGallery"
$moduleName1 = "DisplayConfig"
$moduleName2 = "MonitorConfig"
if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) {
& .\dep_fix.ps1
}
# Import the local module
$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path
import-module -name $dpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Import the other localmodule
$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path
import-module -name $mpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Check if there are enough arguments
$numArgs = $args.Count
switch ($numArgs) {
0 { Write-Error "This script requires at least 2 arguments Xres Yres."; break }
1 { Write-Error "This script requires at least 2 arguments Xres Yres."; break }
2 { $disp = Get-Monitor | Select-String -Pattern "MTT1337" | Select-Object LineNumber | Select-Object -ExpandProperty LineNumber
$vres = $args[0]
$hres = $args[1]
continue
}
default { Write-Error "Invalid number of arguments: $numArgs"; break }
}
# Setting the resolution on the correct display.
Get-DisplayConfig | Set-DisplayResolution -DisplayId $disp -Width $vres -Height $hres | Use-DisplayConfig
-32
View File
@@ -1,32 +0,0 @@
# Define the repository name and URL
$repoName = "PSGallery"
$repoUrl = "https://www.powershellgallery.com/api/v2"
# Check if the repository is registered
if (-not (Get-PSRepository -Name $repoName)) {
# Register the repository
Register-PSRepository -Name $repoName -SourceLocation $repoUrl -Confirm:$false -InformationAction:Ignore -WarningAction:SilentlyContinue
}
#Trust the repo, either its allready installed or newly added
Set-PSRepository -Name $repoName -InstallationPolicy Trusted -InformationAction:Ignore -WarningAction:SilentlyContinue
# Define the module name and version
$moduleName1 = "DisplayConfig"
$version1 = "1.0.5"
# Define the module name and version
$moduleName2 = "MonitorConfig"
$version2 = "1.0.3"
# Check if the module1 is installed
if (-not (Get-InstalledModule -Name $moduleName1 -MinimumVersion $version1)) {
# Save the module
Save-Module -Name $moduleName1 -Repository $repoName -RequiredVersion $version1 -Confirm:$false -InformationAction:Ignore -WarningAction:SilentlyContinue
}
# Check if the module2 is installed
if (-not (Get-InstalledModule -Name $moduleName2 -MinimumVersion $version2)) {
# Save the module
Save-Module -Name $moduleName2 -Repository $repoName -RequiredVersion $version2 -Confirm:$false -InformationAction:Ignore -WarningAction:SilentlyContinue
}
-26
View File
@@ -1,26 +0,0 @@
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$repoName = "PSGallery"
$moduleName1 = "DisplayConfig"
$moduleName2 = "MonitorConfig"
if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) {
& .\dep_fix.ps1
}
# Import the local module
$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path; import-module -name $dpth
# Import the other localmodule
$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path; import-module -name $mpth
$disp = Get-Monitor | Select-String -Pattern "MTT1337" | Select-Object LineNumber | Select-Object -ExpandProperty LineNumber
Set-DisplayPrimary -DisplayId $disp
-39
View File
@@ -1,39 +0,0 @@
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$repoName = "PSGallery"
$moduleName1 = "DisplayConfig"
$moduleName2 = "MonitorConfig"
if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) {
& .\dep_fix.ps1
}
# Import the local module
$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path
import-module -name $dpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Import the other localmodule
$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path
import-module -name $mpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Use the module's functions and cmdlets in your script
# Check if there are enough arguments
$numArgs = $args.Count
switch ($numArgs) {
0 { Write-Error "This script requires a refreshrate above 59 or reset"; break }
1 { $disp = Get-Monitor | Select-String -Pattern "MTT1337" | Select-Object LineNumber | Select-Object -ExpandProperty LineNumber
$rate = $args[0]
continue
}
default { Write-Error "Invalid number of arguments: $numArgs"; break }
}
# Setting the resolution on the correct display.
Get-DisplayConfig | Set-DisplayRefreshRate -DisplayId $disp -RefreshRate $rate | Use-DisplayConfig
-46
View File
@@ -1,46 +0,0 @@
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$repoName = "PSGallery"
$moduleName1 = "DisplayConfig"
$moduleName2 = "MonitorConfig"
if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) {
& .\dep_fix.ps1
}
# Import the local module
$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path
import-module -name $dpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Import the other localmodule
$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path
import-module -name $mpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Check if there are enough arguments
$numArgs = $args.Count
switch ($numArgs) {
0 { Write-Error "This script requires at least 1, rotation in degrees ex. 90/180/270."; break }
1 { $disp = Get-Monitor | Select-String -Pattern "MTT1337" | Select-Object LineNumber | Select-Object -ExpandProperty LineNumber
switch ($args[0]) {
90 { $degree = "Rotate90"
continue
}
180 { $degree = "Rotate180"
continue
}
270 { $degree = "Rotate270"
continue
}
default { Write-Error "Invalid rotation angle(valid 90,180,270)."; break }
}
default { Write-Error "Invalid number of arguments: $numArgs"; break }
}
# Setting the resolution on the correct display.
Get-DisplayConfig | Set-DisplayRotation -DisplayId $disp -Rotation $degree | Use-DisplayConfig
-54
View File
@@ -1,54 +0,0 @@
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$repoName = "PSGallery"
$moduleName1 = "DisplayConfig"
$moduleName2 = "MonitorConfig"
if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) {
& .\dep_fix.ps1
}
# Import the local module
$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path
import-module -name $dpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Import the other localmodule
$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path
import-module -name $mpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Check if there are enough arguments
$numArgs = $args.Count
switch ($numArgs) {
0 { Write-Error "This script requires a scale 'reset' or an accepted percfentage value (100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500) limited by the device max scale."; break }
1 { $disp = Get-Monitor | Select-String -Pattern "MTT1337" | Select-Object LineNumber | Select-Object -ExpandProperty LineNumber
$maxscale = Get-DisplayScale -DisplayId $disp | Select-Object -ExpandProperty MaxScale
if ( $args[0] -is [int] ) {
if ( $args[0] -le $maxscale -And $args[0] -ge 100 ) {
Set-DisplayScale -DisplayId $disp -Scale $args[0]
break
}
else {
Write-Error "Invalid scale percentage."
break
}
}
else {
if ( $args[0] -eq "reset" ) {
Set-DisplayScale -DisplayId $disp -Recommended
break
}
else {
Write-Error "Invalid arguments: 'reset' or a valid percentage value like 150 is acceptable."
break
}
}
}
default { Write-Error "Invalid number of arguments: $numArgs"; break }
}
+1 -1
View File
@@ -7,7 +7,7 @@
}
}
$device = get-pnpdevice -class Display -FriendlyName 'Virtual Display' -ErrorAction SilentlyContinue
$device = get-pnpdevice -class Display -FriendlyName 'IddSampleDriver Device HDR' -ErrorAction SilentlyContinue
if ($device) {
if ($device.Status -eq 'OK') {
-36
View File
@@ -1,36 +0,0 @@
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$repoName = "PSGallery"
$moduleName1 = "DisplayConfig"
$moduleName2 = "MonitorConfig"
if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) {
& .\dep_fix.ps1
}
# Import the local module
$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path
import-module -name $dpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
# Import the other localmodule
$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path
import-module -name $mpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false
$profi = Get-DisplayProfile
if ( $profi -eq "Extend" ) {
Set-DisplayProfile Clone
break
}
if ( $profi -eq "Clone" ) {
Set-DisplayProfile Extend
break
}