Skip to content

Commit c019c8a

Browse files
committed
Merge branch 'main' into cl_khr_unified_svm
2 parents 6d88078 + b1a1675 commit c019c8a

5 files changed

Lines changed: 438 additions & 6 deletions

File tree

include/getenv_util.hpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
// Copyright (c) 2022-2024 Ben Ashbaugh
3+
//
4+
// SPDX-License-Identifier: MIT
5+
*/
6+
#pragma once
7+
8+
#include <stdlib.h>
9+
#include <string.h>
10+
11+
#include <string>
12+
13+
#if defined(_WIN32)
14+
15+
#include <windows.h>
16+
17+
#define GETENV( _name, _value ) _dupenv_s( &_value, NULL, _name )
18+
#define FREEENV( _value ) free( _value )
19+
20+
#else
21+
22+
#define GETENV( _name, _value ) _value = getenv(_name)
23+
#define FREEENV( _value ) (void)_value
24+
25+
#endif
26+
27+
static inline bool getControlFromEnvironment(
28+
const char* name,
29+
void* pValue,
30+
size_t size )
31+
{
32+
char* envVal = NULL;
33+
GETENV( name, envVal );
34+
35+
if( envVal != NULL )
36+
{
37+
if( size == sizeof(unsigned int) )
38+
{
39+
unsigned int* puVal = (unsigned int*)pValue;
40+
*puVal = atoi(envVal);
41+
}
42+
else if( strlen(envVal) < size )
43+
{
44+
char* pStr = (char*)pValue;
45+
strcpy( pStr, envVal );
46+
}
47+
48+
FREEENV( envVal );
49+
return true;
50+
}
51+
52+
return false;
53+
}
54+
55+
template <class T>
56+
static bool getControl(
57+
const char* name,
58+
T& value )
59+
{
60+
unsigned int readValue = 0;
61+
bool success = getControlFromEnvironment( name, &readValue, sizeof(readValue) );
62+
if( success )
63+
{
64+
value = readValue;
65+
}
66+
67+
return success;
68+
}
69+
70+
template <>
71+
bool getControl<bool>(
72+
const char* name,
73+
bool& value )
74+
{
75+
unsigned int readValue = 0;
76+
bool success = getControlFromEnvironment( name, &readValue, sizeof(readValue) );
77+
if( success )
78+
{
79+
value = ( readValue != 0 );
80+
}
81+
82+
return success;
83+
}
84+
85+
template <>
86+
bool getControl<std::string>(
87+
const char* name,
88+
std::string& value )
89+
{
90+
char readValue[256] = "";
91+
bool success = getControlFromEnvironment( name, readValue, sizeof(readValue) );
92+
if( success )
93+
{
94+
value = readValue;
95+
}
96+
97+
return success;
98+
}

layers/10_cmdbufemu/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ clGetExtensionFunctionAddressForPlatform
2626
clInitLayer
2727
```
2828

29+
## Optional Controls
30+
31+
The following environment variables can modify the behavior of the command buffer emulation layer:
32+
33+
| Environment Variable | Behavior | Example Format |
34+
|----------------------|----------|-----------------|
35+
| `CMDBUFEMU_EnhancedErrorChecking` | Enables additional error checking when commands are added to a command buffer using a command buffer "test queue". By default, the additional error checking is disabled. | `export CMDBUFEMU_EnhancedErrorChecking=1`<br/><br/>`set CMDBUFEMU_EnhancedErrorChecking=1` |
36+
2937
## Known Limitations
3038

3139
This section describes some of the limitations of the emulated `cl_khr_command_buffer` functionality:
3240

33-
* Many error conditions are not properly checked for and returned.
41+
* Some error conditions are not properly checked for and returned.
3442
* Many functions are not thread safe.

0 commit comments

Comments
 (0)