Пример #1
0
//----------------------------------------------------------------------------
void TestRawBuffer()
{
    Environment env;
    std::string path = env.GetVariable("GTE_PATH");
    if (path == "")
    {
        LogError("You must create the environment variable GTE_PATH.");
        return;
    }
    path += "/Samples/Basics/RawBuffers/Shaders/";
    path += "RawBuffers.hlsl";
    std::shared_ptr<ComputeShader> cshader(ShaderFactory::CreateCompute(path));
    if (!cshader)
    {
        LogError("Cannot find or compile RawBuffers.hlsl.");
        return;
    }

    DX11Engine engine(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
        D3D11_CREATE_DEVICE_DEBUG, D3D_FEATURE_LEVEL_11_0);

    std::shared_ptr<RawBuffer> inputBuffer(new RawBuffer(4));
    char* input = inputBuffer->GetData();
    *(unsigned char*)&input[0] = 'a';
    *(double*)&input[1] = (double)GTE_C_PI;
    *(float*)&input[9] = (float)GTE_C_PI;
    *(short*)&input[13] = -1;
    *(unsigned char*)&input[15] = 'b';

    std::shared_ptr<RawBuffer> outputBuffer(new RawBuffer(4));
    outputBuffer->SetUsage(Resource::SHADER_OUTPUT);
    outputBuffer->SetCopyType(Resource::COPY_STAGING_TO_CPU);

    cshader->Set("input", inputBuffer);
    cshader->Set("output", outputBuffer);

    engine.Execute(cshader, 1, 1, 1);

    engine.CopyGpuToCpu(outputBuffer);
    char* output = outputBuffer->GetData();
    double pid;
    float pif;
    short minusOne;
    unsigned char a, b;
    pid = *(double*)&output[0];         // 3.1415926535897931
    pif = *(float*)&output[8];          // 3.14159274
    minusOne = *(short*)&output[12];    // -1
    a = *(unsigned char*)&output[14];   // 'a'
    b = *(unsigned char*)&output[15];   // 'b'

    outputBuffer = nullptr;
    inputBuffer = nullptr;
    cshader = nullptr;
}
Пример #2
0
//----------------------------------------------------------------------------
AMDPerformance::AMDPerformance(void* dx11Device)
    :
    mModule(nullptr),
    mMaxCounters(0),
    mNumProfileCalls(0)
{
    Environment env;
    std::string path = env.GetVariable("GEOMETRIC_TOOLS");
    if ("" == path)
    {
        LogError("Cannot find environment variable GEOMETRIC_TOOLS.");
        return;
    }
    std::wstring wpath = Environment::Convert(path);

    std::string arch = env.GetVariable("PROCESSOR_ARCHITECTURE");
    if ("" == arch)
    {
        LogError("Cannot find environment variable PROCESSOR_ARCHITECTURE.");
        return;
    }

    if ("AMD64" == arch)
    {
        wpath += L"\\x64\\GPUPerfAPIDX11-x64.dll";
    }
    else
    {
        wpath += L"\\x86\\GPUPerfAPIDX11.dll";
    }

    mModule = LoadLibrary(wpath.c_str());
    if (nullptr == mModule)
    {
        LogError("Failed to load the AMD performance library.");
        return;
    }

    AMD_GET_FUNCTION(RegisterLoggingCallback);
    AMD_GET_FUNCTION(Initialize);
    AMD_GET_FUNCTION(Destroy);
    AMD_GET_FUNCTION(OpenContext);
    AMD_GET_FUNCTION(CloseContext);
    AMD_GET_FUNCTION(SelectContext);
    AMD_GET_FUNCTION(GetNumCounters);
    AMD_GET_FUNCTION(GetCounterName);
    AMD_GET_FUNCTION(GetCounterDescription);
    AMD_GET_FUNCTION(GetCounterDataType);
    AMD_GET_FUNCTION(GetCounterUsageType);
    AMD_GET_FUNCTION(GetDataTypeAsStr);
    AMD_GET_FUNCTION(GetUsageTypeAsStr);
    AMD_GET_FUNCTION(EnableCounter);
    AMD_GET_FUNCTION(DisableCounter);
    AMD_GET_FUNCTION(GetEnabledCount);
    AMD_GET_FUNCTION(GetEnabledIndex);
    AMD_GET_FUNCTION(IsCounterEnabled);
    AMD_GET_FUNCTION(EnableCounterStr);
    AMD_GET_FUNCTION(DisableCounterStr);
    AMD_GET_FUNCTION(EnableAllCounters);
    AMD_GET_FUNCTION(DisableAllCounters);
    AMD_GET_FUNCTION(GetCounterIndex);
    AMD_GET_FUNCTION(GetPassCount);
    AMD_GET_FUNCTION(BeginSession);
    AMD_GET_FUNCTION(EndSession);
    AMD_GET_FUNCTION(BeginPass);
    AMD_GET_FUNCTION(EndPass);
    AMD_GET_FUNCTION(BeginSample);
    AMD_GET_FUNCTION(EndSample);
    AMD_GET_FUNCTION(GetSampleCount);
    AMD_GET_FUNCTION(IsSampleReady);
    AMD_GET_FUNCTION(IsSessionReady);
    AMD_GET_FUNCTION(GetSampleUInt64);
    AMD_GET_FUNCTION(GetSampleUInt32);
    AMD_GET_FUNCTION(GetSampleFloat64);
    AMD_GET_FUNCTION(GetSampleFloat32);
    AMD_GET_FUNCTION(GetStatusAsStr);

    GPA_Status status = GPA_Initialize();
    if (GPA_STATUS_OK != status)
    {
        // If this call fails, you need to run MSVS as Administrator.  This is
        // required so you can access the high-performance counters.
        LogInformation("GPA_Initialize failed: " + msStatusName[status]);
        LogError("Did you run MSVS in administrator mode?");
        return;
    }

    // This function creates and destroys an ID3D11Query object.
    status = GPA_OpenContext(dx11Device);
    if (GPA_STATUS_OK != status)
    {
        AMD_REPORT_ERROR(GPA_OpenContext, status);
        return;
    }

    status = GPA_GetNumCounters(&mMaxCounters);
    if (GPA_STATUS_OK != status)
    {
        AMD_REPORT_ERROR(GPA_GetNumCounters, status);
        return;
    }

    mNames.resize(mMaxCounters);
    mDescriptions.resize(mMaxCounters);
    mDataTypes.resize(mMaxCounters);
    mUsageTypes.resize(mMaxCounters);

    for (gpa_uint32 i = 0; i < mMaxCounters; ++i)
    {
        char const* temp = nullptr;
        status = GPA_GetCounterName(i, &temp);
        AMD_REPORT_INFORMATION(GPA_GetCounterName, status);
        if (nullptr != temp)
        {
            mNames[i] = temp;
        }

        status = GPA_GetCounterDescription(i, &temp);
        AMD_REPORT_INFORMATION(GPA_GetCounterDescription, status);
        if (temp)
        {
            mDescriptions[i] = temp;
        }

        status = GPA_GetCounterDataType(i, &mDataTypes[i]);
        AMD_REPORT_INFORMATION(GPA_GetCounterDataType, status);

        status = GPA_GetCounterUsageType(i, &mUsageTypes[i]);
        AMD_REPORT_INFORMATION(GPA_GetCounterUsageType, status);

        // This code should not fail for GPUPerfAPI-2.11.739.0.  It is
        // included here for when we upgrade to the next version, and AMD
        // modifies counter names or removes counters.
        int j;
        for (j = 0; j < MAX_AMD_COUNTERS; ++j)
        {
            if (mNames[i] == msCounterName[j])
            {
                mSupportedCounters.push_back(static_cast<AMDCounter>(j));
                break;
            }
        }
        if (j == MAX_AMD_COUNTERS)
        {
            // The name cannot be found in the AMD counter enumerations.  This
            // means we have incorrectly typed an enumeration member (fix it).
            LogError("AMD counter name not found.");
        }
    }
}
Пример #3
0
	PluginStatus Execute(const Command& aCommand , Environment& aEnvironment , wstring& ErrorMessage)
	{
		if(aCommand.Name==L"write")
		{
			for(vector<LexerToken>::const_iterator i=aCommand.Parameters.begin();i!=aCommand.Parameters.end();i++)
			{
				if(i->Type==ltName)
				{
					if(aEnvironment.HasVariable(i->Token))
					{
						wcout<<aEnvironment.GetVariable(i->Token);
					}
					else
					{
						ErrorMessage=L"变量"+i->Token+L"不存在。";
						return psFail;
					}
				}
				else
				{
					wcout<<i->Token;
				}
			}
			return psSuccess;
		}
		else if(aCommand.Name==L"writeln")
		{
			for(vector<LexerToken>::const_iterator i=aCommand.Parameters.begin();i!=aCommand.Parameters.end();i++)
			{
				if(i->Type==ltName)
				{
					if(aEnvironment.HasVariable(i->Token))
					{
						wcout<<aEnvironment.GetVariable(i->Token);
					}
					else
					{
						ErrorMessage=L"变量"+i->Token+L"不存在。";
						return psFail;
					}
				}
				else
				{
					wcout<<i->Token;
				}
			}
			wcout<<endl;
			return psSuccess;
		}
		else if(aCommand.Name==L"read")
		{
			for(vector<LexerToken>::const_iterator i=aCommand.Parameters.begin();i!=aCommand.Parameters.end();i++)
			{
				if(i->Type==ltName)
				{
					wstring Value;
					wcin>>Value;
					aEnvironment.SetVariable(i->Token,Value);
				}
				else
				{
					ErrorMessage=i->Token+L"不是变量。";
					return psFail;
				}
			}