diff options
author | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 00:45:08 +0000 |
---|---|---|
committer | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 00:45:08 +0000 |
commit | 2cc9523f46da42a8261d36f68154a9ce9ed6b471 (patch) | |
tree | 3f9ce2bedde7bbc4377447af3a01bd48516ce8ce /o3d/command_buffer/client/cross/effect_helper.cc | |
parent | 8cd7d69565a1f4f9dfae797b8cd25bf18292a423 (diff) | |
download | chromium_src-2cc9523f46da42a8261d36f68154a9ce9ed6b471.zip chromium_src-2cc9523f46da42a8261d36f68154a9ce9ed6b471.tar.gz chromium_src-2cc9523f46da42a8261d36f68154a9ce9ed6b471.tar.bz2 |
Change command buffer client code to use structures.
I didn't update the big_test although I'm happy to
do that in another CL.
I changed the CB renderer code to use this. The only
place I didn't is the state handling code. I'll
consider changing that in another CL.
I changed DoCommand so it gets passed the entire
command data including the command itself where
as it used to get passed the command buffer entry
after the command. I wanted to put the commands
into the structures as I think it makes them easier
to use since they can then correctly set their header.
I could have left DoCommand as is but there would
have been a lot of funky pointer math and I thought
this change made it cleaner.
Some questions I had while doing this.
There are a few places in the code that use
unsigned int instead of uint32. It seems
we should use uint32 because unsigned int
is not guarnteed to be 32bits. So for example
ResourceID is unsigned int right now.
The CMD::Set/CMD::Init/CommandBufferHelper commands
are currently fairly untyped. For example
DESTROY_TEXTURE takes a uint32 id. Should it take
a ResourceID instead? DRAW should maybe take an
enum for primitive_type? If we decide to do that
I'd like to do it in another CL.
There's no checking for overflow. We could add
a bunch of DCHECK like DCHECK_LE(width, 65536)
or DCHECK_LE(semantic_index, 16). I'd like to
do those in another CL as well as I think we
need to discuss what commands we want to change.
All the code is in .h files because we want all
of this code to inline. Theoretically this should
be just as efficient as poking values into arrays
in the opt builds.
Review URL: http://codereview.chromium.org/212018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26886 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/command_buffer/client/cross/effect_helper.cc')
-rw-r--r-- | o3d/command_buffer/client/cross/effect_helper.cc | 71 |
1 files changed, 26 insertions, 45 deletions
diff --git a/o3d/command_buffer/client/cross/effect_helper.cc b/o3d/command_buffer/client/cross/effect_helper.cc index ced1b3b..b9254cc 100644 --- a/o3d/command_buffer/client/cross/effect_helper.cc +++ b/o3d/command_buffer/client/cross/effect_helper.cc @@ -52,18 +52,14 @@ bool EffectHelper::CreateEffectParameters(ResourceID effect_id, // Get the param count. Uint32 *retval = shm_allocator_->AllocTyped<Uint32>(1); - CommandBufferEntry args[4]; - args[0].value_uint32 = effect_id; - args[1].value_uint32 = sizeof(*retval); - args[2].value_uint32 = shm_id_; - args[3].value_uint32 = shm_allocator_->GetOffset(retval); - helper_->AddCommand(GET_PARAM_COUNT, 4, args); + helper_->GetParamCount(effect_id, sizeof(*retval), + shm_id_, shm_allocator_->GetOffset(retval)); // Finish has to be called to get the result. helper_->Finish(); // We could have failed if the effect_id is invalid. if (helper_->interface()->GetParseError() != - BufferSyncInterface::PARSE_NO_ERROR) { + BufferSyncInterface::kParseNoError) { shm_allocator_->Free(retval); return false; } @@ -79,10 +75,7 @@ bool EffectHelper::CreateEffectParameters(ResourceID effect_id, for (unsigned int i = 0; i < param_count; ++i) { EffectParamDesc *desc = &((*descs)[i]); desc->id = param_id_allocator_->AllocateID(); - args[0].value_uint32 = desc->id; - args[1].value_uint32 = effect_id; - args[2].value_uint32 = i; - helper_->AddCommand(CREATE_PARAM, 3, args); + helper_->CreateParam(desc->id, effect_id, i); } // Read param descriptions in batches. We use as much shared memory as @@ -97,16 +90,14 @@ bool EffectHelper::CreateEffectParameters(ResourceID effect_id, for (unsigned int j = 0 ; j < count; ++j) { EffectParamDesc *desc = &((*descs)[i + j]); Desc *raw_desc = raw_descs + j; - args[0].value_uint32 = desc->id; - args[1].value_uint32 = sizeof(*raw_desc); - args[2].value_uint32 = shm_id_; - args[3].value_uint32 = shm_allocator_->GetOffset(raw_desc); - helper_->AddCommand(GET_PARAM_DESC, 4, args); + helper_->GetParamDesc(desc->id, sizeof(*raw_desc), + shm_id_, + shm_allocator_->GetOffset(raw_desc)); } // Finish to get the results. helper_->Finish(); DCHECK_EQ(helper_->interface()->GetParseError(), - BufferSyncInterface::PARSE_NO_ERROR); + BufferSyncInterface::kParseNoError); for (unsigned int j = 0 ; j < count; ++j) { EffectParamDesc *desc = &((*descs)[i + j]); Desc *raw_desc = raw_descs + j; @@ -133,18 +124,16 @@ bool EffectHelper::GetParamStrings(EffectParamDesc *desc) { // Not enough memory to get the param desc. return false; } - CommandBufferEntry args[4]; - args[0].value_uint32 = desc->id; - args[1].value_uint32 = size; - args[2].value_uint32 = shm_id_; - args[3].value_uint32 = shm_allocator_->GetOffset(raw_desc); - helper_->AddCommand(GET_PARAM_DESC, 4, args); + helper_->GetParamDesc(desc->id, size, + shm_id_, + shm_allocator_->GetOffset(raw_desc)); + // Finish to get the results. helper_->Finish(); // We could have failed if the param ID is invalid. if (helper_->interface()->GetParseError() != - BufferSyncInterface::PARSE_NO_ERROR) { + BufferSyncInterface::kParseNoError) { shm_allocator_->Free(raw_desc); return false; } @@ -162,13 +151,13 @@ bool EffectHelper::GetParamStrings(EffectParamDesc *desc) { // Not enough memory to get the param desc. return false; } - args[1].value_uint32 = size; - args[3].value_uint32 = shm_allocator_->GetOffset(raw_desc); - helper_->AddCommand(GET_PARAM_DESC, 4, args); + helper_->GetParamDesc(desc->id, size, + shm_id_, + shm_allocator_->GetOffset(raw_desc)); // Finish to get the results. helper_->Finish(); DCHECK_EQ(helper_->interface()->GetParseError(), - BufferSyncInterface::PARSE_NO_ERROR); + BufferSyncInterface::kParseNoError); DCHECK_EQ(raw_desc->size, size); } @@ -201,11 +190,9 @@ bool EffectHelper::GetParamStrings(EffectParamDesc *desc) { void EffectHelper::DestroyEffectParameters( const std::vector<EffectParamDesc> &descs) { - CommandBufferEntry args[1]; for (unsigned int i = 0; i < descs.size(); ++i) { const EffectParamDesc &desc = descs[i]; - args[0].value_uint32 = desc.id; - helper_->AddCommand(DESTROY_PARAM, 1, args); + helper_->DestroyParam(desc.id); param_id_allocator_->FreeID(desc.id); } } @@ -217,18 +204,15 @@ bool EffectHelper::GetEffectStreams(ResourceID effect_id, // Get the param count. Uint32 *retval = shm_allocator_->AllocTyped<Uint32>(1); - CommandBufferEntry args[5]; - args[0].value_uint32 = effect_id; - args[1].value_uint32 = sizeof(*retval); - args[2].value_uint32 = shm_id_; - args[3].value_uint32 = shm_allocator_->GetOffset(retval); - helper_->AddCommand(GET_STREAM_COUNT, 4, args); + helper_->GetStreamCount(effect_id, sizeof(*retval), + shm_id_, + shm_allocator_->GetOffset(retval)); // Finish has to be called to get the result. helper_->Finish(); // We could have failed if the effect_id is invalid. if (helper_->interface()->GetParseError() != - BufferSyncInterface::PARSE_NO_ERROR) { + BufferSyncInterface::kParseNoError) { shm_allocator_->Free(retval); return false; } @@ -253,17 +237,14 @@ bool EffectHelper::GetEffectStreams(ResourceID effect_id, for (unsigned int j = 0 ; j < count; ++j) { EffectStreamDesc *desc = &((*descs)[i + j]); Desc *raw_desc = raw_descs + j; - args[0].value_uint32 = effect_id; - args[1].value_uint32 = i+j; - args[2].value_uint32 = sizeof(*raw_desc); - args[3].value_uint32 = shm_id_; - args[4].value_uint32 = shm_allocator_->GetOffset(raw_desc); - helper_->AddCommand(GET_STREAM_DESC, 5, args); + helper_->GetStreamDesc(effect_id, i + j, sizeof(*raw_desc), + shm_id_, + shm_allocator_->GetOffset(raw_desc)); } // Finish to get the results. helper_->Finish(); DCHECK_EQ(helper_->interface()->GetParseError(), - BufferSyncInterface::PARSE_NO_ERROR); + BufferSyncInterface::kParseNoError); for (unsigned int j = 0 ; j < count; ++j) { EffectStreamDesc *desc = &((*descs)[i + j]); Desc *raw_desc = raw_descs + j; |