本文整理汇总了C++中ShaderCode::BufferSize方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderCode::BufferSize方法的具体用法?C++ ShaderCode::BufferSize怎么用?C++ ShaderCode::BufferSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderCode
的用法示例。
在下文中一共展示了ShaderCode::BufferSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrepareShader
void PixelShaderCache::PrepareShader(
PIXEL_SHADER_RENDER_MODE render_mode,
u32 components,
const XFMemory &xfr,
const BPMemory &bpm,
bool ongputhread)
{
const API_TYPE api = ((D3D::GetCaps().PixelShaderVersion >> 8) & 0xFF) < 3 ? API_D3D9_SM20 : API_D3D9_SM30;
PixelShaderUid uid;
GetPixelShaderUID(uid, render_mode, components, xfr, bpm);
if (ongputhread)
{
Compiler->ProcCompilationResults();
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.bEnableShaderDebugging)
{
ShaderCode code;
GeneratePixelShaderCodeD3D9(code, uid.GetUidData());
}
#endif
// Check if the shader is already set
if (last_entry[render_mode])
{
if (uid == last_uid[render_mode])
{
return;
}
}
last_uid[render_mode] = uid;
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
}
else
{
if (external_last_uid[render_mode] == uid)
{
return;
}
external_last_uid[render_mode] = uid;
}
PixelShadersLock.lock();
PSCacheEntry* entry = &PixelShaders[uid];
PixelShadersLock.unlock();
if (ongputhread)
{
last_entry[render_mode] = entry;
}
// Compile only when we have a new instance
if (entry->initialized.test_and_set())
{
return;
}
// Need to compile a new shader
ShaderCompilerWorkUnit *wunit = Compiler->NewUnit(PIXELSHADERGEN_BUFFERSIZE);
wunit->GenerateCodeHandler = [uid, api](ShaderCompilerWorkUnit* wunit)
{
ShaderCode code;
code.SetBuffer(wunit->code.data());
if (api == API_D3D9_SM20)
{
GeneratePixelShaderCodeD3D9SM2(code, uid.GetUidData());
}
else
{
GeneratePixelShaderCodeD3D9(code, uid.GetUidData());
}
wunit->codesize = (u32)code.BufferSize();
};
wunit->entrypoint = "main";
wunit->flags = D3DCOMPILE_SKIP_VALIDATION | D3DCOMPILE_OPTIMIZATION_LEVEL3;
wunit->target = D3D::PixelShaderVersionString();
wunit->ResultHandler = [uid, entry](ShaderCompilerWorkUnit* wunit)
{
if (SUCCEEDED(wunit->cresult))
{
ID3DBlob* shaderBuffer = wunit->shaderbytecode;
const u8* bytecode = (const u8*)shaderBuffer->GetBufferPointer();
u32 bytecodelen = (u32)shaderBuffer->GetBufferSize();
g_ps_disk_cache.Append(uid, bytecode, bytecodelen);
PushByteCode(uid, bytecode, bytecodelen, entry);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.bEnableShaderDebugging)
{
u32 code_hash = HashAdler32((const u8 *)wunit->code.data(), wunit->codesize);
unique_shaders.insert(code_hash);
entry->code = wunit->code.data();
}
if (g_ActiveConfig.iLog & CONF_SAVESHADERS) {
static int counter = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(szTemp, wunit->code.data());
}
#endif
}
else
{
static int num_failures = 0;
std::string filename = StringFromFormat("%sbad_ps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
//.........这里部分代码省略.........
示例2: PrepareShader
void VertexShaderCache::PrepareShader(u32 components, const XFMemory &xfr, const BPMemory &bpm, bool ongputhread)
{
VertexShaderUid uid;
GetVertexShaderUID(uid, components, xfr, bpm);
if (ongputhread)
{
Compiler->ProcCompilationResults();
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.bEnableShaderDebugging)
{
ShaderCode code;
GenerateVertexShaderCodeD3D9(code, uid.GetUidData());
}
#endif
if (last_entry)
{
if (uid == last_uid)
{
return;
}
}
last_uid = uid;
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
}
else
{
if (external_last_uid == uid)
{
return;
}
external_last_uid = uid;
}
vshaderslock.lock();
VSCacheEntry *entry = &vshaders[uid];
vshaderslock.unlock();
if (ongputhread)
{
last_entry = entry;
}
// Compile only when we have a new instance
if (entry->initialized.test_and_set())
{
return;
}
ShaderCompilerWorkUnit *wunit = Compiler->NewUnit(VERTEXSHADERGEN_BUFFERSIZE);
wunit->GenerateCodeHandler = [uid](ShaderCompilerWorkUnit* wunit)
{
ShaderCode code;
code.SetBuffer(wunit->code.data());
GenerateVertexShaderCodeD3D9(code, uid.GetUidData());
wunit->codesize = (u32)code.BufferSize();
};
wunit->entrypoint = "main";
wunit->flags = D3DCOMPILE_SKIP_VALIDATION | D3DCOMPILE_OPTIMIZATION_LEVEL3;
wunit->target = D3D::VertexShaderVersionString();
wunit->ResultHandler = [uid, entry](ShaderCompilerWorkUnit* wunit)
{
if (SUCCEEDED(wunit->cresult))
{
ID3DBlob* shaderBuffer = wunit->shaderbytecode;
const u8* bytecode = (const u8*)shaderBuffer->GetBufferPointer();
u32 bytecodelen = (u32)shaderBuffer->GetBufferSize();
g_vs_disk_cache.Append(uid, bytecode, bytecodelen);
PushByteCode(uid, bytecode, bytecodelen, entry);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.bEnableShaderDebugging)
{
entry->code = wunit->code.data();
}
#endif
}
else
{
static int num_failures = 0;
std::string filename = StringFromFormat("%sbad_vs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
std::ofstream file;
OpenFStream(file, filename, std::ios_base::out);
file << ((const char*)wunit->code.data());
file << ((const char*)wunit->error->GetBufferPointer());
file.close();
PanicAlert("Failed to compile vertex shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%s):\n%s",
filename,
D3D::VertexShaderVersionString(),
(char*)wunit->error->GetBufferPointer());
}
};
Compiler->CompileShaderAsync(wunit);
}