Index: command_buffer/service/win/d3d9/effect_d3d9.cc |
=================================================================== |
--- command_buffer/service/win/d3d9/effect_d3d9.cc (revision 19749) |
+++ command_buffer/service/win/d3d9/effect_d3d9.cc (working copy) |
@@ -69,13 +69,16 @@ |
} |
EffectD3D9::EffectD3D9(ID3DXEffect *d3d_effect, |
- ID3DXConstantTable *fs_constant_table) |
+ ID3DXConstantTable *fs_constant_table, |
+ IDirect3DVertexShader9 *d3d_vertex_shader) |
: d3d_effect_(d3d_effect), |
fs_constant_table_(fs_constant_table), |
+ d3d_vertex_shader_(d3d_vertex_shader), |
sync_parameters_(false) { |
for (unsigned int i = 0; i < kMaxSamplerUnits; ++i) { |
samplers_[i] = kInvalidResource; |
} |
+ SetStreams(); |
} |
// Releases the D3D effect. |
EffectD3D9::~EffectD3D9() { |
@@ -86,6 +89,8 @@ |
d3d_effect_->Release(); |
DCHECK(fs_constant_table_); |
fs_constant_table_->Release(); |
+ DCHECK(d3d_vertex_shader_); |
+ d3d_vertex_shader_->Release(); |
} |
// Compiles the effect, and checks that the effect conforms to what we expect |
@@ -152,7 +157,17 @@ |
d3d_effect->Release(); |
return NULL; |
} |
- return new EffectD3D9(d3d_effect, table); |
+ IDirect3DVertexShader9 *d3d_vertex_shader = NULL; |
+ HR(device->CreateVertexShader(pass_desc.pVertexShaderFunction, |
+ &d3d_vertex_shader)); |
+ if (!d3d_vertex_shader) { |
+ d3d_effect->Release(); |
+ table->Release(); |
+ DLOG(ERROR) << "Failed to create vertex shader"; |
+ return NULL; |
+ } |
+ |
+ return new EffectD3D9(d3d_effect, table, d3d_vertex_shader); |
} |
// Begins rendering with the effect, setting all the appropriate states. |
@@ -177,6 +192,11 @@ |
return effect_desc.Parameters; |
} |
+// Gets the number of input streams from the shader. |
+unsigned int EffectD3D9::GetStreamCount() { |
+ return streams_.size(); |
+} |
+ |
// Retrieves the matching DataType from a D3D parameter description. |
static effect_param::DataType GetDataTypeFromD3D( |
const D3DXPARAMETER_DESC &desc) { |
@@ -282,6 +302,38 @@ |
return result; |
} |
+bool EffectD3D9::SetStreams() { |
+ if (!d3d_vertex_shader_) { |
+ return false; |
+ } |
+ UINT size; |
+ d3d_vertex_shader_->GetFunction(NULL, &size); |
+ scoped_array<DWORD> function(new DWORD[size]); |
+ d3d_vertex_shader_->GetFunction(function.get(), &size); |
+ |
+ UINT num_semantics; |
+ HR(D3DXGetShaderInputSemantics(function.get(), |
+ NULL, |
+ &num_semantics)); |
+ scoped_array<D3DXSEMANTIC> semantics(new D3DXSEMANTIC[num_semantics]); |
+ HR(D3DXGetShaderInputSemantics(function.get(), |
+ semantics.get(), |
+ &num_semantics)); |
+ |
+ streams_.resize(num_semantics); |
+ for (UINT i = 0; i < num_semantics; ++i) { |
+ vertex_struct::Semantic semantic; |
+ unsigned int semantic_index; |
+ if (D3DSemanticToCBSemantic(static_cast<D3DDECLUSAGE>(semantics[i].Usage), |
+ static_cast<int>(semantics[i].UsageIndex), |
+ &semantic, &semantic_index)) { |
+ streams_[i].semantic = semantic; |
+ streams_[i].semantic_index = semantic_index; |
+ } |
+ } |
+ return true; |
+} |
+ |
void EffectD3D9::LinkParam(EffectParamD3D9 *param) { |
params_.push_back(param); |
} |
@@ -290,6 +342,23 @@ |
std::remove(params_.begin(), params_.end(), param); |
} |
+// Fills the Desc structure, appending name and semantic if any, and if enough |
+// room is available in the buffer. |
+bool EffectD3D9::GetStreamDesc(unsigned int index, |
+ unsigned int size, |
+ void *data) { |
+ using effect_stream::Desc; |
+ if (size < sizeof(Desc)) // NOLINT |
+ return false; |
+ |
+ Desc stream = streams_[index]; |
+ Desc *desc = static_cast<Desc *>(data); |
+ memset(desc, 0, sizeof(*desc)); |
+ desc->semantic = stream.semantic; |
+ desc->semantic_index = stream.semantic_index; |
Antoine Labour
2009/07/06 23:48:12
how about simply *desc = streams_[index]; instead
|
+ return true; |
+} |
+ |
EffectParamD3D9::EffectParamD3D9(effect_param::DataType data_type, |
EffectD3D9 *effect, |
D3DXHANDLE handle) |
@@ -559,6 +628,31 @@ |
BufferSyncInterface::PARSE_INVALID_ARGUMENTS; |
} |
+// Gets the stream count from the effect and store it in the memory buffer. |
+BufferSyncInterface::ParseError GAPID3D9::GetStreamCount( |
+ ResourceID id, |
+ unsigned int size, |
+ void *data) { |
+ EffectD3D9 *effect = effects_.Get(id); |
+ if (!effect || size < sizeof(Uint32)) // NOLINT |
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; |
+ *static_cast<Uint32 *>(data) = effect->GetStreamCount(); |
+ return BufferSyncInterface::PARSE_NO_ERROR; |
+} |
+ |
+BufferSyncInterface::ParseError GAPID3D9::GetStreamDesc( |
+ ResourceID id, |
+ unsigned int index, |
+ unsigned int size, |
+ void *data) { |
+ EffectD3D9 *effect = effects_.Get(id); |
+ if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; |
+ return effect->GetStreamDesc(index, size, data) ? |
+ BufferSyncInterface::PARSE_NO_ERROR : |
+ BufferSyncInterface::PARSE_INVALID_ARGUMENTS; |
+} |
+ |
+ |
// If the current effect is valid, call End on it, and tag for revalidation. |
void GAPID3D9::DirtyEffect() { |
if (validate_effect_) return; |