VertexProgram::VertexProgram( const VertexProcessor::State &state, vk::PipelineLayout const *pipelineLayout, SpirvShader const *spirvShader) : VertexRoutine(state, pipelineLayout, spirvShader) { ifDepth = 0; loopRepDepth = 0; currentLabel = -1; whileTest = false; enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); auto it = spirvShader->inputBuiltins.find(spv::BuiltInInstanceIndex); if (it != spirvShader->inputBuiltins.end()) { // TODO: we could do better here; we know InstanceIndex is uniform across all lanes assert(it->second.SizeInComponents == 1); routine.getValue(it->second.Id)[it->second.FirstComponent] = As<Float4>(Int4((*Pointer<Int>(data + OFFSET(DrawData, instanceID))))); } routine.pushConstants = data + OFFSET(DrawData, pushConstants); Pointer<Pointer<Byte>> descriptorSets = Pointer<Pointer<Byte>>(data + OFFSET(DrawData, descriptorSets)); auto numDescriptorSets = routine.pipelineLayout->getNumDescriptorSets(); for(unsigned int i = 0; i < numDescriptorSets; i++) { routine.descriptorSets[i] = descriptorSets[i]; } }
void StateManager::Init() { NullTexture = new Texture(NULL); CurVShader = NULL; CurPShader = NULL; CurIBuffer = NULL; D3DSURFACE_DESC Desc; Desc.Width = 1; Desc.Height = 1; Bitmap BlackBmp(1, 1); BlackBmp.Clear(); NullTexture->Update(BlackBmp, Desc); for(UINT i = 0; i < MaxTextures; i++) { CurTexture[i] = NullTexture; } for(UINT i = 0; i < MaxVShaderFloatConstants; i++) { VShaderFloatConstants[i] = Vec4f(0.0f, 0.0f, 0.0f, 0.0f); } for(UINT i = 0; i < MaxVShaderBoolConstants; i++) { VShaderBoolConstants[i] = FALSE; } for(UINT i = 0; i < MaxVShaderIntConstants; i++) { VShaderIntConstants[i] = Int4(0, 0, 0, 0); } VertexShaderSimulator.LoadConstantsFromDevice(); VertexShaderSimulator.ResetRegisters(); VertexShaderSimulator.InitalizeHashes(); //VertexShaderSimulator.OutputNewShaderList(); for(UINT i = 0; i < MaxPShaderFloatConstants; i++) { PShaderFloatConstants[i] = Vec4f(0.0f, 0.0f, 0.0f, 0.0f); } for(UINT i = 0; i < MaxPShaderBoolConstants; i++) { PShaderBoolConstants[i] = FALSE; } for(UINT i = 0; i < MaxPShaderIntConstants; i++) { PShaderIntConstants[i] = Int4(0, 0, 0, 0); } }
VertexProgram::VertexProgram( const VertexProcessor::State &state, vk::PipelineLayout const *pipelineLayout, SpirvShader const *spirvShader, const vk::DescriptorSet::Bindings &descriptorSets) : VertexRoutine(state, pipelineLayout, spirvShader), descriptorSets(descriptorSets) { auto it = spirvShader->inputBuiltins.find(spv::BuiltInInstanceIndex); if (it != spirvShader->inputBuiltins.end()) { // TODO: we could do better here; we know InstanceIndex is uniform across all lanes assert(it->second.SizeInComponents == 1); routine.getVariable(it->second.Id)[it->second.FirstComponent] = As<Float4>(Int4((*Pointer<Int>(data + OFFSET(DrawData, instanceID))))); } routine.descriptorSets = data + OFFSET(DrawData, descriptorSets); routine.descriptorDynamicOffsets = data + OFFSET(DrawData, descriptorDynamicOffsets); routine.pushConstants = data + OFFSET(DrawData, pushConstants); it = spirvShader->inputBuiltins.find(spv::BuiltInSubgroupSize); if (it != spirvShader->inputBuiltins.end()) { ASSERT(it->second.SizeInComponents == 1); routine.getVariable(it->second.Id)[it->second.FirstComponent] = As<SIMD::Float>(Int(SIMD::Width)); } it = spirvShader->inputBuiltins.find(spv::BuiltInSubgroupLocalInvocationId); if (it != spirvShader->inputBuiltins.end()) { ASSERT(it->second.SizeInComponents == 1); routine.getVariable(it->second.Id)[it->second.FirstComponent] = As<SIMD::Float>(SIMD::Int(0, 1, 2, 3)); } }
void VertexProgram::program(UInt &index) { auto it = spirvShader->inputBuiltins.find(spv::BuiltInVertexIndex); if (it != spirvShader->inputBuiltins.end()) { assert(it->second.SizeInComponents == 1); routine.getVariable(it->second.Id)[it->second.FirstComponent] = As<Float4>(Int4(As<Int>(index) + *Pointer<Int>(data + OFFSET(DrawData, baseVertex))) + Int4(0, 1, 2, 3)); } auto activeLaneMask = SIMD::Int(0xFFFFFFFF); // TODO: Control this. spirvShader->emit(&routine, activeLaneMask, descriptorSets); spirvShader->emitEpilog(&routine); }
void VertexProgram::program(UInt &index) { // shader->print("VertexShader-%0.8X.txt", state.shaderID); enableIndex = 0; auto it = spirvShader->inputBuiltins.find(spv::BuiltInVertexIndex); if (it != spirvShader->inputBuiltins.end()) { assert(it->second.SizeInComponents == 1); routine.getValue(it->second.Id)[it->second.FirstComponent] = As<Float4>(Int4(index) + Int4(0, 1, 2, 3)); } auto activeLaneMask = SIMD::Int(0xFFFFFFFF); // TODO: Control this. spirvShader->emit(&routine, activeLaneMask); if(currentLabel != -1) { Nucleus::setInsertBlock(returnBlock); } spirvShader->emitEpilog(&routine); }
CValueConvert<SSafeSqlCP, CDB_Object>::operator Int4(void) const { if (m_Value.IsNULL()) { return Int4(); } const EDB_Type cur_type = m_Value.GetType(); switch (cur_type) { case eDB_Int: return ConvertSafe(static_cast<const CDB_Int&>(m_Value).Value()); case eDB_SmallInt: return ConvertSafe(static_cast<const CDB_SmallInt&>(m_Value).Value()); case eDB_TinyInt: return ConvertSafe(static_cast<const CDB_TinyInt&>(m_Value).Value()); case eDB_Bit: return ConvertSafe(static_cast<const CDB_Bit&>(m_Value).Value()); default: ReportTypeConvError(cur_type, "Int4"); } return 0; }
BEGIN_NCBI_SCOPE /////////////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(Test_Procedure) { try { // Test a regular IStatement with "exec" // Parameters are not allowed with this construction. { auto_ptr<IStatement> auto_stmt( GetConnection().GetStatement() ); // Execute it first time ... auto_stmt->SendSql( "exec sp_databases" ); while( auto_stmt->HasMoreResults() ) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch ( rs->GetResultType() ) { case eDB_RowResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_ParamResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_StatusResult: while( rs->Next() ) { int status = rs->GetVariant(1).GetInt4(); status = status; } break; case eDB_ComputeResult: case eDB_CursorResult: break; } } } // Execute it second time ... auto_stmt->SendSql( "exec sp_databases" ); while( auto_stmt->HasMoreResults() ) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch ( rs->GetResultType() ) { case eDB_RowResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_ParamResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_StatusResult: while( rs->Next() ) { int status = rs->GetVariant(1).GetInt4(); status = status; } break; case eDB_ComputeResult: case eDB_CursorResult: break; } } } // Same as before but do not retrieve data ... auto_stmt->SendSql( "exec sp_databases" ); auto_stmt->SendSql( "exec sp_databases" ); } // Test ICallableStatement // No parameters at this time. { // Execute it first time ... auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status auto_stmt->GetReturnStatus(); // Execute it second time ... auto_stmt.reset( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status auto_stmt->GetReturnStatus(); // Same as before but do not retrieve data ... auto_stmt.reset( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); auto_stmt.reset( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); } // Temporary test ... // !!! This is a bug ... if (false) { auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "anyone", "allowed", "PUBSEQ_OS_LXA", "" ); auto_ptr<ICallableStatement> auto_stmt( conn->GetCallableStatement("id_seqid4gi") ); auto_stmt->SetParam( CVariant(1), "@gi" ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } if (false) { const string query("[db_alias] is not null"); auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "*****", "******", "MSSQL31", "AlignDb_Info" ); auto_ptr<ICallableStatement> auto_stmt( conn->PrepareCall("[dbo].[FindAttributesEx]") ); auto_stmt->SetParam( CVariant(1), "@userid" ); auto_stmt->SetParam( CVariant("ALIGNDB"), "@application" ); auto_stmt->SetParam( CVariant("AlignDbMasterInfo"), "@classname" ); // LongChar doesn't work. // auto_stmt->SetParam( CVariant(new CDB_LongChar(query.length(), query)), "@query" ); // auto_stmt->SetParam( CVariant::LongChar(query.data(), query.length()), "@query" ); auto_stmt->SetParam( CVariant(query), "@query" ); auto_stmt->SetParam( CVariant(1), "@max_results" ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } // Test returned recordset ... { // In case of MS SQL 2005 sp_databases returns empty result set. // It is not a bug. It is a difference in setiings for MS SQL // 2005. if (GetArgs().GetServerType() != CDBConnParams::eMSSqlServer) { int num = 0; // Execute it first time ... auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); while (rs->Next()) { BOOST_CHECK(rs->GetVariant(1).GetString().size() > 0); BOOST_CHECK(rs->GetVariant(2).GetInt4() > 0); BOOST_CHECK_EQUAL(rs->GetVariant(3).IsNull(), true); ++num; } BOOST_CHECK(num > 0); DumpResults(auto_stmt.get()); } { int num = 0; auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_server_info") ); auto_stmt->Execute(); BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); while (rs->Next()) { BOOST_CHECK(rs->GetVariant(1).GetInt4() > 0); BOOST_CHECK(rs->GetVariant(2).GetString().size() > 0); BOOST_CHECK(rs->GetVariant(3).GetString().size() > 0); ++num; } BOOST_CHECK(num > 0); DumpResults(auto_stmt.get()); } } // Test ICallableStatement // With parameters. { { auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_server_info") ); // Set parameter to NULL ... auto_stmt->SetParam( CVariant(eDB_Int), "@attribute_id" ); auto_stmt->Execute(); if (GetArgs().GetServerType() == CDBConnParams::eSybaseSQLServer) { BOOST_CHECK_EQUAL( size_t(30), GetNumOfRecords(auto_stmt) ); } else { BOOST_CHECK_EQUAL( size_t(29), GetNumOfRecords(auto_stmt) ); } // Set parameter to 1 ... auto_stmt->SetParam( CVariant( Int4(1) ), "@attribute_id" ); auto_stmt->Execute(); BOOST_CHECK_EQUAL( size_t(1), GetNumOfRecords(auto_stmt) ); } // NULL value with CVariant ... { auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_statistics") ); auto_stmt->SetParam(CVariant((const char*) NULL), "@table_name"); auto_stmt->Execute(); DumpResults(auto_stmt.get()); } // Doesn't work for some reason ... if (false) { // Execute it first time ... auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_statistics") ); auto_stmt->SetParam(CVariant(GetTableName()), "@table_name"); auto_stmt->Execute(); { BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); BOOST_CHECK(rs->Next()); DumpResults(auto_stmt.get()); } // Execute it second time ... auto_stmt->SetParam(CVariant("#bulk_insert_table"), "@table_name"); auto_stmt->Execute(); { BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); BOOST_CHECK(rs->Next()); DumpResults(auto_stmt.get()); } } if (false) { auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("DBAPI_Sample..TestBigIntProc") ); auto_stmt->SetParam(CVariant(Int8(1234567890)), "@num"); auto_stmt->ExecuteUpdate(); } } // Test output parameters ... if (false) { CRef<CDB_UserHandler_Diag> handler(new CDB_UserHandler_Diag()); I_DriverContext* drv_context = GetDS().GetDriverContext(); drv_context->PushDefConnMsgHandler(handler); auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("DBAPI_Sample..SampleProc3") ); auto_stmt->SetParam(CVariant(1), "@id"); auto_stmt->SetParam(CVariant(2.0), "@f"); auto_stmt->SetOutputParam(CVariant(eDB_Int), "@o"); auto_stmt->Execute(); // auto_stmt->SendSql( "exec DBAPI_Sample..TestProc4 @test_out output" ); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: BOOST_CHECK(rs->Next()); NcbiCout << "Output param: " << rs->GetVariant(1).GetInt4() << endl; break; case eDB_ComputeResult: break; case eDB_StatusResult: break; case eDB_CursorResult: break; default: break; } } } // BOOST_CHECK(auto_stmt->HasMoreResults()); // BOOST_CHECK(auto_stmt->HasRows()); // auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); // BOOST_CHECK(rs.get() != NULL); // // while (rs->Next()) { // BOOST_CHECK(rs->GetVariant(1).GetString().size() > 0); // BOOST_CHECK(rs->GetVariant(2).GetInt4() > 0); // BOOST_CHECK_EQUAL(rs->GetVariant(3).IsNull(), true); // ++num; // } // // BOOST_CHECK(num > 0); DumpResults(auto_stmt.get()); drv_context->PopDefConnMsgHandler(handler); } // Temporary test ... if (false) { auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "anyone", "allowed", "", "GenomeHits" ); auto_ptr<ICallableStatement> auto_stmt( conn->GetCallableStatement("NewSub") ); auto_stmt->SetParam(CVariant("tsub2"), "@name"); auto_stmt->SetParam(CVariant("tst"), "@center"); auto_stmt->SetParam(CVariant("9606"), "@taxid"); auto_stmt->SetParam(CVariant("H**o sapiens"), "@organism"); auto_stmt->SetParam(CVariant(""), "@notes"); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } // Temporary test ... if (false && GetArgs().GetServerType() != CDBConnParams::eSybaseSQLServer) { auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "pmcupdate", "*******", "PMC3QA", "PMC3QA" ); auto_ptr<ICallableStatement> auto_stmt( conn->PrepareCall("id_new_id") ); auto_stmt->SetParam(CVariant("tsub2"), "@IdName"); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } } catch(const CException& ex) { DBAPI_BOOST_FAIL(ex); } }
static CDB_Object* s_GetItem(I_Result::EGetItem policy, EDB_Type data_type, CDB_Object* item_buff, EDB_Type b_type, const char* d_ptr, size_t d_len) { if ( !d_ptr ) d_ptr = ""; if (b_type == eDB_VarChar) { if ( !item_buff ) { item_buff = new CDB_VarChar; } if ( d_len ) { ((CDB_VarChar*) item_buff)->SetValue(d_ptr, d_len); } else { item_buff->AssignNULL(); } return item_buff; } if (b_type == eDB_Image) { if ( !item_buff ) { item_buff = new CDB_Image; } else if (policy == I_Result::eAssignLOB) { // Explicitly truncate previous value ... static_cast<CDB_Image*>(item_buff)->Truncate(); } if ( d_len ) { ((CDB_Image*) item_buff)->Append(d_ptr, d_len); } else { item_buff->AssignNULL(); } return item_buff; } if (b_type == eDB_Text) { if ( !item_buff ) { item_buff = new CDB_Text; } else if (policy == I_Result::eAssignLOB) { // Explicitly truncate previous value ... static_cast<CDB_Text*>(item_buff)->Truncate(); } if ( d_len ) { ((CDB_Text*) item_buff)->Append(d_ptr, d_len); } else { item_buff->AssignNULL(); } return item_buff; } long int_val = 0; Int8 int8_val; double double_val; switch ( data_type ) { case eDB_Bit: case eDB_TinyInt: case eDB_SmallInt: case eDB_Int: int_val = NStr::StringToLong(d_ptr); break; case eDB_BigInt: int8_val = NStr::StringToLong(d_ptr); break; case eDB_Float: case eDB_Double: double_val = NStr::StringToDouble(d_ptr); break; default: break; } switch ( b_type ) { case eDB_TinyInt: { if ( item_buff ) *((CDB_TinyInt*) item_buff) = Uint1(int_val); else item_buff = new CDB_TinyInt(Uint1(int_val)); break; } case eDB_Bit: { if ( item_buff ) *((CDB_Bit*) item_buff) = int(int_val); else item_buff = new CDB_Bit(int(int_val)); break; } case eDB_SmallInt: { if ( item_buff ) *((CDB_SmallInt*) item_buff) = Int2(int_val); else item_buff = new CDB_SmallInt(Int2(int_val)); break; } case eDB_Int: { if ( item_buff ) *((CDB_Int*) item_buff) = Int4(int_val); else item_buff = new CDB_Int(Int4(int_val)); break; } case eDB_BigInt: { if ( item_buff ) *((CDB_BigInt*) item_buff) = int8_val; else item_buff = new CDB_BigInt(int8_val); break; } case eDB_Float: { if ( item_buff ) *((CDB_Float*) item_buff) = float(double_val); else item_buff = new CDB_Float(float(double_val)); break; } case eDB_Double: { if ( item_buff ) *((CDB_Double*) item_buff) = double_val; else item_buff = new CDB_Double(double_val); break; } case eDB_DateTime: { CTime time; if ( d_len ) time = CTime(d_ptr, "Y-M-D h:m:s"); if ( item_buff ) *(CDB_DateTime*) item_buff = time; else item_buff = new CDB_DateTime(time); break; } case eDB_SmallDateTime: { CTime time; if (d_len) time = CTime(d_ptr, "Y-M-D"); if (item_buff) *(CDB_SmallDateTime*) item_buff = time; else item_buff = new CDB_SmallDateTime(time); break; } default: break; } if (d_len == 0 && item_buff) { item_buff->AssignNULL(); } return item_buff; }
Int4 VertexProgram::enableMask() { Int4 enable = true ? Int4(enableStack[enableIndex]) : Int4(0xFFFFFFFF); return enable; }