本文整理汇总了C++中LPD3DXCONSTANTTABLE::GetConstantDesc方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXCONSTANTTABLE::GetConstantDesc方法的具体用法?C++ LPD3DXCONSTANTTABLE::GetConstantDesc怎么用?C++ LPD3DXCONSTANTTABLE::GetConstantDesc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPD3DXCONSTANTTABLE
的用法示例。
在下文中一共展示了LPD3DXCONSTANTTABLE::GetConstantDesc方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void CD3D9HLSLMaterialRenderer::printHLSLVariables(LPD3DXCONSTANTTABLE table)
{
// currently we only support top level parameters.
// Should be enough for the beginning. (TODO)
// print out constant names
D3DXCONSTANTTABLE_DESC tblDesc;
HRESULT hr = table->GetDesc(&tblDesc);
if (!FAILED(hr))
{
for (int i=0; i<(int)tblDesc.Constants; ++i)
{
D3DXCONSTANT_DESC d;
UINT n = 1;
D3DXHANDLE cHndl = table->GetConstant(NULL, i);
if (!FAILED(table->GetConstantDesc(cHndl, &d, &n)))
{
core::stringc s = " '";
s += d.Name;
s += "' Registers:[begin:";
s += (int)d.RegisterIndex;
s += ", count:";
s += (int)d.RegisterCount;
s += "]";
os::Printer::log(s.c_str());
}
}
}
}
示例2: compileHLSLToD3D9
int compileHLSLToD3D9(const char* from, const char* to, const std::map<std::string, int>& attributes) {
LPD3DXBUFFER errors;
LPD3DXBUFFER shader;
LPD3DXCONSTANTTABLE table;
HRESULT hr = D3DXCompileShaderFromFileA(from, nullptr, nullptr, "main", isVertexShader(from) ? "vs_2_0" : "ps_2_0", 0, &shader, &errors, &table);
if (FAILED(hr)) hr = D3DXCompileShaderFromFileA(from, nullptr, nullptr, "main", isVertexShader(from) ? "vs_3_0" : "ps_3_0", 0, &shader, &errors, &table);
if (errors != nullptr) std::cerr << (char*)errors->GetBufferPointer();
if (!FAILED(hr)) {
std::ofstream file(to, std::ios_base::binary);
file.put(attributes.size());
for (std::map<std::string, int>::const_iterator attribute = attributes.begin(); attribute != attributes.end(); ++attribute) {
file << attribute->first.c_str();
file.put(0);
file.put(attribute->second);
}
D3DXCONSTANTTABLE_DESC desc;
table->GetDesc(&desc);
file.put(desc.Constants);
for (UINT i = 0; i < desc.Constants; ++i) {
D3DXHANDLE handle = table->GetConstant(nullptr, i);
D3DXCONSTANT_DESC descriptions[10];
UINT count = 10;
table->GetConstantDesc(handle, descriptions, &count);
if (count > 1) std::cerr << "Error: Number of descriptors for one constant is greater than one." << std::endl;
for (UINT i2 = 0; i2 < count; ++i2) {
char regtype;
switch (descriptions[i2].RegisterSet) {
case D3DXRS_BOOL:
regtype = 'b';
break;
case D3DXRS_INT4:
regtype = 'i';
break;
case D3DXRS_FLOAT4:
regtype = 'f';
break;
case D3DXRS_SAMPLER:
regtype = 's';
break;
}
//std::cout << descriptions[i2].Name << " " << regtype << descriptions[i2].RegisterIndex << " " << descriptions[i2].RegisterCount << std::endl;
file << descriptions[i2].Name;
file.put(0);
file.put(regtype);
file.put(descriptions[i2].RegisterIndex);
file.put(descriptions[i2].RegisterCount);
}
}
DWORD* data = (DWORD*)shader->GetBufferPointer();
for (unsigned i = 0; i < shader->GetBufferSize() / 4; ++i) {
if ((data[i] & 0xffff) == 0xfffe) { //comment token
unsigned size = (data[i] >> 16) & 0xffff;
i += size;
}
else file.write((char*)&data[i], 4);
示例3: UpdateConstTabDesc
GXINT GShaderImpl::UpdateConstTabDesc(LPD3DXCONSTANTTABLE pct, LPD3DXCONSTANTTABLE_DESC pctd, GXUINT uHandleShift)
{
GXINT nCacheSize = 0;
GXDWORD dwTopIndex = (GXDWORD)m_aConstDesc.size() + 1;
Marimo::ShaderConstName* pConstNameObj = m_pGraphicsImpl->InlGetShaderConstantNameObj();
pct->GetDesc(pctd);
GXD3DXCONSTDESC cd;
for(GXUINT i = 0; i < pctd->Constants; i++)
{
GXUINT uCount;
D3DXHANDLE hConst = pct->GetConstant(NULL, i);
pct->GetConstantDesc(hConst, &cd, &uCount);
//// 把RegisterIndex +1,便于Pixel与Vertex的Index打包
//cd.RegisterIndex = cd.RegisterIndex;
#ifdef _DEBUG
if(cd.RegisterSet == D3DXRS_SAMPLER)
{
ASSERT(cd.Bytes == 4);
}
else if(cd.RegisterSet == D3DXRS_FLOAT4 ||
cd.RegisterSet == D3DXRS_INT4)
{
// Shader被优化后有可能Rows和RegisterCount不相等
//ASSERT(cd.Rows == cd.RegisterCount);
ASSERT(cd.Bytes == cd.Rows * cd.Columns * sizeof(float));
}
else
ASSERT(0);
#endif // _DEBUG
// Sampler不算在常量寄存器内
// 寄存器的大小按照出现的最大寄存器索引+占用的寄存器数量决定,
// 因为寄存器可能是跳跃的,不一定是连续使用的.
if(cd.RegisterSet != D3DXRS_SAMPLER) {
nCacheSize = clMax(nCacheSize,
(GXINT)((cd.RegisterIndex + cd.RegisterCount) * sizeof(float4))); // 根据上面的断言调整,保证这个计算不会覆盖
}
cd.dwNameID = clStringA(cd.Name).GetHash();
cd.dwHandle = (i + dwTopIndex) << uHandleShift;
cd.nCanvasUniform = pConstNameObj->AddName(this, cd.Name, cd.Bytes);
m_aConstDesc.push_back(cd);
}
return nCacheSize;
}
示例4: hasSeenShader
HRESULT APIENTRY D3DProxyDeviceAdv::SetVertexShader(IDirect3DVertexShader9* pvShader)
{
IDirect3DVertexShader9* pShader = NULL;
LPD3DXCONSTANTTABLE pConstantTable = NULL;
BYTE *pData = NULL;
HRESULT hr = m_pDevice->SetVertexShader(pvShader);
m_pDevice->GetVertexShader(&pShader);
UINT pSizeOfData;
if(NULL == pShader) goto grexit;
pShader->GetFunction(NULL,&pSizeOfData);
findWeirdMirrorsEdgeShader(pSizeOfData);
pData = new BYTE[pSizeOfData];
pShader->GetFunction(pData,&pSizeOfData);
bool shaderSeen = hasSeenShader(pSizeOfData);
D3DXCONSTANT_DESC pConstantDesc[32];
UINT pConstantNum = 32;
D3DXGetShaderConstantTable(reinterpret_cast<DWORD*>(pData),&pConstantTable);
if(pConstantTable == NULL) goto grexit;
D3DXCONSTANTTABLE_DESC pDesc;
pConstantTable->GetDesc(&pDesc);
for(UINT i = 0; i < pDesc.Constants; i++)
{
D3DXHANDLE Handle = pConstantTable->GetConstant(NULL,i);
if(Handle == NULL) continue;
pConstantTable->GetConstantDesc(Handle,pConstantDesc,&pConstantNum);
for(UINT j = 0; j < pConstantNum; j++)
{
removeExistingMatrices(pConstantDesc[j]);
parse4by4Matrices(pConstantDesc[j]);
parseIndividualFloats(pConstantDesc[j]);
}
}
grexit:
_SAFE_RELEASE(pConstantTable);
_SAFE_RELEASE(pShader);
if(pData) delete[] pData;
return hr;
}
示例5: CreateStereoConstantFrom
/**
* Returns a collection of modified constants for the specified shader.
* (may be an empty collection if no modifications apply)
* <StrartRegister, StereoShaderConstant<float>>
*
* Hash the shader and load modification rules:
* If rules for this specific shader use those else use default rules.
*
* For each shader constant:
* Check if constant matches a rule (name and/or index). If it does create a stereoshaderconstant
* based on rule and add to map of stereoshaderconstants to return.
*
* @param pActualVertexShader The actual (not wrapped) vertex shader.
* @return Collection of stereoshaderconstants for this shader (empty collection if no modifications).
***/
std::map<UINT, StereoShaderConstant<float>> ShaderModificationRepository::GetModifiedConstantsF(IDirect3DVertexShader9* pActualVertexShader)
{
// All rules are assumed to be valid. Validation of rules should be done when rules are loaded/created
std::vector<ConstantModificationRule*> rulesToApply;
std::map<UINT, StereoShaderConstant<float>> result;
// Hash the shader and load modification rules
BYTE *pData = NULL;
UINT pSizeOfData;
pActualVertexShader->GetFunction(NULL, &pSizeOfData);
pData = new BYTE[pSizeOfData];
pActualVertexShader->GetFunction(pData,&pSizeOfData);
uint32_t hash;
MurmurHash3_x86_32(pData, pSizeOfData, VIREIO_SEED, &hash);
if (m_shaderSpecificModificationRuleIDs.count(hash) == 1) {
// There are specific modification rules to use with this shader
auto itRules = m_shaderSpecificModificationRuleIDs[hash].begin();
while (itRules != m_shaderSpecificModificationRuleIDs[hash].end()) {
rulesToApply.push_back(&(m_AllModificationRules[*itRules]));
++itRules;
}
}
else {
// No specific rules, use general rules
auto itRules = m_defaultModificationRuleIDs.begin();
while (itRules != m_defaultModificationRuleIDs.end()) {
rulesToApply.push_back(&(m_AllModificationRules[*itRules]));
++itRules;
}
}
// Load the constant descriptions for this shader and create StereoShaderConstants as the applicable rules require them.
LPD3DXCONSTANTTABLE pConstantTable = NULL;
D3DXGetShaderConstantTable(reinterpret_cast<DWORD*>(pData), &pConstantTable);
if(pConstantTable) {
D3DXCONSTANTTABLE_DESC pDesc;
pConstantTable->GetDesc(&pDesc);
D3DXCONSTANT_DESC pConstantDesc[64];
for(UINT i = 0; i < pDesc.Constants; i++)
{
D3DXHANDLE handle = pConstantTable->GetConstant(NULL,i);
if(handle == NULL) continue;
UINT pConstantNum = 64;
pConstantTable->GetConstantDesc(handle, pConstantDesc, &pConstantNum);
if (pConstantNum >= 64) {
OutputDebugString("ShaderModificationRepository::GetModifiedConstantsF - Need larger constant description buffer");
}
for(UINT j = 0; j < pConstantNum; j++)
{
// We are only modifying selected float vectors/matricies.
if (pConstantDesc[j].RegisterSet != D3DXRS_FLOAT4)
continue;
if ( ((pConstantDesc[j].Class == D3DXPC_VECTOR) && (pConstantDesc[j].RegisterCount == 1))
|| (((pConstantDesc[j].Class == D3DXPC_MATRIX_ROWS) || (pConstantDesc[j].Class == D3DXPC_MATRIX_COLUMNS)) && (pConstantDesc[j].RegisterCount == 4)) ) {
// Check if any rules match this constant
auto itRules = rulesToApply.begin();
while (itRules != rulesToApply.end()) {
// Type match
if ((*itRules)->m_constantType == pConstantDesc[j].Class) {
// name match required
if ((*itRules)->m_constantName.size() > 0) {
bool nameMatch = false;
if ((*itRules)->m_allowPartialNameMatch) {
nameMatch = std::strstr(pConstantDesc[j].Name, (*itRules)->m_constantName.c_str()) != NULL;
/*if (nameMatch) {
OutputDebugString("Match\n");
}
//.........这里部分代码省略.........
示例6: compileHLSLShaderDx9
//.........这里部分代码省略.........
&& 0 != line)
{
start = bx::uint32_imax(1, line-10);
end = start + 20;
}
printCode(_code.c_str(), line, start, end);
fprintf(stderr, "Error: 0x%08x %s\n", (uint32_t)hr, log);
errorMsg->Release();
return false;
}
UniformArray uniforms;
if (NULL != constantTable)
{
D3DXCONSTANTTABLE_DESC desc;
hr = constantTable->GetDesc(&desc);
if (FAILED(hr) )
{
fprintf(stderr, "Error 0x%08x\n", (uint32_t)hr);
return false;
}
BX_TRACE("Creator: %s 0x%08x", desc.Creator, (uint32_t /*mingw warning*/)desc.Version);
BX_TRACE("Num constants: %d", desc.Constants);
BX_TRACE("# cl ty RxC S By Name");
for (uint32_t ii = 0; ii < desc.Constants; ++ii)
{
D3DXHANDLE handle = constantTable->GetConstant(NULL, ii);
D3DXCONSTANT_DESC constDesc;
uint32_t count;
constantTable->GetConstantDesc(handle, &constDesc, &count);
BX_TRACE("%3d %2d %2d [%dx%d] %d %3d %s[%d] c%d (%d)"
, ii
, constDesc.Class
, constDesc.Type
, constDesc.Rows
, constDesc.Columns
, constDesc.StructMembers
, constDesc.Bytes
, constDesc.Name
, constDesc.Elements
, constDesc.RegisterIndex
, constDesc.RegisterCount
);
UniformType::Enum type = findUniformTypeDx9(constDesc);
if (UniformType::Count != type)
{
Uniform un;
un.name = '$' == constDesc.Name[0] ? constDesc.Name+1 : constDesc.Name;
un.type = type;
un.num = constDesc.Elements;
un.regIndex = constDesc.RegisterIndex;
un.regCount = constDesc.RegisterCount;
uniforms.push_back(un);
}
}
}
uint16_t count = (uint16_t)uniforms.size();
bx::write(_writer, count);
uint32_t fragmentBit = profile[0] == 'p' ? BGFX_UNIFORM_FRAGMENTBIT : 0;
示例7: main
void main(int argc, char* argv[]) {
int i, n;
HRESULT hr;
LPD3DXBUFFER pCode;
LPD3DXBUFFER pErr;
LPD3DXCONSTANTTABLE pTbl;
char* src_name = "test.hlsl";
char* cod_name = "test.cod";
char* prm_name = "test.prm";
char* profile = "ps_3_0";
if (argc > 1) {
src_name = argv[1];
}
if (argc > 2) {
cod_name = argv[2];
}
if (argc > 3) {
prm_name = argv[3];
}
if (argc > 4) {
profile = argv[4];
}
hr = D3DXCompileShaderFromFile(src_name, NULL, NULL, "main", profile, D3DXSHADER_PREFER_FLOW_CONTROL, &pCode, &pErr, &pTbl);
if (D3D_OK == hr) {
D3DXCONSTANTTABLE_DESC desc;
pTbl->GetDesc(&desc);
n = desc.Constants;
SymTbl* pSym = new SymTbl(2*1024*1024);
s_tbl.nb_param = 0;
printf("# const = %d\n", n);
PARAM_INFO* pInfo = s_tbl.info;
for (i = 0; i < n; ++i) {
UINT count = 1;
D3DXCONSTANT_DESC info[1];
D3DXHANDLE hConst = pTbl->GetConstant(NULL, i);
pTbl->GetConstantDesc(hConst, info, &count);
printf("%s, reg = %d, len = %d\n", info[0].Name, info[0].RegisterIndex, info[0].RegisterCount);
int sym_id = pSym->Add((char*)info[0].Name);
pInfo->name = sym_id;
pInfo->reg = info[0].RegisterIndex;
pInfo->len = info[0].RegisterCount;
switch (info[0].Type) {
case D3DXPT_FLOAT:
if (info[0].Class == D3DXPC_SCALAR) {
pInfo->type = E_PARAMTYPE_FLOAT;
} else {
pInfo->type = E_PARAMTYPE_FVEC;
}
break;
case D3DXPT_INT:
if (info[0].Class == D3DXPC_SCALAR) {
pInfo->type = E_PARAMTYPE_INT;
} else {
pInfo->type = E_PARAMTYPE_IVEC;
}
break;
case D3DXPT_BOOL:
pInfo->type = E_PARAMTYPE_BOOL;
break;
case D3DXPT_SAMPLER:
case D3DXPT_SAMPLER1D:
case D3DXPT_SAMPLER2D:
case D3DXPT_SAMPLER3D:
case D3DXPT_SAMPLERCUBE:
pInfo->type = E_PARAMTYPE_SMP;
break;
}
++pInfo;
++s_tbl.nb_param;
}
int tbl_size = sizeof(int) + s_tbl.nb_param*sizeof(PARAM_INFO);
int prm_size = tbl_size + pSym->Length();
char* pPrm = new char[prm_size];
memcpy(pPrm, &s_tbl, tbl_size);
memcpy(pPrm + tbl_size, pSym->Top(), pSym->Length());
Bin_write(cod_name, pCode->GetBufferPointer(), pCode->GetBufferSize());
Bin_write(prm_name, pPrm, prm_size);
delete pSym;
if (pTbl) {
pTbl->Release();
}
} else {
if (pErr) {
char* pErr_msg = (char*)pErr->GetBufferPointer();
printf("%s", pErr_msg);
}
}
if (pErr) {
pErr->Release();
}
//.........这里部分代码省略.........
示例8: compileHLSLToD3D9
int compileHLSLToD3D9(const char* from, const char* to, const std::map<std::string, int>& attributes, EShLanguage stage) {
#ifdef SYS_WINDOWS
HMODULE lib = LoadLibraryA("d3dx9_43.dll");
if (lib != nullptr) CompileShaderFromFileA = (D3DXCompileShaderFromFileAType)GetProcAddress(lib, "D3DXCompileShaderFromFileA");
if (CompileShaderFromFileA == nullptr) {
std::cerr << "d3dx9_43.dll could not be loaded, please install dxwebsetup." << std::endl;
return 1;
}
LPD3DXBUFFER errors;
LPD3DXBUFFER shader;
LPD3DXCONSTANTTABLE table;
HRESULT hr = CompileShaderFromFileA(from, nullptr, nullptr, "main", stage == EShLangVertex ? "vs_2_0" : "ps_2_0", 0, &shader, &errors, &table);
if (FAILED(hr)) hr = CompileShaderFromFileA(from, nullptr, nullptr, "main", stage == EShLangVertex ? "vs_3_0" : "ps_3_0", 0, &shader, &errors, &table);
if (errors != nullptr) std::cerr << (char*)errors->GetBufferPointer();
if (!FAILED(hr)) {
std::ofstream file(to, std::ios_base::binary);
file.put((char)attributes.size());
for (std::map<std::string, int>::const_iterator attribute = attributes.begin(); attribute != attributes.end(); ++attribute) {
file << attribute->first.c_str();
file.put(0);
file.put(attribute->second);
}
D3DXCONSTANTTABLE_DESC desc;
table->GetDesc(&desc);
file.put(desc.Constants);
for (UINT i = 0; i < desc.Constants; ++i) {
D3DXHANDLE handle = table->GetConstant(nullptr, i);
D3DXCONSTANT_DESC descriptions[10];
UINT count = 10;
table->GetConstantDesc(handle, descriptions, &count);
if (count > 1) std::cerr << "Error: Number of descriptors for one constant is greater than one." << std::endl;
for (UINT i2 = 0; i2 < count; ++i2) {
char regtype;
switch (descriptions[i2].RegisterSet) {
case D3DXRS_BOOL:
regtype = 'b';
break;
case D3DXRS_INT4:
regtype = 'i';
break;
case D3DXRS_FLOAT4:
regtype = 'f';
break;
case D3DXRS_SAMPLER:
regtype = 's';
break;
}
//std::cout << descriptions[i2].Name << " " << regtype << descriptions[i2].RegisterIndex << " " << descriptions[i2].RegisterCount << std::endl;
if (strcmp(descriptions[i2].Name, "dx_ViewAdjust") != 0) file << "_"; // TODO: Remove when kfx is deprecated
file << descriptions[i2].Name;
file.put(0);
file.put(regtype);
file.put(descriptions[i2].RegisterIndex);
file.put(descriptions[i2].RegisterCount);
}
}
DWORD* data = (DWORD*)shader->GetBufferPointer();
for (unsigned i = 0; i < shader->GetBufferSize() / 4; ++i) {
if ((data[i] & 0xffff) == 0xfffe) { //comment token
unsigned size = (data[i] >> 16) & 0xffff;
i += size;
}
else file.write((char*)&data[i], 4);